so, i'm building 8-step sequencer using arduino ide, , got part configure period duration using pot. , work, doesn't work way expect. i've been looking @ code hours, , can't figure out went wrong, hoping here give me hand
here's relevant code, "loop" section:
so, first part determining t duration. wanted go 0.1-1 s, or, 100+[0-1023]*0.89 [ms], roughly.
my sequencer has 8 leds, , in second part wanted test setup turning each led period t, , jumping next period/led, t determined pot position. , that, instead of 0.1-1s, around 2-20s. did wrong?
i declared timers type "long", t used type "float". problem, can 2 in equation?
i attach whole code if needed, it's still under construction, it's messy.
here's relevant code, "loop" section:
code: [select]
// playing speed regulation, using pot:
int speedpot = analogread(pot1); // pot determines t duration
float t_step = 0.89; // [ms], t_step=(1000ms-100ms)/1024
float t = 100 + speedpot * t_step; // [ms], t= t_on + t_off, length of 1 period
if (millis() - t_timer < t) { // step scope
digitalwrite(led[stepcounter], high);
} else { // time t passed, time move on
t_timer = millis();
digitalwrite(led[stepcounter], low);
if (stepcounter == 7)
stepcounter = 0;
else
stepcounter++;
}so, first part determining t duration. wanted go 0.1-1 s, or, 100+[0-1023]*0.89 [ms], roughly.
my sequencer has 8 leds, , in second part wanted test setup turning each led period t, , jumping next period/led, t determined pot position. , that, instead of 0.1-1s, around 2-20s. did wrong?
i declared timers type "long", t used type "float". problem, can 2 in equation?
i attach whole code if needed, it's still under construction, it's messy.
quote
i declared timers type "long",they should unsigned long match value returned millis() , avoid possible problems negative values.
Arduino Forum > Using Arduino > Programming Questions > Help with timings
arduino
Comments
Post a Comment