Shop OBEX P1 Docs P2 Docs Learn Events
Control Accessory — Parallax Forums

Control Accessory

Furthering my effort to get familiar with the P2's IO I created a rudimentary Forth app to enable control of the Parallax "control accessory" which has 4 tactile push buttons and 4 blue leds. The accessory was connected to pins 24 - 31

These are the 5 words and 1 variable that I used

byte pin_# \ variable for the pin connected to the pressed button

rst 0 pin_# ! ; \ word to initialize the variable to zero

set_pd pin 2304 wrpin L ; \ set a pin to 1k5 pull down

read_buttons 32 28 do I pin@ -1 = if I pin_# ! then loop ; \ monitor the buttons and store the value in pin_#

case_test switch 28 case 25 pin H break 29 case 24 pin H break 30 case 26 pin H break 31 case 27 pin H break ; \ switch case pin_# and set led high

all_low 28 24 do I pin L loop ; \ take all led pins low

Make sure pins 28 to 31 are set to pull down before running the following loop

begin rst read_buttons pin_# @ case_test 100 ms all_low key until

Sign In or Register to comment.