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
34
A Journey Into Feature Toggles - OSCON Austin 2017
phodgson
5
520
Test-driven Client-side JS
phodgson
5
780
Functional Reactive JavaScript
phodgson
8
740
different.js - Forward JS 2014
phodgson
4
780
Railsconf2014
phodgson
7
1.4k
iOS Unit Testing Workshop
phodgson
3
470
Multi-platform Mobile with Calatrava - May 2013
phodgson
2
440
Unit testing with Kiwi - CocoaConf San Jose 2013
phodgson
1
590
Other Decks in Programming
See All in Programming
layerx_20241129.pdf
kyoheig3
2
280
103 Early Hints
sugi_0000
1
180
Symfony Mapper Component
soyuka
2
690
Java 23の概要とJava Web Frameworkの現状 / Java 23 and Java web framework
kishida
2
400
暇に任せてProxmoxコンソール 作ってみました
karugamo
1
680
eBPF Deep Dive: Architecture and Safety Mechanisms
takehaya
12
1.4k
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4k
macOS なしで iOS アプリを開発する(※ただし xxx に限る)
mitsuharu
1
180
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
240
N.E.X.T LEVEL
pluu
2
290
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
430
バグを見つけた?それAppleに直してもらおう!
uetyo
0
140
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
Documentation Writing (for coders)
carmenintech
66
4.5k
Building Applications with DynamoDB
mza
91
6.1k
Bash Introduction
62gerente
608
210k
Fireside Chat
paigeccino
34
3.1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
800
Docker and Python
trallard
41
3.1k
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 phodgson@thoughtworks.com these slides http://bit.ly/buildlightsaber