program behaving wierdly, help me please!
hi all, sorry this, sure must simple problem brain cant solve it.
i have flashing light, want flash per minute of.
i using spark fun light sensor, seems respond pretty well, did simple program consisting of:
serial.println(analogread(pinbpminput));
and serial data showed clear difference between when light off , when on. when on got reading of 24 , when off reading low 3.
the code have posted below supposed serial print 1, first time light flashes, , continue counting until light has flashed 4 times , reset one.
so serial data should be:
1
2
3
4
1
2
3
4
if light has flashed 8 times example.
but!!! problem, serial data putting out above example 1 flash of light, puts out few numbers every time flashes rather 1 number @ time.
what doing wrong? bugging me, because cant see how wrong!
thanks everyone!
i have flashing light, want flash per minute of.
i using spark fun light sensor, seems respond pretty well, did simple program consisting of:
serial.println(analogread(pinbpminput));
and serial data showed clear difference between when light off , when on. when on got reading of 24 , when off reading low 3.
the code have posted below supposed serial print 1, first time light flashes, , continue counting until light has flashed 4 times , reset one.
so serial data should be:
1
2
3
4
1
2
3
4
if light has flashed 8 times example.
but!!! problem, serial data putting out above example 1 flash of light, puts out few numbers every time flashes rather 1 number @ time.
what doing wrong? bugging me, because cant see how wrong!
code: [select]
int pinbpminput = 0;
int count;
int bpm;
int tick = false;
int oldtick = false;
void setup() {
serial.begin(9600);
serial.println("online");
delay(2000);
count = 0;
pinmode(pinbpminput,input);
}
void loop() {
oldtick = tick;
bpm = analogread(pinbpminput);
if (bpm >10) tick = true;
else tick = false;
if (tick&&(oldtick != tick)) {
count = count++;
if (count > 4){
count =1;
}
serial.println(count);
}
}thanks everyone!
you need "debounce" readings buttons. try adding short delay after code has bumped 'count'.
oh, and
is enough code increment variable.
oh, and
code: [select]
count++;is enough code increment variable.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > program behaving wierdly, help me please!
arduino
Comments
Post a Comment