Building Your Own Lightsaber

Building Your Own Lightsaber

Presented at CodeMash 2014

Fe6b81005d1553accd6b2a28f6a2bef1?s=128

Pete Hodgson

January 03, 2014
Tweet

Transcript

  1. 4.
  2. 5.
  3. 9.
  4. 10.
  5. 12.
  6. 14.
  7. 17.
  8. 18.
  9. 22.
  10. 23.
  11. 37.
  12. 40.

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

    but LEDs can come in many colors… solution: combine different colored LEDs
  13. 54.
  14. 55.
  15. 57.
  16. 58.
  17. 59.
  18. 60.
  19. 61.
  20. 66.
  21. 69.
  22. 71.
  23. 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); ! }!
  24. 76.
  25. 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);! }!
  26. 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
  27. 80.
  28. 81.
  29. 82.
  30. 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);!
  31. 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);!
  32. 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);!
  33. 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] ); ! }!
  34. 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] ); ! }!
  35. 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] ); ! }!
  36. 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] ); ! }!
  37. 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! }! }!
  38. 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! }! }!
  39. 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! }! }!
  40. 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! }! }!
  41. 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! }! }!
  42. 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! }! }!
  43. 101.
  44. 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
  45. 107.
  46. 108.
  47. 110.