Goal: Use a button to light an LED when pressed.
Purpose: This will demonstrate the use of “ina” to sense an I/O button then use “outa” on another pin to light an LED.
Clock frequency: 5,000 Hz
Propeller code type: This propeller code is based on spin language only.
Files to download: (right click)
Pics to download: (click to enlarge)
Note: Only copy and paste from the link above, or formatting issues will occur!
{{
************************************
* demo_pushbutton_led *
* 2008 *
************************************
Goal: Use a button to light an LED when pressed.
Purpose: This will demonstrate the use of "ina" to sense an I/O button,
then use "outa" on another pin to light an LED.
}}
CON
_clkmode = xtal1 + pll16x ' Feedback and PLL multiplier
_xinfreq = 5_000_000 ' External oscillator = 5 MHz
LED = 0 ' LED Output Pin
PUSHBUTTON = 1 ' Pushbutton Input Pin
PUB ButtonBlinkSpeed ' Main method
dira[LED]~~ ' Set pin to output
repeat ' Endless loop
if ina[PUSHBUTTON] == 1 ' If pushbutton pressed
outa[LED]~~ ' Turn on the LED
else ' If pushbutton not pressed
outa[LED]~ ' Turn off the LED
