The below project was so that I can learn about the overall process of 3D printing and to learn some Arduino programming.
We will start with the programming.
The program is based on the concepts shown in the “Fade” and the “BlinkWithoutDelay” that Arduino has as examples.
With the combination of the two concepts this allowed me to not only fade up and down the brightness of the LEDs but also cycle through the LEDs I am using and their colors at the same time.
For those that may not already know the “delay()” function does not allow for other process in your code to happen while the delay period is being executed.
The code that I am using may not be the best possible way to go about the overall task however it does what I wanted it to do based on my understanding of the language.
There are comments in the below code to help explain what each part does.
// The below names the pins that will be controlling which LED will be on.:
int Green1 = 22;
int Red1 = 23;
int Green2 = 24;
int Red2 = 25;
int Green3 = 26;
int Red3 = 27;
int Green4 = 28;
int Red4 = 29;
int Green5 = 30;
int Red5 = 31;
int Green6 = 32;
int Red6 = 33;
int Blue1 = 34;
int Blue2 = 35;
int Blue3 = 36;
int Blue4 = 37;
int Blue5 = 38;
int Blue6 = 39;
// This is a part of the set up for the timing of the LED control.:
unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
// Another part of the timing.:
int interval1 = 20; //For controlling the overall speed of the fading affect.:
int interval2 = 1000; //This value will change as the code it running. It is for indicating when the LEDs should change states.:
// The below provides a known stating point for the code and the LEDs.:
int Redstate1 = LOW;
int Redstate2 = LOW;
int Redstate3 = LOW;
int Redstate4 = LOW;
int Redstate5 = LOW;
int Redstate6 = LOW;
int Bluestate1 = LOW;
int Bluestate2 = LOW;
int Bluestate3 = LOW;
int Bluestate4 = LOW;
int Bluestate5 = LOW;
int Bluestate6 = LOW;
int Greenstate1 = LOW;
int Greenstate2 = LOW;
int Greenstate3 = LOW;
int Greenstate4 = LOW;
int Greenstate5 = LOW;
int Greenstate6 = LOW;
// Apart of the fading affect.:
int brightness = 0; //starting point for the brightness of the fade.:
int fadeAmount = 5; //For controlling how much the brightness will change when it does change.:
// These names the pins that will be controlling the LED's fading.:
int Led1 = 7;
int Led2 = 6;
int Led3 = 5;
int Led4 = 4;
int Led5 = 3;
int Led6 = 2;
void setup() {
// The below is the setup code, to run once just before the looping.:
pinMode (Green1, OUTPUT);
pinMode (Red1, OUTPUT);
pinMode (Blue1, OUTPUT);
pinMode (Green2, OUTPUT);
pinMode (Red2, OUTPUT);
pinMode (Blue2, OUTPUT);
pinMode (Green3, OUTPUT);
pinMode (Red3, OUTPUT);
pinMode (Blue3, OUTPUT);
pinMode (Green4, OUTPUT);
pinMode (Red4, OUTPUT);
pinMode (Blue4, OUTPUT);
pinMode (Green5, OUTPUT);
pinMode (Red5, OUTPUT);
pinMode (Blue5, OUTPUT);
pinMode (Green6, OUTPUT);
pinMode (Red6, OUTPUT);
pinMode (Blue6, OUTPUT);
pinMode (Led1, OUTPUT);
pinMode (Led2, OUTPUT);
pinMode (Led3, OUTPUT);
pinMode (Led4, OUTPUT);
pinMode (Led5, OUTPUT);
pinMode (Led6, OUTPUT);
digitalWrite (Red1, Redstate1);
digitalWrite (Red2, Redstate2);
digitalWrite (Red3, Redstate3);
digitalWrite (Red4, Redstate4);
digitalWrite (Red5, Redstate5);
digitalWrite (Red6, Redstate6);
digitalWrite (Green1, Greenstate1);
digitalWrite (Green2, Greenstate2);
digitalWrite (Green3, Greenstate3);
digitalWrite (Green4, Greenstate4);
digitalWrite (Green5, Greenstate5);
digitalWrite (Green6, Greenstate6);
digitalWrite (Blue1, Bluestate1);
digitalWrite (Blue2, Bluestate2);
digitalWrite (Blue3, Bluestate3);
digitalWrite (Blue4, Bluestate4);
digitalWrite (Blue5, Bluestate5);
digitalWrite (Blue6, Bluestate6);
}
void loop() {
//This is where the fading is being controlled during the loop.:
if ((unsigned long)(millis() - previousMillis2) >= interval1) {
previousMillis2 = (unsigned long)millis();
analogWrite(Led1, brightness);
analogWrite(Led2, brightness);
analogWrite(Led3, brightness);
analogWrite(Led4, brightness);
analogWrite(Led5, brightness);
analogWrite(Led6, brightness);
brightness = brightness + fadeAmount;
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
}
//The below controls what state the LEDs will be in during the loop and when they will change.:
//Each if statement is checked for what LED states are in, when the correct if statement is found the LED states are updated.:
if ((unsigned long)(millis() - previousMillis1) >= interval2) {
previousMillis1 = (unsigned long)millis();
if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = HIGH;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == HIGH) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = HIGH;
Redstate2 = HIGH;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == HIGH) && (Redstate2 == HIGH) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = HIGH;
Redstate2 = HIGH;
Redstate3 = HIGH;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == HIGH) && (Redstate2 == HIGH) && (Redstate3 == HIGH) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = HIGH;
Redstate3 = HIGH;
Redstate4 = HIGH;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == HIGH) && (Redstate3 == HIGH) && (Redstate4 == HIGH) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = HIGH;
Redstate4 = HIGH;
Redstate5 = HIGH;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == HIGH) && (Redstate4 == HIGH) && (Redstate5 == HIGH) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = HIGH;
Redstate5 = HIGH;
Redstate6 = HIGH;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == HIGH) && (Redstate5 == HIGH) && (Redstate6 == HIGH) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = HIGH;
Redstate6 = HIGH;
Greenstate1 = HIGH;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == HIGH) && (Redstate6 == HIGH) && (Greenstate1 == HIGH) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = HIGH;
Greenstate1 = HIGH;
Greenstate2 = HIGH;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == HIGH) && (Greenstate1 == HIGH) && (Greenstate2 == HIGH) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = HIGH;
Greenstate2 = HIGH;
Greenstate3 = HIGH;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == HIGH) && (Greenstate2 == HIGH) && (Greenstate3 == HIGH) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = HIGH;
Greenstate3 = HIGH;
Greenstate4 = HIGH;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == HIGH) && (Greenstate3 == HIGH) && (Greenstate4 == HIGH) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = HIGH;
Greenstate4 = HIGH;
Greenstate5 = HIGH;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == HIGH) && (Greenstate4 == HIGH) && (Greenstate5 == HIGH) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = HIGH;
Greenstate5 = HIGH;
Greenstate6 = HIGH;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == HIGH) && (Greenstate5 == HIGH) && (Greenstate6 == HIGH) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = HIGH;
Greenstate6 = HIGH;
Bluestate1 = HIGH;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == HIGH) && (Greenstate6 == HIGH) && (Bluestate1 == HIGH) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = HIGH;
Bluestate1 = HIGH;
Bluestate2 = HIGH;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == HIGH) && (Bluestate1 == HIGH) && (Bluestate2 == HIGH) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = HIGH;
Bluestate2 = HIGH;
Bluestate3 = HIGH;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == HIGH) && (Bluestate2 == HIGH) && (Bluestate3 == HIGH) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = HIGH;
Bluestate3 = HIGH;
Bluestate4 = HIGH;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == HIGH) && (Bluestate3 == HIGH) && (Bluestate4 == HIGH) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = HIGH;
Bluestate4 = HIGH;
Bluestate5 = HIGH;
Bluestate6 = LOW;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == HIGH) && (Bluestate4 == HIGH) && (Bluestate5 == HIGH) && (Bluestate6 == LOW)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = HIGH;
Bluestate5 = HIGH;
Bluestate6 = HIGH;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == HIGH) && (Bluestate5 == HIGH) && (Bluestate6 == HIGH)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = HIGH;
Bluestate6 = HIGH;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == HIGH) && (Bluestate6 == HIGH)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = HIGH;
}
else if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == HIGH)) {
Redstate1 = LOW;
Redstate2 = LOW;
Redstate3 = LOW;
Redstate4 = LOW;
Redstate5 = LOW;
Redstate6 = LOW;
Greenstate1 = LOW;
Greenstate2 = LOW;
Greenstate3 = LOW;
Greenstate4 = LOW;
Greenstate5 = LOW;
Greenstate6 = LOW;
Bluestate1 = LOW;
Bluestate2 = LOW;
Bluestate3 = LOW;
Bluestate4 = LOW;
Bluestate5 = LOW;
Bluestate6 = LOW;
}
//The below writes to the LED control pins the LED states from the if statements.:
digitalWrite (Red1, Redstate1);
digitalWrite (Red2, Redstate2);
digitalWrite (Red3, Redstate3);
digitalWrite (Red4, Redstate4);
digitalWrite (Red5, Redstate5);
digitalWrite (Red6, Redstate6);
digitalWrite (Green1, Greenstate1);
digitalWrite (Green2, Greenstate2);
digitalWrite (Green3, Greenstate3);
digitalWrite (Green4, Greenstate4);
digitalWrite (Green5, Greenstate5);
digitalWrite (Green6, Greenstate6);
digitalWrite (Blue1, Bluestate1);
digitalWrite (Blue2, Bluestate2);
digitalWrite (Blue3, Bluestate3);
digitalWrite (Blue4, Bluestate4);
digitalWrite (Blue5, Bluestate5);
digitalWrite (Blue6, Bluestate6);
// The below changes how fast the LED states are cycled through or resets the interval value.:
if ((Redstate1 == LOW) && (Redstate2 == LOW) && (Redstate3 == LOW) && (Redstate4 == LOW) && (Redstate5 == LOW) && (Redstate6 == LOW) && (Greenstate1 == LOW) && (Greenstate2 == LOW) && (Greenstate3 == LOW) && (Greenstate4 == LOW) && (Greenstate5 == LOW) && (Greenstate6 == LOW) && (Bluestate1 == LOW) && (Bluestate2 == LOW) && (Bluestate3 == LOW) && (Bluestate4 == LOW) && (Bluestate5 == LOW) && (Bluestate6 == LOW)) {
if (interval2 == 0) {
interval2 = 1000;
}
else {
interval2 -= 50;
}
}
}
}
The above code was tested and uploaded to the below Arduino and circuit shown in the image.
Next will be the 3D printing part of the project.
After drawing up the project in On-Shape I needed to verify the sizing of the various items.
So first we printed the outer box as the other pieces will be sized to it.
Outer box.
I then had just the bottom of the liner printed to check the inner liner’s widths/lengths
This piece’s widths did fit well so I had the full liner printed.
Inner liner bottom test piece.
Although the width/length of the liner fit nicely the corners of the object proved too irregular and as a result it did not really fit in the outer box very well. So I modified the inner liner.
Inner liner 1
As you can see below the modification was a 5mm chamfer on each of the vertical corners
This did make the liner fit albeit snuggly.
Inner liner 2
I then had the lid printed. Which does fit nicely on the whole project.
The below is the arduino and circuit mounted/placed in the inner liner
The below is the inner liner with project assembled in the outer box.
Internal power cord assembled and installed.
Fully assembled box!
The below is a viewable link to On Shape’s site for the project.
Lid.stl (78.0 KB)
LED box liner.stl (625.6 KB)
Outer box.stl (280.0 KB)
Materials used
-Filament
–RED 0.112" PLA (RM-PL0127)
—For the outer box 42meters took ~21hrs on the lulzbot
–White 0.112" PLA (RM-PL0128)
—For the inner liner 45.5meters took ~18hrs on the lulzbot
–Black 0.112" PLA (RM-PL0121)
—For the lid 10.4meters took ~4hrs on the lulzbot
-1x 2.10mm by 5.50mm panel jack (54-00063)
-1x Cable with 2.10mm by 5.50mm plug (10-02225)
-24x NPN transistor (2N3904BU)
-1x Wire kit various sizes 22awg 350pcs in kit (WK-1)
–Specifically used
—18x of the 100mm yellow wires
—6x of the 78mm orange wires
-2x solid core red wire
-2x solid core black wire
-6x RGB 4-lead through hole LEDs (HV-5RGB25)
-1x Arduino Mega2560 (A000067)
-1x Short breadboard 3.20" L x 2.00" W (FIT0096)
-6x 100Ω through hole resistors no specific item number as these are ones I had already. However the CFM12JT100R should work.
-6x 470Ω through hole resistors (SFR16S0004700JA500)
-6x screws (1551ATS100)
The below is the schematic for the circuit.
Thank you for taking a look at the project, I hope you liked it!