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
103
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
20
A Journey Into Feature Toggles - OSCON Austin 2017
phodgson
5
510
Test-driven Client-side JS
phodgson
5
780
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
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
860
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
1.8k
現場で役立つモデリング 超入門
masuda220
PRO
15
3.2k
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
120
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
Quine, Polyglot, 良いコード
qnighy
4
640
最新TCAキャッチアップ
0si43
0
140
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
RubyLSPのマルチバイト文字対応
notfounds
0
110
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
Better Code Design in PHP
afilina
PRO
0
120
Featured
See All Featured
Statistics for Hackers
jakevdp
796
220k
Done Done
chrislema
181
16k
Navigating Team Friction
lara
183
14k
Become a Pro
speakerdeck
PRO
25
5k
We Have a Design System, Now What?
morganepeng
50
7.2k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
What's new in Ruby 2.0
geeforr
343
31k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Ruby is Unlike a Banana
tanoku
97
11k
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