PWM library help
[size=14][size=12]so did searching , couldn't find looking for. i want able generate pwm @ duty cycle , frequency. to create library can call upon during current project , future projects come. i new here , apologize if asking question guys on daily basis (i hate guys), couldn't find answer.
so goal turn signal wii nunchunck pwm signal, them output motor. i understand math involved, not sure how package together.
here got:
here know wrong.
duty , hertz never assigned anything, therefore no other variables assigned anything. to fix want numbers inputed in manner:
setpwm (duty, hertz)
that how call upon library.
so how do that?
i ok if don't want type response , link me somewhere.
also aware variables truncated. that intentional. and know need header file, after have working.
thanks,
mike[/size][/size]
so goal turn signal wii nunchunck pwm signal, them output motor. i understand math involved, not sure how package together.
here got:
code: [select]
int pwmpin = 11
int hertz;
int duty;
int timehigh;
int timelow;
int totaltime;
void setup ()
{
pinmode (pwmpin, output);
}
void loop ()
{
totaltime = 1000000 / hertz;
duty = duty / 100;
timehigh = totaltime * duty;
timelow = totaltime - timehigh;
digitalwrite (pwmpin, low);
delaymicroseconds (timelow);
digitalwrite (pwmpin, high);
delaymicroseconds (timehigh);
}
here know wrong.
duty , hertz never assigned anything, therefore no other variables assigned anything. to fix want numbers inputed in manner:
setpwm (duty, hertz)
that how call upon library.
so how do that?
i ok if don't want type response , link me somewhere.
also aware variables truncated. that intentional. and know need header file, after have working.
thanks,
mike[/size][/size]
i think have bit backwards. setup , loop functions not go in library.
a library defines class instantiated in sketch. @ of libraries available arduino examples of how library structured , used.
if want create library, have constructor , setpwm methods. setpwm method have 2 reference arguments defined store values.
if not make sense you, don't think ready creating libraries.
a library defines class instantiated in sketch. @ of libraries available arduino examples of how library structured , used.
if want create library, have constructor , setpwm methods. setpwm method have 2 reference arguments defined store values.
if not make sense you, don't think ready creating libraries.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > PWM library help
arduino
Comments
Post a Comment