|
Intro to Physical Computing Syllabus code, circuits, & construction
|
Lab Assignment |
||||
| Digital Input and output using the microcontroller | |||||
|
Minimum parts needed: (new parts in bold. see parts list for details)
Step 1: Connect an LED and a 220 ohm resistor in series with each of the eight pins on your microcontroller (5 to 12 on a BX-24, portd.0 to portd.7 on a PIC 18F452). Connect the end of the LED to ground.
Program the microcontroller to light up each LED with a pause in between. BX-24: Sub main() call delay(0.5) ' start program with a half-second delay do call putPin(12, 1) call delay(0.5) call putPin(12,0) call putPin(13,1) call delay(0.5) ' fill in the rest of the pins yourself loop end sub PicBasic Pro: main: high portd.0 pause 500 low portd.0 high portd.1 pause 500 ' fill in the rest of the pins yourself goto main |
|||||
| Step 2:
Connect a switch (or several switches) any of pins of your microcontroller:
Connect an LED to another pin as shown above, and program the microcontroller to change the LED when the switch changes. Here's one possibility: BX-24: sub main() do if getPin(13) = 1 then ' if the switch is closed on pin 13 call putPin(12,0) ' set pin 12 low else call putPin(12,1) ' set pin 12 high end if loop end sub PicBasic Pro: input portb.0 output portd.1 main: if portb.0 = 1 then ' if the switch is closed on pin RB0 low portd.1 ' set pin RD1 low else high portd.1 ' set RD1 high endif goto main |
|||||
| Step 3:
Combine switches and LED's to make a more complex application. Make a puzzle or a combination lock using your switches. Use the LED's to give the user visual feedback. Or think about incorporating ripple effects, where one switch affects many outputs. Besides the progamming and electronic aspects of your application, consider also the material aspects. What is the ideal switch for your application? Will a standard switch work, or will you need something special, like a whisker switch or a tilt switch or a magnetic switch? Will you need to build your own switch? Will you need to build it into a structure so that the user doesn't realize she's triggering action, or should it be a clear, unambiguous controller? Feel free to incorporate any additional elements from future labs or other sources in your application. |