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
6k
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
A Journey Into Feature Toggles - OSCON Austin 2017
phodgson
5
490
Test-driven Client-side JS
phodgson
5
760
Functional Reactive JavaScript
phodgson
8
710
different.js - Forward JS 2014
phodgson
4
750
Railsconf2014
phodgson
7
1.3k
iOS Unit Testing Workshop
phodgson
3
450
Multi-platform Mobile with Calatrava - May 2013
phodgson
2
410
Unit testing with Kiwi - CocoaConf San Jose 2013
phodgson
1
550
Automated Mobile Acceptance Testing Presentation - mdevcon 2013
phodgson
2
670
Other Decks in Programming
See All in Programming
AWS CDKを用いたセキュアなCI/CDパイプラインの構築 / Build a secure CI/CD pipeline using AWS CDK
seike460
PRO
3
550
Rails 8 Frontend: 10 commandments & 7 deadly sins in 2025
yshmarov
1
600
ROS 2のZenoh対応とZenohのROS 2対応
takasehideki
2
250
Infrastructure as Code でセキュリティを楽にしよう!
konokenj
5
1.4k
CSC305 Lecture 01
javiergs
PRO
1
140
[KR] Server Driven Compose With Firebase
skydoves
2
140
.NET Aspireのクラウド対応検証: Azureと他環境での実践
ymd65536
1
250
Frontend Magic mit CSS Houdini
joergneumann
0
420
5年分のツケを一気に払った話
soogie
3
1.2k
個人開発で使ってるやつを紹介する回
yohfee
1
670
Iteratorでページネーションを実現する
sonatard
3
700
利用者視点で考える、イテレータとの上手な付き合い方
syumai
4
210
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
50
13k
Intergalactic Javascript Robots from Outer Space
tanoku
268
27k
Code Review Best Practice
trishagee
62
16k
Building a Modern Day E-commerce SEO Strategy
aleyda
37
6.8k
Designing with Data
zakiwarfel
98
5.1k
Into the Great Unknown - MozCon
thekraken
30
1.4k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
41
9.2k
Building Applications with DynamoDB
mza
90
6k
What the flash - Photography Introduction
edds
67
11k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Imperfection Machines: The Place of Print at Facebook
scottboms
263
13k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.7k
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