Homework - Rawi Fayad

Hello!
So what I had in mind was to light and animate (on a basic level) the pieces of a 'Tetris lamp' that no longer works (photo attached).
This image has been resized to fit in the page. Click to enlarge.

What I wanted to do was make the yellow box (the 'head') rotate/swivel, and possibly the 'arms' as well, using I imagine a standard servo actuator. As well as this, I'll be inserting various LEDs in the parts (Neopixel ring in the 'head', neopixel sticks/individual LEDs in the rest of the pieces) 

I also initially considered adding sound/music to it (sound effects, or maybe the tetris music) but not sure I'd get around to buying/ordering and actually adding that in in time, so I'm not including that for the time being.

Materials (either owned or ordered and on their way)
- Arduino Nano & terminal

- NeoPixel ring (for the 'head')
- Neopixel stick
- LEDs

- Adafruit standard servo

- Solderless breadboard, jumper wires, 12V power supply, push-switches, etc


Other stuff I might need:

- Simple straight/angle brackets for connecting the pieces together

- Laser pointers on the 'arms'

- Very possibly will discover I missed something or have the wrong part at some point when I actually start putting it all together....

Comments

  • Here is the first peice of code I wrote so far, designed for a NeoPixel strip across the blue 'hip' bar. It is meant to light up each LED individually, then turn it off and move to the next one, etc. Once it gets to the end of the strip, it repeats in the opposite direction. Unfortunately as my components have only just arrived, I have not had a chance to test the code yet, but wanted to get started drafting it to see if it looks correct.

    #include <Adafruit_NeoPixel.h>
    #include <avr/power.h>

    #define PIN 6
    void setup() {
      strip.begin();
      strip.show(); // Initialize all pixels to 'off'
    }

    //The following code individually turns on each LED in succession to white and moves across strip, back and forth, with each LED turning off before the next one turns on
    void loop() {
      for (int led=0; led<8; led++){
        strip.setPixelColor(led, 250, 250, 250); 
        strip.show();    //turn on LED in white
        delay(10);
        strip.setPixelColor (led, 0, 0, 0);
        strip.show();  //turn off each LED before turning on the next one
        delay(10)
      }
      for (int led=8; led>=0; led--){
        stip.setPixelColor(led, 250, 250, 250);
        strip.show();  //Same as above but in the other direction, starting at led no. 8
        delay(10);
        strip.setPixelColor (led, 0, 0, 0);
        strip.show();
        delay (10);
      }
    }
  • This code is for the Neopixels on the 'arms' - pretty basic, just wants the LED strip to 'fill', ie light the LEDs successively, in one direction, then turn the strip off and start over. 

    #include <Adafruit_NeoPixel.h>
    #include <avr/power.h>

    #define PIN 6

    void setup() {
      strip.begin();
      strip.show(); // Initialize all pixels to 'off'
    }

    void loop() {
      for (int led=0, led<8, led++)
      strip.setPixelColor (led, 250, 250, 250);
      strip.show();
      delay(10);
    }
  • This code runs the 'head' ring and 'chest' strip, in succession. I want to see if I can get them going simultaneously.

    #include <Adafruit_NeoPixel.h>
    #include <avr/power.h>

    // Parameter 1 = number of pixels in strip
    // Parameter 2 = Arduino pin number (most are valid)
    // Parameter 3 = pixel type flags, add together as needed:
    //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
    //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
    //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
    //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
    Adafruit_NeoPixel strip_head = Adafruit_NeoPixel(12, 5, NEO_GRB + NEO_KHZ800);
    Adafruit_NeoPixel strip_hip = Adafruit_NeoPixel(8, 6, NEO_GRB + NEO_KHZ800);

    // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
    // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
    // and minimize distance between Arduino and first pixel.  Avoid connecting
    // on a live circuit...if you must, connect GND first.

    void setup() {
      strip_head.begin();
      strip_head.show(); // Initialize all pixels to 'off'
       strip_hip.begin();
      strip_hip.show();
    }

    //The following code loops around the ring in red, white, and blue successively (turning on each LED individually)
    void loop() {
      for (int led = 0; led < 12; led++) {
        strip_head.setPixelColor(led, 250, 0, 0);
        strip_head.show();    //turn on LEDs in red, successively
        delay(10);
        strip_head.setPixelColor(led, 0, 0, 0);
        strip_head.show();    //turn off each LED after moving on to the next one
        delay(10);
      }

      for (int led = 0; led < 12; led++) {
        strip_head.setPixelColor(led, 250, 250, 250);
        strip_head.show();    //turn on LEDs in white, successively
        delay(10);
        strip_head.setPixelColor(led, 0, 0, 0);
        strip_head.show();    //turn off each LED after moving on to the next one
        delay(10);
      }

      for (int led = 0; led < 12; led++) {
        strip_head.setPixelColor(led, 0, 0, 250);
        strip_head.show();    //turn on LEDs in blue, successively
        delay(10);
        strip_head.setPixelColor(led, 0, 0, 0);
        strip_head.show();    //turn off each LED after moving on to the next one
        delay(10);
      }



    //The following code individually turns on each LED in succession to orange (one direction) and blue (other direction) and moves across strip, back and forth, with each LED turning off before the next one turns on
      for (int led=0; led<8; led++){
        strip_hip.setPixelColor(led, 250, 160, 0); 
        strip_hip.show();    //turn on LEDs in orange, successively
        delay(10);
        strip_hip.setPixelColor (led, 0, 0, 0);
        strip_hip.show();  //turn off each LED before turning on the next one
        delay(10);
      }
      for (int led=8; led>=0; led--){
        strip_hip.setPixelColor(led, 0, 0, 250);
        strip_hip.show();  //Same as above but in the other direction and in blue
        delay(10);
        strip_hip.setPixelColor (led, 0, 0, 0);
        strip_hip.show();
        delay (10);
      }
    }
     
  • edited May 2015
    this is for the 'arms' - but the Neopixels i'll be using for them haven't arrived, so I can't run this as well as the chest at the moment (only have the one strip for now)

    #include <Adafruit_NeoPixel.h>
    #include <avr/power.h>

    #define PIN 4

    // Parameter 1 = number of pixels in strip
    // Parameter 2 = Arduino pin number (most are valid)
    // Parameter 3 = pixel type flags, add together as needed:
    //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
    //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
    //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
    //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);

    // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
    // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
    // and minimize distance between Arduino and first pixel.  Avoid connecting
    // on a live circuit...if you must, connect GND first.

    void setup() {
      strip.begin();
      strip.show(); // Initialize all pixels to 'off'
    }

    //The following code individually turns on each LED in succession to white and moves across strip, back and forth, with each LED turning off before the next one turns on
    void loop() {
      for (int led=0; led<8; led++){
        strip.setPixelColor(led, 85, 85, 85); 
        delay(5);
        strip.show();    //turn on LEDs in white, successively
        delay(50);
      }
      for (int led=0; led<8; led++){
        strip.setPixelColor(led, 0, 0, 0); 
        delay(5);
        strip.show();    //turn off LEDs, successively
        delay(5);
      }  
     for (int led=0; led<8; led++){
        strip.setPixelColor(led, 0, 0, 250); 
        delay(5);
        strip.show();    //turn on LEDs in blue, successively
        delay(50);
      }
      for (int led=0; led<8; led++){
        strip.setPixelColor(led, 0, 0, 0); 
        delay(5);
        strip.show();    //turn off LEDs, successively
        delay(50);
      }
      }  
  • This is the code for the 'legs', when the strips arrive

    #include <Adafruit_NeoPixel.h>
    #include <avr/power.h>

    #define PIN 3

    // Parameter 1 = number of pixels in strip
    // Parameter 2 = Arduino pin number (most are valid)
    // Parameter 3 = pixel type flags, add together as needed:
    //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
    //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
    //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
    //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);

    // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
    // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
    // and minimize distance between Arduino and first pixel.  Avoid connecting
    // on a live circuit...if you must, connect GND first.

    void setup() {
      strip.begin();
      strip.show(); // Initialize all pixels to 'off'
    }


    void loop() {
      for (int led=0; led<8; led++){
        strip.setPixelColor(led, 85, 85, 85); //turns on LEDS in white, successively, to fill strip
        delay(5);
        strip.setPixelColor (led, 0, 0, 0);
        strip.show();    //turn off LEDs, successively
        delay(50);
      }
      for (int led=0; led<8; led++){
        strip.setPixelColor(led, 0, 250, 0); 
        strip.show(); //'fill' strip with green, and stay 'on' in green
        delay(20);
      }  
     for (int led=0; led<8; led++){
        strip.setPixelColor(led, 250, 0, 0); 
        delay(5);
        strip.show();    //'fill' already-green strip with red
        delay(50);
      }
      }  
  • And this is the code for the 'head' rotation servo. Very basic stuff, just turning the head back and forth with 50ms wait. The 'arms' servo code is identical except with a much longer wait of 500ms (and both arms will be coded the same and moving identically)

    /* Sweep
     by BARRAGAN <http://barraganstudio.com>
     This example code is in the public domain.

     modified 8 Nov 2013
     by Scott Fitzgerald
    */ 

    #include <Servo.h> 
     
    Servo myservo;  // create servo object to control a servo 
                    // twelve servo objects can be created on most boards
     
    int pos = 0;    // variable to store the servo position 
     
    void setup() 
      myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
     
    void loop() 
      for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees 
      {                                  // in steps of 1 degree 
        myservo.write(pos);              // tell servo to go to position in variable 'pos' 
        delay(50);                       // waits 50ms for the servo to reach the position 
      } 
      for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees 
      {                                
        myservo.write(pos);              // tell servo to go to position in variable 'pos' 
        delay(50);                       // waits 50ms for the servo to reach the position 
      } 

  • edited May 2015
    The build so far...

    Still to be added: The arms (to be connected via servos and angle brackets on the blue hip bar), the servo attaching the head to the purple chest, and NeoPixel strips in both the arms, and the legs (vertical strips on the lower sections of the leg)

    Parts were attached together using self-adhesive velcro pads, either on their own (in the case of attaching the 'legs' to the blue 'hip' bar), or together with the straight bracket and screw attaching the 'hip' to the purple 'chest' piece. 

  • Soldering to the original Tetris Lamp LEDs
  • edited May 2015
    The back of the current build. Holes for the wires were either cut in the plastic, or melted through with the soldering iron.
  • edited May 2015
    First test of the 'Arms' code:


  • edited May 2015
    'Head' and 'chest' in the dark




  • Test at the current build (head, chest, and 'hip' lights)


  • Current code:

    #include <Adafruit_NeoPixel.h>
    #include <avr/power.h>

    // Parameter 1 = number of pixels in strip
    // Parameter 2 = Arduino pin number (most are valid)
    // Parameter 3 = pixel type flags, add together as needed:
    //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
    //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
    //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
    //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
    Adafruit_NeoPixel strip_head = Adafruit_NeoPixel(12, 5, NEO_GRB + NEO_KHZ800);
    Adafruit_NeoPixel strip_hip = Adafruit_NeoPixel(8, 6, NEO_GRB + NEO_KHZ800);
    Adafruit_NeoPixel strip_limbs = Adafruit_NeoPixel(8, 7, NEO_GRB + NEO_KHZ800);

    // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
    // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
    // and minimize distance between Arduino and first pixel.  Avoid connecting
    // on a live circuit...if you must, connect GND first.

    void setup() {
      strip_head.begin();
      strip_head.show(); // Initialize all pixels to 'off'
      strip_hip.begin();
      strip_hip.show();
      strip_limbs.begin();
      strip_limbs.show();
    }

    //The following code loops around the ring in red, white, and blue successively (turning on each LED individually)
    void loop() {
      for (int led = 0; led < 12; led++) {
        strip_head.setPixelColor(led, 250, 0, 0);
        strip_head.show();    //turn on LEDs in red, successively
        delay(10);
        strip_head.setPixelColor(led, 0, 0, 0);
        strip_head.show();    //turn off each LED after moving on to the next one
        delay(10);
      }

      for (int led = 0; led < 12; led++) {
        strip_head.setPixelColor(led, 250, 250, 250);
        strip_head.show();    //turn on LEDs in white, successively
        delay(10);
        strip_head.setPixelColor(led, 0, 0, 0);
        strip_head.show();    //turn off each LED after moving on to the next one
        delay(10);
      }

      for (int led = 0; led < 12; led++) {
        strip_head.setPixelColor(led, 0, 0, 250);
        strip_head.show();    //turn on LEDs in blue, successively
        delay(10);
        strip_head.setPixelColor(led, 0, 0, 0);
        strip_head.show();    //turn off each LED after moving on to the next one
        delay(10);
      }



      //The following code individually turns on each LED in succession to orange (one direction) and blue (other direction) and moves across strip, back and forth, with each LED turning off before the next one turns on
      for (int led = 0; led < 8; led++) {
        strip_hip.setPixelColor(led, 250, 160, 0);
        strip_hip.show();    //turn on LEDs in orange, successively
        delay(10);
        strip_hip.setPixelColor (led, 0, 0, 0);
        strip_hip.show();  //turn off each LED before turning on the next one
        delay(10);
      }
      for (int led = 8; led >= 0; led--) {
        strip_hip.setPixelColor(led, 0, 0, 250);
        strip_hip.show();  //Same as above but in the other direction and in blue
        delay(10);
        strip_hip.setPixelColor (led, 0, 0, 0);
        strip_hip.show();
        delay (10);
      }

      for (int led = 0; led < 8; led++) {
        strip_limbs.setPixelColor (led, 250, 250, 250);
        strip_limbs.show();
        delay(5);
        strip_limbs.setPixelColor(led, 0, 0, 0);
        delay(50);
        strip_limbs.show();
      }
    }

Sign In or Register to comment.