
Originally Posted by
fratello
I want this :
- if I push button on gpio.3, gpio.5 goes high UNTILL voltage at AN3 goes OVER 550 mV or I push again the button ;
As it's written ... when a button is pressed, it checks the voltage ONE time then waits for the button to be released. That's all.
Not even close to what you "wanted".
The "Check's" need to be in a loop, or a couple loops since you want to look for a second button press.
Something like this might work ...
Code:
if GPIO.3=1 AND GPIO.0 = 0 then
HIGH GPIO.5
pause 20 ; debounce
while GPIO.3 = 1
CALL CHECK ; check while waiting for button release
WEND
pause 20
WHILE GPIO.3 = 0
CALL CHECK ; continue checking input
if GPIO.5 = 0 THEN ; IF LED was turned OFF in CHECK routine
GP3PressDone ; we're done
endif
WEND ; stop if button is pressed again
LOW GPIO.5
while GPIO.3 = 1 ; wait for button release
WEND
pause 20
endif
GP3PressDone:
Then do the same thing for the GP2 button.
I was bouncing back and forth from the code to the schematic, having a hard time figuring out what you were trying to do. With so many GPIO's spread throughout the program it's really, really hard.
It would be a lot easier to debug your programs if you used Aliases.
Instead of GPIO.0 etc ... give meaningful Names to each Pin ...
Code:
LED1 VAR GPIO.5
LED2 VAR GPIO.0
BUTN1 VAR GPIO.3
BUTN2 VAR GPIO.2
Then it would look like this, which is much easier to follow ...
Comments help too.
Code:
if BUTN1 = 1 AND LED2 = 0 then
HIGH LED1
pause 20 ; debounce
while BUTN1 = 1
CALL CHECK ; check while waiting for button release
WEND
pause 20
WHILE BUTN1 = 0
CALL CHECK ; continue checking input
if LED1 = 0 THEN ; IF LED was turned OFF in CHECK routine
GP3PressDone ; we're done
endif
WEND ; stop if button is pressed again
LOW LED1
while BUTN1 = 1 ; wait for button release
WEND
pause 20
endif
GP3PressDone:
You would have received an answer a lot quicker that way too. 
<br>
Bookmarks