Having troubles with stopping a function
hello.
i new arduino programming, , testing out things see how works have come wall couldnt climb using internet(google).
what trying make basic "menu" system can use 1 arduino multiple tasks. testing photo resistor , led, , intensions lightlevel activated button, , when clicked button again turn off lightlevel function. wrote function, , when click button lightlevel function working great, arduino stuck in function , cant get out of again. if me thankful.
here main loop:
and function:
i new arduino programming, , testing out things see how works have come wall couldnt climb using internet(google).
what trying make basic "menu" system can use 1 arduino multiple tasks. testing photo resistor , led, , intensions lightlevel activated button, , when clicked button again turn off lightlevel function. wrote function, , when click button lightlevel function working great, arduino stuck in function , cant get out of again. if me thankful.
here main loop:
code: [select]
void loop(void)
{
int reading = digitalread(buttonpin);
if (reading != lastbuttonstate)
{
serial.println("a");
lastdebouncetime = millis();
}
if ((millis() - lastdebouncetime) > debouncedelay)
{
serial.println("b");
if (reading != buttonstate)
{
serial.println("c");
buttonstate = !sensorstate;
if (buttonstate == high)
{
serial.println("d");
sensorstate = high;
}
}
}
if (sensorstate == high)
{
serial.println("e");
lightlevel();
}
lastbuttonstate = reading;
serial.println(sensorstate);
serial.println(lastbuttonstate);
serial.println(reading);
and function:
code: [select]
void lightlevel()
{
if (sensorstate == high)
{
photocellreading = analogread(photocellpin);
serial.print("analog reading = ");
serial.println(photocellreading); // raw analog reading
// led gets brighter darker @ sensor
// means have -invert- reading 0-1023 1023-0
photocellreading = 1023 - photocellreading;
//now have map 0-1023 0-255 since thats range analogwrite uses
ledbrightness = map(photocellreading, 0, 1023, 0, 255);
analogwrite(ledpin, ledbrightness);
delay(100);
}
}
quote
but arduino stuck in functionassuming "lightlevel()" function sketch got stuck in, don't see how function "sticks.
post code.
Arduino Forum > Using Arduino > Programming Questions > Having troubles with stopping a function
arduino
Comments
Post a Comment