Slide 1

Slide 1 text

Building your own Lightsaber

Slide 2

Slide 2 text

me me me Pete Hodgson Consultant at ThoughtWorks @ph1 blog.thepete.net

Slide 3

Slide 3 text

TSA Pro-Tip™

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Green Field http://www.flickr.com/photos/jillclardy/3213748255

Slide 7

Slide 7 text

Continuous Integration

Slide 8

Slide 8 text

Feedback

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Feedback

Slide 11

Slide 11 text

http://www.flickr.com/photos/johnmueller/52621490/ what if you have
 no build box?

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Raspberry Pi

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Raspberry Pi

Slide 16

Slide 16 text

visual indicator aka build light

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Build
 Light

Slide 20

Slide 20 text

Pretending to work

Slide 21

Slide 21 text

raspberry pi & build light

Slide 22

Slide 22 text

done.

Slide 23

Slide 23 text

done. ?

Slide 24

Slide 24 text

build light build my own lightsaber

Slide 25

Slide 25 text

Learning by Doing

Slide 26

Slide 26 text

Learning Doing

Slide 27

Slide 27 text

Learning Doing Learning By Doing

Slide 28

Slide 28 text

Choose a “right-sized“ problem

Slide 29

Slide 29 text

build light build my own lightsaber

Slide 30

Slide 30 text

LEDs low voltage (can be powered via USB) bright flexible (blinky! colors!)

Slide 31

Slide 31 text

all the colors

Slide 32

Slide 32 text

The Drefus Model

Slide 33

Slide 33 text

Beginner Expert

Slide 34

Slide 34 text

Beginner detailed step-by-step instructions no wider context

Slide 35

Slide 35 text

Beginner detailed step-by-step instructions no wider context Expert wider context (goal) no details (yet)

Slide 36

Slide 36 text

Know where you are on the Drefus scale

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

all the colors

Slide 39

Slide 39 text

multi-color LEDs Search

Slide 40

Slide 40 text

multi-color LEDs Search an LED can only be one color… but LEDs can come in many colors… solution: combine different colored LEDs

Slide 41

Slide 41 text

RGB
 color mixing

Slide 42

Slide 42 text

vary LED brightness Search

Slide 43

Slide 43 text

vary LED brightness Pulse Width Modulation P W M Search

Slide 44

Slide 44 text

Incandescent Bulb Voltage Brightness

Slide 45

Slide 45 text

LED Voltage Brightness

Slide 46

Slide 46 text

voltage 100% 0% time brightness: 100%

Slide 47

Slide 47 text

voltage 100% 0% time

Slide 48

Slide 48 text

50%
 on 50%
 off duty cycle voltage 100% 0% time

Slide 49

Slide 49 text

50%
 on 50%
 off duty cycle brightness: 50% voltage 100% 0% time

Slide 50

Slide 50 text

voltage 100% 0% time

Slide 51

Slide 51 text

25% on 75% off voltage 100% 0% time

Slide 52

Slide 52 text

brightness: 25% 25% on 75% off voltage 100% 0% time

Slide 53

Slide 53 text

Don't trust your intuition '

Slide 54

Slide 54 text

Red LED + Green LED + Blue LED + PWM = all the colors!

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Raspberry PI red LED green LED blue LED PWM

Slide 57

Slide 57 text

GPIO Pins

Slide 58

Slide 58 text

Raspberry Pi has two GPIO pins which capable of PWM output. Our light needs three.

Slide 59

Slide 59 text

Arduino

Slide 60

Slide 60 text

Arduino is an Open-Source electronics prototyping platform based on flexible, easy-to-use hardware and software. - arduino.cc

Slide 61

Slide 61 text

Arduino

Slide 62

Slide 62 text

Raspberry PI red LED green LED blue LED PWM

Slide 63

Slide 63 text

Raspberry PI red LED green LED blue LED PWM Arduino ???

Slide 64

Slide 64 text

Feature-creep as a learning tool

Slide 65

Slide 65 text

Raspberry PI red LED green LED blue LED PWM Arduino ???

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

baby steps, towards an eventual goal.

Slide 68

Slide 68 text

sketch 1 blinking an LED (Hello World of hardware)

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

IO pin ground pin

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

pin “high” (+ve voltage)

Slide 73

Slide 73 text

pin “low” (0 voltage)

Slide 74

Slide 74 text

int LED_PIN = 6;! ! void setup() { ! pinMode(LED_PIN, OUTPUT); ! }! ! void loop() {! digitalWrite(LED_PIN, HIGH);! delay(1000); ! digitalWrite(LED_PIN, LOW);! delay(1000); ! }!

Slide 75

Slide 75 text

sketch 2 fading an LED (PWM)

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

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);! }!

Slide 78

Slide 78 text

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

Slide 79

Slide 79 text

sketch 3 mixing colors

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

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);!

Slide 84

Slide 84 text

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);!

Slide 85

Slide 85 text

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);!

Slide 86

Slide 86 text

! 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] ); ! }!

Slide 87

Slide 87 text

! 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] ); ! }!

Slide 88

Slide 88 text

! 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] ); ! }!

Slide 89

Slide 89 text

! 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] ); ! }!

Slide 90

Slide 90 text

Raspberry PI red LED green LED blue LED PWM Arduino ???

Slide 91

Slide 91 text

Raspberry PI red LED green LED blue LED PWM Arduino ???

Slide 92

Slide 92 text

Raspberry PI red LED green LED blue LED PWM Arduino serial

Slide 93

Slide 93 text

sketch 4 an echo server (serial IO)

Slide 94

Slide 94 text

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! }! }!

Slide 95

Slide 95 text

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! }! }!

Slide 96

Slide 96 text

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! }! }!

Slide 97

Slide 97 text

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! }! }!

Slide 98

Slide 98 text

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! }! }!

Slide 99

Slide 99 text

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! }! }!

Slide 100

Slide 100 text

Raspberry PI red LED green LED blue LED PWM Arduino serial

Slide 101

Slide 101 text

GPIO Pins

Slide 102

Slide 102 text

Raspberry PI red LED green LED blue LED Arduino

Slide 103

Slide 103 text

Raspberry PI red LED green LED blue LED Arduino “ffaa11\n”

Slide 104

Slide 104 text

Raspberry PI red LED green LED blue LED Arduino “ffaa11\n”

Slide 105

Slide 105 text

Raspberry PI red LED green LED blue LED Arduino “ffaa11\n”

Slide 106

Slide 106 text

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

Slide 107

Slide 107 text

Resources

Slide 108

Slide 108 text

Resources

Slide 109

Slide 109 text

moredip/aphex (work in progress)

Slide 110

Slide 110 text

Have FUN!

Slide 111

Slide 111 text

Pete Hodgson @ph1 [email protected] these slides http://bit.ly/buildlightsaber