SlideShare a Scribd company logo
Drawing is putting a line round an idea 
~Henri Matisse
Hacking is giving form to an idea
Hack to Learn
Hack to Communicate
Hack to Do
Hack to Do Think
How to Hack Electronics 
PLANNING-NESS 2014
Hi. I’m Robert Gallup
Agenda 
Mad Cap First Hacks 
Electricity + Electronics 
Hacking Switches + Knobs + Smart LEDs 
Project? 
Wrap Up
Feel Free to Wander
?
Your Hacker’s Kit E 
STEALTH CASE BREADBOARD RESISTOR LED 
SMART LED 
JUMPER WIRES BUTTON KNOB TRINKET
Microcontroller
Put the Trinket in the Breadboard >
Connect the Trinket to your Computer > 
Power Indicator Glowing at First
Download Software > 
http://www.robertgallup.com/download/planningness2014-mac.zip 
Unzip Arduino Software 
Note: There are also downloads for “-windows”, and “-linux”
Start Arduino
Mac OS X: Security Settings > 
1 2 3 4 
Open Preferences Unlock, and change 
“Allow apps …” to 
Anywhere 
Run IMPORTANT: Reset 
security settings
Configure the Software for Your Board >
Configure the Programmer >
Add the Planning-ness Examples > 
1 
2 Select planningness2014 in the Libraries folder 
from the class software download
If it works, … >
?
Load the LEDBlink Example >
The Sketch Window > 
Sketch (program)
Run the Sketch on your Trinket > 
1 2 
Press Reset 
Press the 
Run button 
LED glows
Wait. What?!
The “Blink” > 
Blinking
Sketch Structure (Recipe) E 
// 
S 
void 
setup() 
{ 
pinMode(1, 
OUTPUT); 
} 
! 
// 
Loop 
void 
loop() 
{ 
digitalWrite(1, 
HIGH); 
delay(500); 
digitalWrite(1, 
LOW); 
delay(500); 
} 
Comment 
Statements
Sketch Walkthrough (See the Comments) E 
// 
Setup 
runs 
once 
at 
the 
beginning 
void 
setup() 
{ 
pinMode(1, 
OUTPUT); 
// 
Pin 
#1 
is 
output 
} 
! 
// 
Loop 
runs 
over 
and 
over 
again 
forever 
void 
loop() 
{ 
digitalWrite(1, 
HIGH); 
// 
turn 
the 
LED 
on 
delay(1000); 
// 
wait 
for 
a 
second 
digitalWrite(1, 
LOW); 
// 
turn 
the 
LED 
off 
delay(1000); 
// 
wait 
for 
a 
second 
}
Hack 01: Change the Blinking Speed ( 
1. Change the blink speed 
Hint: edit the blink sketch to change the blink delay 
from 1 second to 1/4 second (note: 1 second = 
1000 milliseconds). Then run the sketch again. 
2. Stretch: Make a short on, longer off blink 
Hint: the delay times don’t have to be the same.
Your First Circuit E 
Jumper Wire 
LED 
Resistor
Wire Up an LED > 
USB 
#0 
#1 
#2 
5V 
BAT 
GND 
#4 
#3 
RST 
JUMPER WIRE
A Note about Breadboards E 
All of the contact points 
in the same row are 
connected 
The “rift” separates the two sides
Hack 02: An LED on Another Pin ( 
1. Rewire your hack to move the LED to Trinket pin #2. 
2. In the “blink” sketch, change the LED pin to match. 
Hint: You may have to change more than one line
Hack 02: A Solution ( 
// 
Setup 
runs 
once 
void 
setup() 
{ 
pinMode(2, 
OUTPUT); 
// 
Pin 
#2 
is 
output 
} 
! 
// 
Loop 
repeats 
forever 
void 
loop() 
{ 
digitalWrite(2, 
HIGH); 
// 
turn 
the 
LED 
on 
delay(1000); 
// 
wait 
for 
a 
second 
digitalWrite(2, 
LOW); 
// 
turn 
the 
LED 
off 
delay(1000); 
// 
wait 
for 
a 
second 
}
Hack 02: Another Way, “Variable” ( 
// 
Declarations 
int 
pinLED 
= 
2; 
! 
// 
Setup 
runs 
once 
at 
the 
beginning 
void 
setup() 
{ 
pinMode(pinLED, 
OUTPUT); 
// 
Pin 
is 
output 
} 
! 
// 
Loop 
runs 
over 
and 
over 
again 
forever 
void 
loop() 
{ 
digitalWrite(pinLED, 
HIGH); 
// 
turn 
the 
LED 
on 
delay(1000); 
// 
wait 
for 
a 
second 
digitalWrite(pinLED, 
LOW); 
// 
turn 
the 
LED 
off 
delay(1000); 
// 
wait 
for 
a 
second 
} 
Declare Variable 
pinLED = 2
Variable Declaration E 
int pinLED = 2; 
TYPE NAME VALUE
Libraries Make It Easier
Add the BobaBlox Library > 
1 
2 Select BobaBlox Folder from the class software download
Load and Run the LEDBlinkPinLibrary Example >
What’s Different About This Sketch? E 
// 
Include 
the 
library 
#include 
<BobaBlox.h> 
! 
// 
Declarations 
LED 
boardLED(1); 
// 
Declare 
an 
LED 
on 
pin 
#1 
! 
// 
Setup 
runs 
once 
at 
the 
beginning 
void 
setup() 
{ 
} 
! 
// 
Loop 
repeats 
forever. 
Use 
the 
“blink” 
method 
to 
blink 
boardLED 
void 
loop() 
{ 
boardLED.blink(); 
}
LED Variable Declaration E 
LED boardLED(1); 
TYPE NAME PIN
Using a Function (method) E 
boardLED.blink(); 
NAME METHOD NAME
Another Version of the Blink Method E 
boardLED.blink(1, 100); 
# TIMES 
DELAY
Hack 03: An LED on Another Pin ( 
1. Change the library Blink sketch to use an LED on pin #3 
Hint: You can add a 2nd LED, or move the LED you 
connected in the previous hack.
Hack 04: Fast Blink ( 
1. Change the library sketch to blink faster 
Hint: look at the example of the LED blink method that 
uses two parameters, times and delay.
Hack 05: Blink Morse Code ( 
1. Load and run the SOS sketch from planningness2014 
examples. 
Note: In Morse Code, “S” is dot-dot-dot, “O” is dash-dash- 
dash. 
2. Change the sketch so it blinks “CQ”. 
Hint: In Morse Code, “C” is dot-dash-dot-dash, “Q” is 
dash-dash-dot-dash. Note: “CQ” is a little like “YO” in 
the ham radio world.
For the Wanderer: Examples E
For the Wanderer: Reference E
?
Chips + Circuits
A Microcontroller E 
! 
! 
SENSORS 
microcontroller Input: temperature, motion, touch, … 
ACTUATORS 
Output: light, motor, sound, heat, … 
PROGRAM
E 
The Trinket Basic Connections (pinout) 
0 
1 
2 
+5V (Regulated) 
Digital I/O 
Ground 
4 
3 
LED (Pin 1) 
USB 
Reset Button 
ADAFRUIT Power LED 
TRINKET 
I/O Pins connect the 
microcontroller to 
power, sensors, and 
actuators.
Electronics
Electricity Starts with Electrons E 
Electrons are negative 
(but, nice) 
- 
-
Sometimes Electrons Mingle E 
In conductive 
materials, electrons are 
free to float 
- 
- 
- - 
- 
- 
- 
- -
Mix in Some Universal Forces E 
+ 
- 
Positive Negative 
Like Yin+Yang, 
or Good+Evil, 
one comes 
with the other
Electricity = Motivated Electrons E 
- 
- 
- 
- + - 
- - 
- - 
Electrons are attracted by a positive force
Voltage (volts) = How Motivated E 
- 
+ 
- 
- 
- 
-
Current (amps) = How Many E 
- 
- 
- 
- - 
- - 
- 
- + 
- - - 
- 
- 
- 
-
Volts Jolt! Current Kills!
Current flows positive to negative 
+ + 
+ 
+ 
+ 
+ - + 
+ 
+ 
+ 
+ 
+ + 
+ 
+ 
+ 
Actually, Current is a Little Twisted E
+ 
But, Not Without a Circuit
+ 
This is a Schematic, BTW
Circuits use Components
Component: Resistor E 
+ + 
+ 
+ ++ + + + + + 
HEAT 
VOLTAGE DROP
Component: LED (Light Emitting Diode) E 
CATHODE / - 
+ 
ANODE / + 
-
?
More Hacks
The Button (Digital Input) E
Component: Button (Switch) E 
CONNECTED 
1 
2 PIN GND 
PIN 
GND
Wiring Up a Single Button > 
USB 
#0 
#1 
#2 
5V 
BAT 
GND 
#4 
#3 
RST 
JUMPER WIRE 
JUMPER WIRE
Load / Run the ButtonLED Example E 
// 
Declarations 
LED 
boardLED(1); 
Button 
pushButton(2); 
int 
buttonState; 
! 
// 
Setup 
runs 
once 
at 
the 
beginning 
void 
setup() 
{ 
} 
! 
// 
Loop 
repeats 
forever 
void 
loop() 
{ 
// 
Read 
the 
switch. 
Set 
LED 
on/off 
according 
to 
button 
state 
buttonState 
= 
pushButton.isDown(); 
if 
(buttonState 
== 
1) 
{ 
boardLED.on(); 
} 
else 
{ 
boardLED.off(); 
} 
}
Pushbutton Variable Declaration E 
Button pushButton(1); 
TYPE NAME PIN
Pushbutton isDown Method E 
pushButton.isDown(); 
NAME METHOD NAME
Other Pushbutton Methods E 
pushButton.isDown(); 
pushButton.isUp(); 
pushButton.isPressed(); 
pushButton.isReleased();
Branching (One Thing or Another) E 
if 
(buttonState 
== 
1) 
{ 
boardLED.on(); 
} 
else 
{ 
boardLED.off(); 
}
The If statement (if/then/else) E 
if 
(condition) 
{ 
••• 
} 
else 
{ 
••• 
} 
if condition is true 
if condition is false 
conditions: 
(a == b) 
(a < b) 
(a > b) 
(a <= b) 
(a >= b) 
(a != b)
Hack 06: Reverse the Logic ( 
1. Reverse the logic in the buttonLED sketch. I.e. make 
the LED go OFF when the button is pressed. 
Hint: there are two ways to do this 
2. Stretch: make the LED blink when the button is 
pressed. 
Hint: what other LED functions do you have to work 
with?
The Knob (Analog Input) E
Component: Knob (Potentiometer) E 
+5V 
GND 
Analog Pin 
+5V GND 
Analog Pin
Analog to Digital Converter (ADC) E 
ADC 
0, 25, 100, 300, 100, 1023 
Voltage Values (0-1032)
E 
The Trinket: A More Complete Picture 
+5V (USB) 
0 
1 
2 
0 
1 
1 
Battery 
Ground 
4 
2 
3 3 
Digital I/O 
Analog Output 
Analog Input Reset 
+5V (Regulated) 
LED (Pin 1) 
USB 
Reset Button 
ADAFRUIT Power LED 
TRINKET
Wiring Up a Knob > 
USB 
#0 
#1 
#2 
5V 
BAT 
GND 
#4 
#3 
RST
Load / Run the knobDimLED Example E 
LED 
boardLED(1); 
Knob 
bluKnob(1); 
! 
int 
knobValue; 
int 
LEDBrightness; 
! 
void 
setup() 
{ 
} 
! 
void 
loop() 
{ 
// 
Check 
the 
knob 
value 
// 
Convert 
the 
knob 
value 
(0-­‐1023) 
to 
a 
brightness 
(0-­‐255). 
// 
Note: 
see 
the 
Map 
command 
in 
the 
reference 
knobValue 
= 
bluKnob.value(); 
LEDBrightness 
= 
map(knobValue, 
0, 
1023, 
0, 
255); 
boardLED.setBrightness(LEDBrightness); 
} 
.setBrightness() 
(see reference)
Knob Variable Declaration E 
Knob bluKnob(1); 
TYPE NAME PIN
Knob Value Method E 
bluKnob.value(); 
NAME METHOD NAME
Hack 07: Change Knob Direction ( 
1. Change the direction of the know. I.e. So the 
brightness goes down when the knob it turned up. 
2. Stretch: Change the blink speed with the knob 
position.
The Smart LED (Digital LED) E 
Unlike a standard LED, the Smart LED has a small processor inside that 
controls the light and communicates digitally with your microprocessor. They 
are also called NeoPixels. Generically, they are sometimes referred to by their 
“controller”, the WS2812 or WS2811.
Component: Smart LED (NeoPixel) E 
Digital In 
+5V 
GND 
Digital Out 
0 1 2 3 4 5 6 7 
Digital In 
Multiple of these LEDs can be “cascaded” from a 
singe pin on your micro process (but, you may 
need outside power).
Wiring Up a Smart LED (NeoPixel) > 
USB 
#0 
#1 
#2 
5V 
BAT 
GND 
#4 
#3 
RST
Hack 08: Hack the SmartPixel Example ( 
1. After wiring the SmartPixel up, load and run the 
SmartPixel sketch. 
2. Change the rate the colors change in the sketch 
3. The sketch currently uses red, green, and blue as it’s 
colors. Change to three different colors 
Hint: look at the comments to figure out the parameters 
for the setPixelColor() method.
Hack 09: Hack the SmartPixelRainbow Sketch ( 
1. Load and run the SmartPixelRainbow sketch. 
2. Change the rate the colors change in the sketch. 
Hint: You can guess what to do (perfectly respectable), or 
look at the complicated code in the NeoPixelFunctions tab 
for a clue.
Hack 10: More Smart LED Hacks ( 
1. BIG STRETCH: See if you can figure out how to control 
the rainbow color with a knob. 
Hint: look at the setPixelColor() and wheel() methods. 
2. GIANT STRETCH: See you can cooperate with some of 
your table-mates and connect several smart LEDs 
together. Hint: one of the parameters when you declare 
the LED variable, is the number of LEDs in the strip.
?
Wax On. Wax Off.
LEDs
Buttons
Knobs (potentiometers)
Smart LED
Team Project
Hack 99: Hack Digital Personality ( 
1. Team up and use everything you’ve learned to design a 
switch with a personality. Hint: use two LEDs and a switch. 
pressing the switch turns one of the LEDs on/off. The other 
LED flashes in some way with personality to indicate 
whether you’ve been successful. Note: could you use a knob 
as the switch? 
2. Do anything else you want to try as an individual. Or, as a 
team.
Wrap Up
Many Other Platforms E 
Arduino RPi BeagleBone 
spark.io 
pinocc.io 
teensy
Add-On Boards (Shields) E
Next Steps: Online Tutorials E 
http://arduino.cc/en/Tutorial 
http://playground.arduino.cc 
https://learn.sparkfun.com 
! 
http://learn.adafruit.com 
http://learn.adafruit.com/category/learn-arduino 
! 
! 
google “arduino tutorials”
Next Steps: Arduino Comic E 
http://www.jodyculkin.com/wp-content/uploads/2011/09/arduino-comic-latest3.pdf
Online Resources E 
ARDUINO: www.arduino.cc, reference, tutorials 
SPARKFUN: www.sparkfun.com, components, devices, tutorials 
ADAFRUIT: www.adafruit.com, components, devices, tutorials 
MAKE MAGAZINE: www.makezine.com, magazine, books, stuff 
MAKER SHED: www.makershed.com, components, kits, stuff 
INSTRUCTABLES: www.instructables.com, tutorials 
RADIO SHACK: www.radioshack.com, components, devices, tutorials 
AMAZON: www.amazon.com, books, components, devices, tutorials 
O’REILLY: www.oreilly.com, books, tutorials, etc. 
ELECTRONIC GOLDMINE: http://www.goldmine-elec-products.com, components 
JAMECO: www.jameco.com, components 
MOUSER: www.mouser.com, components 
DIGIKEY: www.digikey.com, components 
!
Thank You!
Robert Gallup bob@xobxob.com @robertgallup

More Related Content

PDF
Arduino: Intro and Digital I/O
DOCX
Basic arduino sketch example
PDF
2015-10-21 - Arduino workshop
PDF
Game Development using SDL and the PDK
DOCX
PDF
NSTA 2013 Denver - ArduBlock and Arduino
PDF
Game Development with SDL and Perl
PDF
Cross-platform game engine development with SDL 2.0
Arduino: Intro and Digital I/O
Basic arduino sketch example
2015-10-21 - Arduino workshop
Game Development using SDL and the PDK
NSTA 2013 Denver - ArduBlock and Arduino
Game Development with SDL and Perl
Cross-platform game engine development with SDL 2.0

What's hot (20)

ODP
SDL2 Game Development VT Code Camp 2013
PPTX
Arduino slides
DOCX
Arduino Full Tutorial
PDF
Wii Nunchuk for Arduino
PPTX
Mom presentation_monday_arduino in the physics lab
PPTX
Introduction to Arduino with ArduBlock & SparkFun LilyPad
PPTX
PPTX
Arduino programming
PDF
Practicas con arduino
PDF
How to Program SmartThings
PDF
IOTC08 The Arduino Platform
PDF
Programming arduino makeymakey
PDF
Arduino based applications part 2
PPTX
Introduction to arduino
PDF
Arduino experimenters guide hq
PDF
Html5 game, websocket e arduino
PDF
Getting Real With Connected Devices Presentation
PDF
Lab2ppt
PPTX
Introduction to Arduino
PPTX
Arduino Slides With Neopixels
SDL2 Game Development VT Code Camp 2013
Arduino slides
Arduino Full Tutorial
Wii Nunchuk for Arduino
Mom presentation_monday_arduino in the physics lab
Introduction to Arduino with ArduBlock & SparkFun LilyPad
Arduino programming
Practicas con arduino
How to Program SmartThings
IOTC08 The Arduino Platform
Programming arduino makeymakey
Arduino based applications part 2
Introduction to arduino
Arduino experimenters guide hq
Html5 game, websocket e arduino
Getting Real With Connected Devices Presentation
Lab2ppt
Introduction to Arduino
Arduino Slides With Neopixels

Similar to How to hack electronics (20)

PPTX
Arduino Workshop (3).pptx
PPTX
Fun with Circuitry and Electronics
PDF
Aruino Lesson 1 - Led Blink
PDF
Arduino workshop
PPTX
Designers, please mind the gap! Let's get started with Arduino
PDF
publish manual
PPT
arduino.ppt
PDF
Arduino learning
PPT
Intro to Arduino
PPTX
Basic arduino components and more things about arduino
PDF
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
PDF
Hardware Hacking and Arduinos
PDF
Making things sense - Day 1 (May 2011)
PPTX
Arduino Workshop
PPTX
Introduction to Arduino
PPTX
LED Cube Presentation Slides
PPT
computer_programming for grade 12 learners
PDF
Arduino spooky projects_class1
PPT
Notes arduino workshop_15
DOC
Fading leds via pwm
Arduino Workshop (3).pptx
Fun with Circuitry and Electronics
Aruino Lesson 1 - Led Blink
Arduino workshop
Designers, please mind the gap! Let's get started with Arduino
publish manual
arduino.ppt
Arduino learning
Intro to Arduino
Basic arduino components and more things about arduino
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Hardware Hacking and Arduinos
Making things sense - Day 1 (May 2011)
Arduino Workshop
Introduction to Arduino
LED Cube Presentation Slides
computer_programming for grade 12 learners
Arduino spooky projects_class1
Notes arduino workshop_15
Fading leds via pwm

More from Planning-ness (20)

PPTX
How to transform limitations into advantages
PPTX
How to build relevant brand experiences in this digital era
PPTX
How to negotiate
PDF
How to get the most out of mobile marketing technology
PPTX
The Neural Basis for Creativity
PDF
The Cultural Muscle Index
PDF
How to be courageous
PDF
How not to see
PDF
How to grow your startup
PPTX
How to raise venture capital
PPTX
How to make the ordinary extraordinary
PDF
How to maximize flow (and be happier, more creative, and have way less brain ...
PDF
Social TV: How to create connected media experiences
PPTX
How to make better decisions
PPT
How does content really spread?
PDF
How to create better connections by understanding the brain
PDF
The Future of Advertising: Death of Advertising
PDF
How to research (curiously) v2
PDF
Amanda Parkes - Planning-ness 2012
PPT
How to measure influence in social networks
How to transform limitations into advantages
How to build relevant brand experiences in this digital era
How to negotiate
How to get the most out of mobile marketing technology
The Neural Basis for Creativity
The Cultural Muscle Index
How to be courageous
How not to see
How to grow your startup
How to raise venture capital
How to make the ordinary extraordinary
How to maximize flow (and be happier, more creative, and have way less brain ...
Social TV: How to create connected media experiences
How to make better decisions
How does content really spread?
How to create better connections by understanding the brain
The Future of Advertising: Death of Advertising
How to research (curiously) v2
Amanda Parkes - Planning-ness 2012
How to measure influence in social networks

Recently uploaded (20)

PPTX
Syllabus Computer Six class curriculum s
PPTX
material for studying about lift elevators escalation
PPTX
Nanokeyer nano keyekr kano ketkker nano keyer
PPT
FABRICATION OF MOS FET BJT DEVICES IN NANOMETER
PPTX
Prograce_Present.....ggation_Simple.pptx
PPTX
Sem-8 project ppt fortvfvmat uyyjhuj.pptx
PPTX
sdn_based_controller_for_mobile_network_traffic_management1.pptx
PPTX
Lecture 3b C Library _ ESP32.pptxjfjfjffkkfkfk
PPT
Hypersensitivity Namisha1111111111-WPS.ppt
PDF
Smarter Security: How Door Access Control Works with Alarms & CCTV
PPTX
Lecture-3-Computer-programming for BS InfoTech
PPTX
02fdgfhfhfhghghhhhhhhhhhhhhhhhhhhhh.pptx
PDF
How NGOs Save Costs with Affordable IT Rentals
PDF
Cableado de Controladores Logicos Programables
PPTX
Embeded System for Artificial intelligence 2.pptx
PPTX
DEATH AUDIT MAY 2025.pptxurjrjejektjtjyjjy
PPT
chapter_1_a.ppthduushshwhwbshshshsbbsbsbsbsh
PPTX
Computers and mobile device: Evaluating options for home and work
PPTX
code of ethics.pptxdvhwbssssSAssscasascc
PPTX
Operating System Processes_Scheduler OSS
Syllabus Computer Six class curriculum s
material for studying about lift elevators escalation
Nanokeyer nano keyekr kano ketkker nano keyer
FABRICATION OF MOS FET BJT DEVICES IN NANOMETER
Prograce_Present.....ggation_Simple.pptx
Sem-8 project ppt fortvfvmat uyyjhuj.pptx
sdn_based_controller_for_mobile_network_traffic_management1.pptx
Lecture 3b C Library _ ESP32.pptxjfjfjffkkfkfk
Hypersensitivity Namisha1111111111-WPS.ppt
Smarter Security: How Door Access Control Works with Alarms & CCTV
Lecture-3-Computer-programming for BS InfoTech
02fdgfhfhfhghghhhhhhhhhhhhhhhhhhhhh.pptx
How NGOs Save Costs with Affordable IT Rentals
Cableado de Controladores Logicos Programables
Embeded System for Artificial intelligence 2.pptx
DEATH AUDIT MAY 2025.pptxurjrjejektjtjyjjy
chapter_1_a.ppthduushshwhwbshshshsbbsbsbsbsh
Computers and mobile device: Evaluating options for home and work
code of ethics.pptxdvhwbssssSAssscasascc
Operating System Processes_Scheduler OSS

How to hack electronics

  • 1. Drawing is putting a line round an idea ~Henri Matisse
  • 2. Hacking is giving form to an idea
  • 6. Hack to Do Think
  • 7. How to Hack Electronics PLANNING-NESS 2014
  • 9. Agenda Mad Cap First Hacks Electricity + Electronics Hacking Switches + Knobs + Smart LEDs Project? Wrap Up
  • 10. Feel Free to Wander
  • 11. ?
  • 12. Your Hacker’s Kit E STEALTH CASE BREADBOARD RESISTOR LED SMART LED JUMPER WIRES BUTTON KNOB TRINKET
  • 14. Put the Trinket in the Breadboard >
  • 15. Connect the Trinket to your Computer > Power Indicator Glowing at First
  • 16. Download Software > http://www.robertgallup.com/download/planningness2014-mac.zip Unzip Arduino Software Note: There are also downloads for “-windows”, and “-linux”
  • 18. Mac OS X: Security Settings > 1 2 3 4 Open Preferences Unlock, and change “Allow apps …” to Anywhere Run IMPORTANT: Reset security settings
  • 19. Configure the Software for Your Board >
  • 21. Add the Planning-ness Examples > 1 2 Select planningness2014 in the Libraries folder from the class software download
  • 22. If it works, … >
  • 23. ?
  • 24. Load the LEDBlink Example >
  • 25. The Sketch Window > Sketch (program)
  • 26. Run the Sketch on your Trinket > 1 2 Press Reset Press the Run button LED glows
  • 28. The “Blink” > Blinking
  • 29. Sketch Structure (Recipe) E // S void setup() { pinMode(1, OUTPUT); } ! // Loop void loop() { digitalWrite(1, HIGH); delay(500); digitalWrite(1, LOW); delay(500); } Comment Statements
  • 30. Sketch Walkthrough (See the Comments) E // Setup runs once at the beginning void setup() { pinMode(1, OUTPUT); // Pin #1 is output } ! // Loop runs over and over again forever void loop() { digitalWrite(1, HIGH); // turn the LED on delay(1000); // wait for a second digitalWrite(1, LOW); // turn the LED off delay(1000); // wait for a second }
  • 31. Hack 01: Change the Blinking Speed ( 1. Change the blink speed Hint: edit the blink sketch to change the blink delay from 1 second to 1/4 second (note: 1 second = 1000 milliseconds). Then run the sketch again. 2. Stretch: Make a short on, longer off blink Hint: the delay times don’t have to be the same.
  • 32. Your First Circuit E Jumper Wire LED Resistor
  • 33. Wire Up an LED > USB #0 #1 #2 5V BAT GND #4 #3 RST JUMPER WIRE
  • 34. A Note about Breadboards E All of the contact points in the same row are connected The “rift” separates the two sides
  • 35. Hack 02: An LED on Another Pin ( 1. Rewire your hack to move the LED to Trinket pin #2. 2. In the “blink” sketch, change the LED pin to match. Hint: You may have to change more than one line
  • 36. Hack 02: A Solution ( // Setup runs once void setup() { pinMode(2, OUTPUT); // Pin #2 is output } ! // Loop repeats forever void loop() { digitalWrite(2, HIGH); // turn the LED on delay(1000); // wait for a second digitalWrite(2, LOW); // turn the LED off delay(1000); // wait for a second }
  • 37. Hack 02: Another Way, “Variable” ( // Declarations int pinLED = 2; ! // Setup runs once at the beginning void setup() { pinMode(pinLED, OUTPUT); // Pin is output } ! // Loop runs over and over again forever void loop() { digitalWrite(pinLED, HIGH); // turn the LED on delay(1000); // wait for a second digitalWrite(pinLED, LOW); // turn the LED off delay(1000); // wait for a second } Declare Variable pinLED = 2
  • 38. Variable Declaration E int pinLED = 2; TYPE NAME VALUE
  • 40. Add the BobaBlox Library > 1 2 Select BobaBlox Folder from the class software download
  • 41. Load and Run the LEDBlinkPinLibrary Example >
  • 42. What’s Different About This Sketch? E // Include the library #include <BobaBlox.h> ! // Declarations LED boardLED(1); // Declare an LED on pin #1 ! // Setup runs once at the beginning void setup() { } ! // Loop repeats forever. Use the “blink” method to blink boardLED void loop() { boardLED.blink(); }
  • 43. LED Variable Declaration E LED boardLED(1); TYPE NAME PIN
  • 44. Using a Function (method) E boardLED.blink(); NAME METHOD NAME
  • 45. Another Version of the Blink Method E boardLED.blink(1, 100); # TIMES DELAY
  • 46. Hack 03: An LED on Another Pin ( 1. Change the library Blink sketch to use an LED on pin #3 Hint: You can add a 2nd LED, or move the LED you connected in the previous hack.
  • 47. Hack 04: Fast Blink ( 1. Change the library sketch to blink faster Hint: look at the example of the LED blink method that uses two parameters, times and delay.
  • 48. Hack 05: Blink Morse Code ( 1. Load and run the SOS sketch from planningness2014 examples. Note: In Morse Code, “S” is dot-dot-dot, “O” is dash-dash- dash. 2. Change the sketch so it blinks “CQ”. Hint: In Morse Code, “C” is dot-dash-dot-dash, “Q” is dash-dash-dot-dash. Note: “CQ” is a little like “YO” in the ham radio world.
  • 49. For the Wanderer: Examples E
  • 50. For the Wanderer: Reference E
  • 51. ?
  • 53. A Microcontroller E ! ! SENSORS microcontroller Input: temperature, motion, touch, … ACTUATORS Output: light, motor, sound, heat, … PROGRAM
  • 54. E The Trinket Basic Connections (pinout) 0 1 2 +5V (Regulated) Digital I/O Ground 4 3 LED (Pin 1) USB Reset Button ADAFRUIT Power LED TRINKET I/O Pins connect the microcontroller to power, sensors, and actuators.
  • 56. Electricity Starts with Electrons E Electrons are negative (but, nice) - -
  • 57. Sometimes Electrons Mingle E In conductive materials, electrons are free to float - - - - - - - - -
  • 58. Mix in Some Universal Forces E + - Positive Negative Like Yin+Yang, or Good+Evil, one comes with the other
  • 59. Electricity = Motivated Electrons E - - - - + - - - - - Electrons are attracted by a positive force
  • 60. Voltage (volts) = How Motivated E - + - - - -
  • 61. Current (amps) = How Many E - - - - - - - - - + - - - - - - -
  • 63. Current flows positive to negative + + + + + + - + + + + + + + + + + Actually, Current is a Little Twisted E
  • 64. + But, Not Without a Circuit
  • 65. + This is a Schematic, BTW
  • 67. Component: Resistor E + + + + ++ + + + + + HEAT VOLTAGE DROP
  • 68. Component: LED (Light Emitting Diode) E CATHODE / - + ANODE / + -
  • 69. ?
  • 72. Component: Button (Switch) E CONNECTED 1 2 PIN GND PIN GND
  • 73. Wiring Up a Single Button > USB #0 #1 #2 5V BAT GND #4 #3 RST JUMPER WIRE JUMPER WIRE
  • 74. Load / Run the ButtonLED Example E // Declarations LED boardLED(1); Button pushButton(2); int buttonState; ! // Setup runs once at the beginning void setup() { } ! // Loop repeats forever void loop() { // Read the switch. Set LED on/off according to button state buttonState = pushButton.isDown(); if (buttonState == 1) { boardLED.on(); } else { boardLED.off(); } }
  • 75. Pushbutton Variable Declaration E Button pushButton(1); TYPE NAME PIN
  • 76. Pushbutton isDown Method E pushButton.isDown(); NAME METHOD NAME
  • 77. Other Pushbutton Methods E pushButton.isDown(); pushButton.isUp(); pushButton.isPressed(); pushButton.isReleased();
  • 78. Branching (One Thing or Another) E if (buttonState == 1) { boardLED.on(); } else { boardLED.off(); }
  • 79. The If statement (if/then/else) E if (condition) { ••• } else { ••• } if condition is true if condition is false conditions: (a == b) (a < b) (a > b) (a <= b) (a >= b) (a != b)
  • 80. Hack 06: Reverse the Logic ( 1. Reverse the logic in the buttonLED sketch. I.e. make the LED go OFF when the button is pressed. Hint: there are two ways to do this 2. Stretch: make the LED blink when the button is pressed. Hint: what other LED functions do you have to work with?
  • 81. The Knob (Analog Input) E
  • 82. Component: Knob (Potentiometer) E +5V GND Analog Pin +5V GND Analog Pin
  • 83. Analog to Digital Converter (ADC) E ADC 0, 25, 100, 300, 100, 1023 Voltage Values (0-1032)
  • 84. E The Trinket: A More Complete Picture +5V (USB) 0 1 2 0 1 1 Battery Ground 4 2 3 3 Digital I/O Analog Output Analog Input Reset +5V (Regulated) LED (Pin 1) USB Reset Button ADAFRUIT Power LED TRINKET
  • 85. Wiring Up a Knob > USB #0 #1 #2 5V BAT GND #4 #3 RST
  • 86. Load / Run the knobDimLED Example E LED boardLED(1); Knob bluKnob(1); ! int knobValue; int LEDBrightness; ! void setup() { } ! void loop() { // Check the knob value // Convert the knob value (0-­‐1023) to a brightness (0-­‐255). // Note: see the Map command in the reference knobValue = bluKnob.value(); LEDBrightness = map(knobValue, 0, 1023, 0, 255); boardLED.setBrightness(LEDBrightness); } .setBrightness() (see reference)
  • 87. Knob Variable Declaration E Knob bluKnob(1); TYPE NAME PIN
  • 88. Knob Value Method E bluKnob.value(); NAME METHOD NAME
  • 89. Hack 07: Change Knob Direction ( 1. Change the direction of the know. I.e. So the brightness goes down when the knob it turned up. 2. Stretch: Change the blink speed with the knob position.
  • 90. The Smart LED (Digital LED) E Unlike a standard LED, the Smart LED has a small processor inside that controls the light and communicates digitally with your microprocessor. They are also called NeoPixels. Generically, they are sometimes referred to by their “controller”, the WS2812 or WS2811.
  • 91. Component: Smart LED (NeoPixel) E Digital In +5V GND Digital Out 0 1 2 3 4 5 6 7 Digital In Multiple of these LEDs can be “cascaded” from a singe pin on your micro process (but, you may need outside power).
  • 92. Wiring Up a Smart LED (NeoPixel) > USB #0 #1 #2 5V BAT GND #4 #3 RST
  • 93. Hack 08: Hack the SmartPixel Example ( 1. After wiring the SmartPixel up, load and run the SmartPixel sketch. 2. Change the rate the colors change in the sketch 3. The sketch currently uses red, green, and blue as it’s colors. Change to three different colors Hint: look at the comments to figure out the parameters for the setPixelColor() method.
  • 94. Hack 09: Hack the SmartPixelRainbow Sketch ( 1. Load and run the SmartPixelRainbow sketch. 2. Change the rate the colors change in the sketch. Hint: You can guess what to do (perfectly respectable), or look at the complicated code in the NeoPixelFunctions tab for a clue.
  • 95. Hack 10: More Smart LED Hacks ( 1. BIG STRETCH: See if you can figure out how to control the rainbow color with a knob. Hint: look at the setPixelColor() and wheel() methods. 2. GIANT STRETCH: See you can cooperate with some of your table-mates and connect several smart LEDs together. Hint: one of the parameters when you declare the LED variable, is the number of LEDs in the strip.
  • 96. ?
  • 97. Wax On. Wax Off.
  • 98. LEDs
  • 103. Hack 99: Hack Digital Personality ( 1. Team up and use everything you’ve learned to design a switch with a personality. Hint: use two LEDs and a switch. pressing the switch turns one of the LEDs on/off. The other LED flashes in some way with personality to indicate whether you’ve been successful. Note: could you use a knob as the switch? 2. Do anything else you want to try as an individual. Or, as a team.
  • 105. Many Other Platforms E Arduino RPi BeagleBone spark.io pinocc.io teensy
  • 107. Next Steps: Online Tutorials E http://arduino.cc/en/Tutorial http://playground.arduino.cc https://learn.sparkfun.com ! http://learn.adafruit.com http://learn.adafruit.com/category/learn-arduino ! ! google “arduino tutorials”
  • 108. Next Steps: Arduino Comic E http://www.jodyculkin.com/wp-content/uploads/2011/09/arduino-comic-latest3.pdf
  • 109. Online Resources E ARDUINO: www.arduino.cc, reference, tutorials SPARKFUN: www.sparkfun.com, components, devices, tutorials ADAFRUIT: www.adafruit.com, components, devices, tutorials MAKE MAGAZINE: www.makezine.com, magazine, books, stuff MAKER SHED: www.makershed.com, components, kits, stuff INSTRUCTABLES: www.instructables.com, tutorials RADIO SHACK: www.radioshack.com, components, devices, tutorials AMAZON: www.amazon.com, books, components, devices, tutorials O’REILLY: www.oreilly.com, books, tutorials, etc. ELECTRONIC GOLDMINE: http://www.goldmine-elec-products.com, components JAMECO: www.jameco.com, components MOUSER: www.mouser.com, components DIGIKEY: www.digikey.com, components !