pbasic code for 3 led and 2 pushbutton
stevenn
Posts: 3
i try to program 3 led and 2 pushbutton program so red led is power blink all time 2 push-button when press 1 button green led is flash when press 2 button yellow led is flash but it don't work here is my code
DO
HIGH 15
PAUSE 500
LOW 15
PAUSE 500
IF ( IN 3 = 1 ) THEN
HIGH 14
PAUSE 50
ELSEIF ( IN4 = 1 ) THEN
HIGH 13
PAUSE 50
ELSE
PAUSE 50
ENDIF
LOW 14
LOW 13
PAUSE 50
LOOP
Can someone check what wrong with the code
DO
HIGH 15
PAUSE 500
LOW 15
PAUSE 500
IF ( IN 3 = 1 ) THEN
HIGH 14
PAUSE 50
ELSEIF ( IN4 = 1 ) THEN
HIGH 13
PAUSE 50
ELSE
PAUSE 50
ENDIF
LOW 14
LOW 13
PAUSE 50
LOOP
Can someone check what wrong with the code
Comments
i can make red led blink the whole time but whe i add 2 push-button it don't work anymore
DO ---- stuff#1 ---- PAUSE ---- stuff#2 ---- PAUSE LOOP
stuff#1 sets things up for the first PAUSE and stuff#2 sets things up for the second pause, then the whole thing repeats. To blink an LED, stuff#1 does whatever is needed to turn the LED on and stuff#2 does whatever is needed to turn the LED off. If you want to blink another LED, you add statements to stuff#1 that turns the 2nd LED on and to stuff#2 that turns the 2nd LED off and so on. If you want to turn the 2nd LED on only when a pushbutton is pressed, you test for that with an IF/THEN statement and either turn the LED on or not. It doesn't hurt to always turn the 2nd LED off in stuff#2 even if it's already off.
If you have questions about how to add the pushbutton testing, I suggest you review the sections in "What's a Microcontroller?" (find here) that deal with pushbuttons and LEDs.