Board-of-Education : Input

Board-of-Education : Input
Digital Electronics
Board of Education - Input
This presentation will explain, both from a
hardware and software perspective, how to
properly connect simple input devices to the
BOE.
2
Input / Output Pins on the BOE
• The BOE has sixteen (16)
pins that can be used for
input or output.
• These pins are labeled
P0 thru P15 and are
connected to two headers
on the BOE.
• Additionally, the headers
have Vdd (5 volts) and Vss
(ground) connections.
3
Push-Button Switch
• Normally Open Push-Button Switch
• Sometimes called a Tactile Switch
• Pins 1&4 and 2&3 are internally
connected.
• When the button is pressed, the
switch is closed. (right picture)
• When the button is NOT pressed,
the switch is open. (left picture)
4
Example Switch Input
• If the button is NOT PRESSED, P3 is pulled to a
logic low (0 volts) through the 10KΩ + 220 Ω
resistors.
• If the button is PRESSED, P3 is pulled to a logic
high (5 volts) through the 220 Ω resistor.
5
Example Switch Input - Hardware
Switch Circuit
6
Example Switch Input - Software
• The IN command reads the logic
level of the specified pin.
• Example : IN 3
Reads the logic level at P3
• If the button is NOT PRESSED…
IN 3
Will read a logic ‘0’.
• If the button is PRESSED…
IN 3
Will read a logic ‘1’.
Switch Circuit
7
Example BASIC Program #1
New Commands:
• IN
• DEBUG
Results Displayed
in the Debug window 
DO
 Start of the DO/LOOP
DEBUG ? IN3 
PAUSE 500 

LOOP
END

Reads the status of P3, Displays the results
Pauses for 500 mSec (0.5 seconds)
End of the DO/LOOP
Ends the program
8
Example BASIC Program #2
New Commands:
• IF/THEN/ELSE
DO
 Start of the DO/LOOP
IF (IN3=1) THEN  Reads the status of P3…. If it equals 1…
HIGH 14
 Turn P14 ON
LOW 13
 Turn P13 OFF
ELSE
 Else…
LOW 14
 Turn P14 OFF
HIGH 13
 Turn P13 ON
ENDIF
 End of the IF/THEN/ELSE Command
PAUSE 50
 Pause for 50 mSec
LOOP
 End of the DO/LOOP
9
END
 Ends the program
Example BASIC Program #3
New Commands:
• DO / LOOP with Until
DO
 Start of the DO/LOOP
command1
 Execute command1 while in the loop
LOOP UNTIL IN3=1  Continue DO/LOOP Until P3 = 1
Command2
 Execute AFTER it leaves the loop
END
 Ends the program
10
Resources
Parallax Inc. (2004). What’s A Microcontroller.
– Retrieved July 15, 2009
– fttp://www.parallax.com/tabid/440/Default.aspx