Thomas Angielsky
Published © GPL3+

The 12. Birthday - Project 12

The next round in my birthday table decoration challenge.

BeginnerFull instructions provided4 hours2,215
The 12. Birthday - Project 12

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Code

Arduino Source Code for the 12 animation

Arduino
//Project 12


// Integrate libraries
#include <Servo.h>


Servo servo1;
Servo servo2;
Servo servo3;

int PinLed1=2;
int PinLed2=3;
int PinLed3=4;
int PinServo1=8;
int PinServo2=12;
int PinServo3=10;

int PinLed2G=A1;
int PinLed2B=A2;
int PinLed2R=A3;
int PinLed1G=A4;
int PinLed1B=A5;
int PinLed1R=A0;

int PosBottom=12;
int PosTop=89;



void setup() {
  servo1.attach(PinServo1); 
  servo2.attach(PinServo2); 
  servo3.attach(PinServo3); 
  pinMode(PinLed1, OUTPUT);
  pinMode(PinLed2, OUTPUT);
  pinMode(PinLed3, OUTPUT);

  pinMode(PinLed1R, OUTPUT);
  pinMode(PinLed1G, OUTPUT);
  pinMode(PinLed1B, OUTPUT);

  pinMode(PinLed2R, OUTPUT);
  pinMode(PinLed2G, OUTPUT);
  pinMode(PinLed2B, OUTPUT);
}


void Led1(boolean r, boolean g, boolean b) {
  digitalWrite(PinLed1R, r);
  digitalWrite(PinLed1G, g);
  digitalWrite(PinLed1B, b);
}

void Led2(boolean r, boolean g, boolean b) {
  digitalWrite(PinLed2R, r);
  digitalWrite(PinLed2G, g);
  digitalWrite(PinLed2B, b);
}


void Move1(int pos) {
  servo1.attach(PinServo1); 
  servo1.write(pos);
  delay(1000);
  servo1.detach();
}

void ServosOn() {
  servo1.attach(PinServo1); 
  servo2.attach(PinServo2); 
  servo3.attach(PinServo3); 
}

void ServosOff() {
  servo1.detach(); 
  servo2.detach(); 
  servo3.detach(); 
}


void Blink12(int r, int g, int b, int dauer1,  int dauer2) {
  //Led1 and 2 goes on an off
  Led1(r,g,b);
  Led2(r,g,b);
  delay(dauer1);
  Led1(LOW,LOW,LOW);
  Led2(LOW,LOW,LOW);
  delay(dauer2);

}

void RunningLight() {
  for (int i=0; i<4; i=i+1){
    digitalWrite(PinLed1, HIGH);
    digitalWrite(PinLed2, LOW);
    digitalWrite(PinLed3, LOW);
    delay(200);
    digitalWrite(PinLed1, LOW);
    digitalWrite(PinLed2, HIGH);
    digitalWrite(PinLed3, LOW);
    delay(200);
    digitalWrite(PinLed1, LOW);
    digitalWrite(PinLed2, LOW);
    digitalWrite(PinLed3, HIGH);
    delay(200);
    }
    digitalWrite(PinLed3, LOW);
}  

void loop() {

  //Lights off
  //all elements down
  ServosOff();

  
  Led1(LOW,LOW,LOW);
  Led2(LOW,LOW,LOW);
  servo1.write(PosBottom);
  delay(50);
  servo2.write(PosBottom);
 


  for (int i=0; i<3; i=i+1){
    servo3.write(PosBottom);
    Blink12(HIGH,LOW,LOW,200,50);
    Blink12(HIGH,HIGH,LOW,200,50);
    Blink12(HIGH,LOW,LOW,200,50);
    servo3.write(PosTop);
    Blink12(HIGH,HIGH,LOW,200,50);
    Blink12(HIGH,LOW,LOW,200,50);
    Blink12(HIGH,HIGH,LOW,200,50);
  }

  RunningLight();
  
  digitalWrite(PinLed1, HIGH);
  digitalWrite(PinLed2, HIGH);
  digitalWrite(PinLed3, HIGH);

  delay(2000);
  
  //Led1 and 2 flash briefly
  for (int i=0; i<6; i=i+1){
    Blink12(HIGH,HIGH,HIGH,100,50);
  }
  
  //2 to top
  servo2.write(PosTop);
  delay(1000);
  
  //Led1 and 2 flash briefly
  for (int i=0; i<6; i=i+1){
    Blink12(HIGH,HIGH,HIGH,100,50);
  }
  
  //1 to top
  servo1.write(PosTop);
  delay(1000);


  //1 and 2 to bottom and top again
  servo1.write(PosBottom);
  servo2.write(PosBottom);
  delay(1000);
  servo1.write(PosTop);
  servo2.write(PosTop);
  delay(1000);
  ServosOff();
  
  //Led1 and 2 flash briefly
  for (int i=0; i<6; i=i+1){
    Blink12(HIGH,HIGH,HIGH,100,50);
  }

  digitalWrite(PinLed1, LOW);
  digitalWrite(PinLed2, LOW);
  digitalWrite(PinLed3, LOW);
  
  //Colorchanges
  for (int i=0; i<2; i=i+1){
    for (int j=0; j<2; j=j+1){
      for (int k=0; k<2; k=k+1){
        Led1(i,j,k);
        Led2(k,i,j);
        delay(500);
        Led1(j,i,k);
        Led2(k,j,i);
        delay(500);
      }
    }
  }  

  //Led1 and 2 flash briefly
  for (int i=0; i<6; i=i+1){
    Blink12(HIGH,HIGH,HIGH,100,50);
  }
  
  delay(1000);
  RunningLight();


  delay(8000);
  
  ServosOff();
  servo1.write(PosBottom);
  servo2.write(PosBottom);
  delay(2000);

  //flash yellow
  for (int i=0; i<5; i=i+1){
    Blink12(HIGH,LOW,HIGH,100,100);
  }
  
  servo3.write(PosBottom);
  delay(1000);
  ServosOff();
  RunningLight();
  delay(8000);


}

Credits

Thomas Angielsky

Thomas Angielsky

18 projects • 36 followers
Mechanical engineer, maker, love woodwork, like Lazarus

Comments