using computer logic Affect something physical (or virtual) Sense something happening in the physical world Scenario #1 The computer analyzes the weight of the pressure input to be larger than a sparrow’s weight. Squirrel?? A water hose is triggered and a spray of water is sent out in the direction of the intruder! A pressure sensor detects that something is trying to take seeds from a bird feeder. Examples The computer analyzes the levels to be lower than normal. The interface on a mobile phone app updates and warns the diabetic that they should eat an apple. A diabetic uses a glucose sensor to measure their blood-sugar level.
Notification of something happening in the virtual world Scenario #2 The computer analyzes the sender to be your best friend. A LED sitting on your desk blinks urgently to get your attention. A Twitter @mention to your Twitter handle is detected. Examples Analyze incoming data using computer logic
https://www.sparkfun.com/arduino_guide How to choose an Arduino Leonardo Mega LilyPad Chip ATmega32U4 ATmega2560 ATmega328 Speed 16MHz 16MHz 8MHz Memory 32Kb 256Kb 32Kb I/O Pins 20 54 9 or 14 Best used for general, all purpose larger projects wearables
samples to get you started: File > Examples ➡Open File > Examples > 01.Basic > BareMinimum • In most cases, the only thing you’ll need to do to get the examples working is to find & replace the pin numbers in the code to the actual pins used in your circuit. ➡ github.com/pchen/ArduinoLilyPadProtoSnap Example code geared specifically for LilyPad ProtoSnap pins:
on the Arduino IDE • Verify - make sure that there are no errors • Upload - compiles (checks for errors too) and writes program to microcontroller’s memory
extension for Arduino version 1.0+ .pde for older sketches • Called a “sketch” because it should feel like picking up a pencil and making a quick drawing. ➡Upload to board: 01.Basics > BlinkExternalLED (We’ll get to how this sketch is made soon...)
semicolon (;) (Much like all English sentences end with a period.) • Examples: delay(1000); // calling a function int a = 1; //assigning a value to variable
boolean isSaturday = true; int myNumber = 1; float pi = 3.14; char firstInitial = ‘P’; char myName[] = “Pearl”; String myName = “Pearl Chen”; Common Data Types boolean true or false int whole number float decimal number char single character char[] or String group of characters A named container that holds a value for later use.
pin#, OUTPUT ); Set a pin to send outgoing commands • digitalWrite( pin#, HIGH ); Output to a pin: HIGH / 5 volts / “on” / 1 • Goal: Light up one (then two) of the external LilyPad LEDs Solution: 01.Basics > TurnOnExternalLED
pin#, OUTPUT ); Set a pin to send outgoing commands • digitalWrite( pin#, LOW ); Output to a pin: LOW / 0 volts / “off” / 0 • delay( milliseconds ); Pause for a set number of milliseconds before executing next line of code. (Note: 1 sec = 1000 ms) • Goal: Try to make the built in LED blink. Solution: 01.Basics > BlinkBuiltInLED
); Set a pin be used as a digital input pin • digitalRead( pin# ); Listen for input values on a pin. Since it’s a digital signal, it will be either HIGH (1) or LOW (0) • (The input will "float" and randomly return either HIGH or LOW without a resistor wired to ground in a circuit. Arduino has a built-in “pull-up resistor” which can be activated using pinMode() as above. More info here.) ➡Open 02.Digital > ButtonBuiltInLED ➡Open 02.Digital > SwitchBuiltInLED
if true } • “if/else” test: if (condition test) { //statements if true }else{ //statements if false } Comparison Operators == equal to != not equal to < less than <= less than or equal to > greater than >= greater than or Logic branching -- allows for different outcomes depending on the condition being tested.
5, 6, 9, 10, 11 • pinMode( pin#, OUTPUT ); Setting pinMode() not necessary for analog -- but won’t hurt. • analogWrite( pin#, dutyCycle ); Output to a pin a duty cycle between 0 (always off) and 255 (always on). • Goal: Light up external LilyPad LEDs on pin 5 and 6 at brightness steps between 0 and 255 Solution: 03.Analog > DimExternalLEDs
Setting pinMode() not necessary for analog -- but won’t hurt. • analogRead( pin# ); Value will be between 0 and the components limit. • Solution: 03.Analog > TempSensor • Also try: 03.Analog > ToneTheremin
) • in loop() use Serial.print() or Serial.println() • To see the serial monitor console, go to Tools > Serial Monitor while your LilyPad is hooked up to your computer via USB. Make sure that the baud rate in the lower righthand corder is also the same as that in Serial.begin().
• Light up an LED each time you click on a button. • When you reach 5 points: buzzzzzzzz! (You win.) • Bonus: Try to remove points when an opponent blocks your light sensor.