Pushbutton Lights LED

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)

demo_pushbutton_led

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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>