Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Building Your Own Lightsaber
Search
Pete Hodgson
January 03, 2014
Programming
102
6.1k
Building Your Own Lightsaber
Presented at CodeMash 2014
Pete Hodgson
January 03, 2014
Tweet
Share
More Decks by Pete Hodgson
See All by Pete Hodgson
Migratory Patterns - KubeCon Salt Lake City, 2024
phodgson
0
12
A Journey Into Feature Toggles - OSCON Austin 2017
phodgson
5
510
Test-driven Client-side JS
phodgson
5
770
Functional Reactive JavaScript
phodgson
8
730
different.js - Forward JS 2014
phodgson
4
770
Railsconf2014
phodgson
7
1.4k
iOS Unit Testing Workshop
phodgson
3
460
Multi-platform Mobile with Calatrava - May 2013
phodgson
2
430
Unit testing with Kiwi - CocoaConf San Jose 2013
phodgson
1
580
Other Decks in Programming
See All in Programming
Quine, Polyglot, 良いコード
qnighy
4
630
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
770
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
500
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
4
1.4k
イベント駆動で成長して委員会
happymana
1
300
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
310
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
160
Macとオーディオ再生 2024/11/02
yusukeito
0
340
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
200
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
300
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
250
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Designing for humans not robots
tammielis
249
25k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Become a Pro
speakerdeck
PRO
25
5k
Fireside Chat
paigeccino
33
3k
Speed Design
sergeychernyshev
24
610
Facilitating Awesome Meetings
lara
50
6.1k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Intergalactic Javascript Robots from Outer Space
tanoku
268
27k
Writing Fast Ruby
sferik
627
61k
Transcript
Building your own Lightsaber
me me me Pete Hodgson Consultant at ThoughtWorks @ph1 blog.thepete.net
TSA Pro-Tip™
None
None
Green Field http://www.flickr.com/photos/jillclardy/3213748255
Continuous Integration
Feedback
None
Feedback
http://www.flickr.com/photos/johnmueller/52621490/ what if you have no build box?
None
Raspberry Pi
None
Raspberry Pi
visual indicator aka build light
None
None
Build Light
Pretending to work
raspberry pi & build light
done.
done. ?
build light build my own lightsaber
Learning by Doing
Learning Doing
Learning Doing Learning By Doing
Choose a “right-sized“ problem
build light build my own lightsaber
LEDs low voltage (can be powered via USB) bright flexible
(blinky! colors!)
all the colors
The Drefus Model
Beginner Expert
Beginner detailed step-by-step instructions no wider context
Beginner detailed step-by-step instructions no wider context Expert wider context
(goal) no details (yet)
Know where you are on the Drefus scale
None
all the colors
multi-color LEDs Search
multi-color LEDs Search an LED can only be one color…
but LEDs can come in many colors… solution: combine different colored LEDs
RGB color mixing
vary LED brightness Search
vary LED brightness Pulse Width Modulation P W M Search
Incandescent Bulb Voltage Brightness
LED Voltage Brightness
voltage 100% 0% time brightness: 100%
voltage 100% 0% time
50% on 50% off duty cycle voltage 100% 0% time
50% on 50% off duty cycle brightness: 50% voltage 100%
0% time
voltage 100% 0% time
25% on 75% off voltage 100% 0% time
brightness: 25% 25% on 75% off voltage 100% 0% time
Don't trust your intuition '
Red LED + Green LED + Blue LED + PWM
= all the colors!
None
Raspberry PI red LED green LED blue LED PWM
GPIO Pins
Raspberry Pi has two GPIO pins which capable of PWM
output. Our light needs three.
Arduino
Arduino is an Open-Source electronics prototyping platform based on flexible,
easy-to-use hardware and software. - arduino.cc
Arduino
Raspberry PI red LED green LED blue LED PWM
Raspberry PI red LED green LED blue LED PWM Arduino
???
Feature-creep as a learning tool
Raspberry PI red LED green LED blue LED PWM Arduino
???
None
baby steps, towards an eventual goal.
sketch 1 blinking an LED (Hello World of hardware)
None
IO pin ground pin
None
pin “high” (+ve voltage)
pin “low” (0 voltage)
int LED_PIN = 6;! ! void setup() { ! pinMode(LED_PIN,
OUTPUT); ! }! ! void loop() {! digitalWrite(LED_PIN, HIGH);! delay(1000); ! digitalWrite(LED_PIN, LOW);! delay(1000); ! }!
sketch 2 fading an LED (PWM)
None
int LED_PIN = 6;! int MAX_BRIGHTNESS = 255;! int brightness
= 0;! ! void setup() { ! pinMode(LED_PIN, OUTPUT); ! }! ! void loop() {! analogWrite(LED_PIN, brightness);! ! brightness = brightness + 5;! if( brightness > MAX_BRIGHTNESS )! brightness = 0;! ! delay(30);! }!
int LED_PIN = 6;! int MAX_BRIGHTNESS = 255;! int brightness
= 0;! ! void setup() { ! pinMode(LED_PIN, OUTPUT); ! }! ! void loop() {! analogWrite(LED_PIN, brightness);! ! brightness = brightness + 5;! if( brightness > MAX_BRIGHTNESS )! brightness = 0;! ! delay(30);! }! PWM
sketch 3 mixing colors
None
None
None
int RED_PIN = 3;! int GREEN_PIN = 5;! int BLUE_PIN
= 6;! int MAX_BRIGHTNESS = 255;! ! void setup() { ! pinMode(RED_PIN, OUTPUT );! pinMode(GREEN_PIN, OUTPUT );! pinMode(BLUE_PIN, OUTPUT );! }! ! void loop() {! byte color[3];! assignRandomColorTo(color);! displayColor(color);! delay(1000); ! }! ! void assignRandomColorTo(byte colorComponents[]){! colorComponents[0] = random(MAX_BRIGHTNESS);!
int RED_PIN = 3;! int GREEN_PIN = 5;! int BLUE_PIN
= 6;! int MAX_BRIGHTNESS = 255;! ! void setup() { ! pinMode(RED_PIN, OUTPUT );! pinMode(GREEN_PIN, OUTPUT );! pinMode(BLUE_PIN, OUTPUT );! }! ! void loop() {! byte color[3];! assignRandomColorTo(color);! displayColor(color);! delay(1000); ! }! ! void assignRandomColorTo(byte colorComponents[]){! colorComponents[0] = random(MAX_BRIGHTNESS);!
int RED_PIN = 3;! int GREEN_PIN = 5;! int BLUE_PIN
= 6;! int MAX_BRIGHTNESS = 255;! ! void setup() { ! pinMode(RED_PIN, OUTPUT );! pinMode(GREEN_PIN, OUTPUT );! pinMode(BLUE_PIN, OUTPUT );! }! ! void loop() {! byte color[3];! assignRandomColorTo(color);! displayColor(color);! delay(1000); ! }! ! void assignRandomColorTo(byte colorComponents[]){! colorComponents[0] = random(MAX_BRIGHTNESS);!
! void loop() {! byte color[3];! assignRandomColorTo(color);! displayColor(color);! delay(1000); !
}! ! void assignRandomColorTo(byte colorComponents[]){! colorComponents[0] = random(MAX_BRIGHTNESS);! colorComponents[1] = random(MAX_BRIGHTNESS);! colorComponents[2] = random(MAX_BRIGHTNESS);! }! ! void displayColor(byte colorComponents[]){! analogWrite( RED_PIN, colorComponents[0] );! analogWrite( GREEN_PIN, colorComponents[1] );! analogWrite( BLUE_PIN, colorComponents[2] ); ! }!
! void loop() {! byte color[3];! assignRandomColorTo(color);! displayColor(color);! delay(1000); !
}! ! void assignRandomColorTo(byte colorComponents[]){! colorComponents[0] = random(MAX_BRIGHTNESS);! colorComponents[1] = random(MAX_BRIGHTNESS);! colorComponents[2] = random(MAX_BRIGHTNESS);! }! ! void displayColor(byte colorComponents[]){! analogWrite( RED_PIN, colorComponents[0] );! analogWrite( GREEN_PIN, colorComponents[1] );! analogWrite( BLUE_PIN, colorComponents[2] ); ! }!
! void loop() {! byte color[3];! assignRandomColorTo(color);! displayColor(color);! delay(1000); !
}! ! void assignRandomColorTo(byte colorComponents[]){! colorComponents[0] = random(MAX_BRIGHTNESS);! colorComponents[1] = random(MAX_BRIGHTNESS);! colorComponents[2] = random(MAX_BRIGHTNESS);! }! ! void displayColor(byte colorComponents[]){! analogWrite( RED_PIN, colorComponents[0] );! analogWrite( GREEN_PIN, colorComponents[1] );! analogWrite( BLUE_PIN, colorComponents[2] ); ! }!
! void loop() {! byte color[3];! assignRandomColorTo(color);! displayColor(color);! delay(1000); !
}! ! void assignRandomColorTo(byte colorComponents[]){! colorComponents[0] = random(MAX_BRIGHTNESS);! colorComponents[1] = random(MAX_BRIGHTNESS);! colorComponents[2] = random(MAX_BRIGHTNESS);! }! ! void displayColor(byte colorComponents[]){! analogWrite( RED_PIN, colorComponents[0] );! analogWrite( GREEN_PIN, colorComponents[1] );! analogWrite( BLUE_PIN, colorComponents[2] ); ! }!
Raspberry PI red LED green LED blue LED PWM Arduino
???
Raspberry PI red LED green LED blue LED PWM Arduino
???
Raspberry PI red LED green LED blue LED PWM Arduino
serial
sketch 4 an echo server (serial IO)
void setup()! {! Serial.begin(57600); // start serial port at 57600
bps! }! ! void loop() {! waitForInput();! ! static char input[1025];! int bytesRead = Serial.readBytesUntil( '\n', input, 1024 );! ! if( bytesRead ){! String str = String(input);! str.toUpperCase();! Serial.println(str);! }! }! ! void waitForInput() {! while (Serial.available() <= 0) {! // busy loop! }! }!
void setup()! {! Serial.begin(57600); // start serial port at 57600
bps! }! ! void loop() {! waitForInput();! ! static char input[1025];! int bytesRead = Serial.readBytesUntil( '\n', input, 1024 );! ! if( bytesRead ){! String str = String(input);! str.toUpperCase();! Serial.println(str);! }! }! ! void waitForInput() {! while (Serial.available() <= 0) {! // busy loop! }! }!
void setup()! {! Serial.begin(57600); // start serial port at 57600
bps! }! ! void loop() {! waitForInput();! ! static char input[1025];! int bytesRead = Serial.readBytesUntil( '\n', input, 1024 );! ! if( bytesRead ){! String str = String(input);! str.toUpperCase();! Serial.println(str);! }! }! ! void waitForInput() {! while (Serial.available() <= 0) {! // busy loop! }! }!
void setup()! {! Serial.begin(57600); // start serial port at 57600
bps! }! ! void loop() {! waitForInput();! ! static char input[1025];! int bytesRead = Serial.readBytesUntil( '\n', input, 1024 );! ! if( bytesRead ){! String str = String(input);! str.toUpperCase();! Serial.println(str);! }! }! ! void waitForInput() {! while (Serial.available() <= 0) {! // busy loop! }! }!
void setup()! {! Serial.begin(57600); // start serial port at 57600
bps! }! ! void loop() {! waitForInput();! ! static char input[1025];! int bytesRead = Serial.readBytesUntil( '\n', input, 1024 );! ! if( bytesRead ){! String str = String(input);! str.toUpperCase();! Serial.println(str);! }! }! ! void waitForInput() {! while (Serial.available() <= 0) {! // busy loop! }! }!
void setup()! {! Serial.begin(57600); // start serial port at 57600
bps! }! ! void loop() {! waitForInput();! ! static char input[1025];! int bytesRead = Serial.readBytesUntil( '\n', input, 1024 );! ! if( bytesRead ){! String str = String(input);! str.toUpperCase();! Serial.println(str);! }! }! ! void waitForInput() {! while (Serial.available() <= 0) {! // busy loop! }! }!
Raspberry PI red LED green LED blue LED PWM Arduino
serial
GPIO Pins
Raspberry PI red LED green LED blue LED Arduino
Raspberry PI red LED green LED blue LED Arduino “ffaa11\n”
Raspberry PI red LED green LED blue LED Arduino “ffaa11\n”
Raspberry PI red LED green LED blue LED Arduino “ffaa11\n”
Much Learning Arduino- compatibles bareduinos LPC810 soldering! transistors protoboard fritzing
voltage regulators node.js cctray line-level converters command-line builds C++ on Arduino usb to serial external programmers OSS hardware
Resources
Resources
moredip/aphex (work in progress)
Have FUN!
Pete Hodgson @ph1
[email protected]
these slides http://bit.ly/buildlightsaber