Movatterモバイル変換


[0]ホーム

URL:


Upgrade to Pro — share decks privately, control downloads, hide ads and more …
Speaker DeckSpeaker Deck
Speaker Deck

Building Your Own Lightsaber

Avatar for Pete Hodgson Pete Hodgson
January 03, 2014

Building Your Own Lightsaber

Presented at CodeMash 2014

Avatar for Pete Hodgson

Pete Hodgson

January 03, 2014
Tweet

More Decks by Pete Hodgson

See All by Pete Hodgson

Other Decks in Programming

See All in Programming

Featured

See All Featured

Transcript

  1. Building your own Lightsaber

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

  3. TSA Pro-Tip™

  4. None
  5. None
  6. Green Field http://www.flickr.com/photos/jillclardy/3213748255

  7. Continuous Integration

  8. Feedback

  9. None
  10. Feedback

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

  12. None
  13. Raspberry Pi

  14. None
  15. Raspberry Pi

  16. visual indicator aka build light

  17. None
  18. None
  19. Build
 Light

  20. Pretending to work

  21. raspberry pi & build light

  22. done.

  23. done. ?

  24. build light build my own lightsaber

  25. Learning by Doing

  26. Learning Doing

  27. Learning Doing Learning By Doing

  28. Choose a “right-sized“ problem

  29. build light build my own lightsaber

  30. LEDs low voltage (can be powered via USB) bright flexible

    (blinky! colors!)
  31. all the colors

  32. The Drefus Model

  33. Beginner Expert

  34. Beginner detailed step-by-step instructions no wider context

  35. Beginner detailed step-by-step instructions no wider context Expert wider context

    (goal) no details (yet)
  36. Know where you are on the Drefus scale

  37. None
  38. all the colors

  39. multi-color LEDs Search

  40. multi-color LEDs Search an LED can only be one color…

    but LEDs can come in many colors… solution: combine different colored LEDs
  41. RGB
 color mixing

  42. vary LED brightness Search

  43. vary LED brightness Pulse Width Modulation P W M Search

  44. Incandescent Bulb Voltage Brightness

  45. LED Voltage Brightness

  46. voltage 100% 0% time brightness: 100%

  47. voltage 100% 0% time

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

  49. 50%
 on 50%
 off duty cycle brightness: 50% voltage 100%

    0% time
  50. voltage 100% 0% time

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

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

  53. Don't trust your intuition '

  54. Red LED + Green LED + Blue LED + PWM

    = all the colors!
  55. None
  56. Raspberry PI red LED green LED blue LED PWM

  57. GPIO Pins

  58. Raspberry Pi has two GPIO pins which capable of PWM

    output. Our light needs three.
  59. Arduino

  60. Arduino is an Open-Source electronics prototyping platform based on flexible,

    easy-to-use hardware and software. - arduino.cc
  61. Arduino

  62. Raspberry PI red LED green LED blue LED PWM

  63. Raspberry PI red LED green LED blue LED PWM Arduino

    ???
  64. Feature-creep as a learning tool

  65. Raspberry PI red LED green LED blue LED PWM Arduino

    ???
  66. None
  67. baby steps, towards an eventual goal.

  68. sketch 1 blinking an LED (Hello World of hardware)

  69. None
  70. IO pin ground pin

  71. None
  72. pin “high” (+ve voltage)

  73. pin “low” (0 voltage)

  74. int LED_PIN = 6;! ! void setup() { ! pinMode(LED_PIN,

    OUTPUT); ! }! ! void loop() {! digitalWrite(LED_PIN, HIGH);! delay(1000); ! digitalWrite(LED_PIN, LOW);! delay(1000); ! }!
  75. sketch 2 fading an LED (PWM)

  76. None
  77. 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);! }!
  78. 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
  79. sketch 3 mixing colors

  80. None
  81. None
  82. None
  83. 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);!
  84. 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);!
  85. 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);!
  86. ! 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] ); ! }!
  87. ! 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] ); ! }!
  88. ! 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] ); ! }!
  89. ! 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] ); ! }!
  90. Raspberry PI red LED green LED blue LED PWM Arduino

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

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

    serial
  93. sketch 4 an echo server (serial IO)

  94. 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! }! }!
  95. 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! }! }!
  96. 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! }! }!
  97. 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! }! }!
  98. 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! }! }!
  99. 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! }! }!
  100. Raspberry PI red LED green LED blue LED PWM Arduino

    serial
  101. GPIO Pins

  102. Raspberry PI red LED green LED blue LED Arduino

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

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

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

  106. 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
  107. Resources

  108. Resources

  109. moredip/aphex (work in progress)

  110. Have FUN!

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


[8]ページ先頭

©2009-2025 Movatter.jp