Help with simple PWM code
hey guys new arduino not microcontrollers. wrote simple program supposed fade pin 13 led. run program , see problem is? when use serial terminal view high , low time values start correctly once supposed switch direction start getting negative values. load , see if can figure out? thanks!
code: [select]
byte updown = 1;
int ht = 0;
int lt = 1000;
void setup() {
pinmode(13, output);
serial.begin(9600);
}
void loop() {
serial.println(ht);
serial.println(lt);
rep();
ht += updown; //as high time goes lower low time same amount
lt -= updown;
if(lt == 0 || lt == 1000){
updown = -updown;
}
}
void rep() {
digitalwrite(13, low);
delaymicroseconds(lt);
digitalwrite(13, high);
delaymicroseconds(ht);
}
quote
when use serial terminal view high , low time values start correctly once supposed switch direction start getting negative values.
negative values what?
a suggestion:
code: [select]
[glow]serial.print("ht = ");[/glow]serial.println(ht);
[glow]serial.print("lt = ");[/glow]serial.println(lt);
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Help with simple PWM code
arduino
Comments
Post a Comment