光る箱

以下は、私が3Dプリンティングのトータルプロセスを学び、Arduinoのプログラミングを学ぶためのプロジェクトでした。

Fully%20assembled%20box

プログラミングから始めましょう。
このプログラムは、Arduinoが例として挙げている「Fade」と「BlinkWithoutDelay」に示されているコンセプトに基づいています。
この2つのコンセプトを組み合わせることで、LEDの明るさをフェードアップ/ダウンさせるだけでなく、使用しているLEDを循環させ、同時にその色も循環させることができるようになりました。
「delay()」関数は、遅延時間が実行されている間は、コード内の他の処理を行うことができませんので、ご注意ください。

使用しているコードは、全体的なタスクを遂行するための最良の方法ではないかもしれませんが、私の言語知識の範囲内で、やりたかったことは実現しています。
以下のコードには、各部分が何をするのかを説明するためのコメントがあります。

// 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;
}
}
}
}

上記のコードをテストし、以下のArduinoと写真に示す回路にアップロードしました。

Arduino%20project

次は、プロジェクトの3Dプリンティングの部品です。

On-Shapeでプロジェクトを描いた後、様々なアイテムの寸法を確認する必要がありました。
そこで、まず外箱を3Dプリンティングしました。他のパーツは外箱に合わせてサイズを調整します。

外箱

IMG_20190327_104554778

インナーライナーの幅や長さを確認するために、ライナーの下側だけをプリンティングしました。
このパーツは幅がぴったりだったので、フルライナーを3Dプリンティングしました。

インナーライナーの底面テストピース

Test-bottom%20of%20inner%20liner

ライナーの幅と長さはきれいに収まりましたが、オブジェクトの角が不規則すぎて、結果的に外箱にうまく収まりませんでした。そこで、インナーライナーを修正しました。

インナーライナー1

Inner%20liner%201

下の写真のように、垂直方向の各コーナーに5mmの面取りを施しました。 これで、ライナーがぴったりとはまるようになりました。

インナーライナー2

Inner%20liner%202

その後、蓋を3Dプリンティングしました。これでプロジェクト全体がきれいにまとまりました。

Lid

下の写真は、arduinoと回路をインナーライナーに装着・配置したものです。

Arduino%20and%20circuit%20in%20inner%20liner

下の写真は、組み立てた状態のインナーライナーを外箱に入れたものです。

Inner%20liner%20assembled%20in%20outer%20box

内部の電源コードが組み立てられて設置されています。

image

完全に組み立てられた箱です!

Fully%20assembled%20box

以下は、On Shapeのサイトへのリンクで、このプロジェクトをご覧いただけます。
https://cad.onshape.com/documents/1f39e195a4a1a2563e7f484d/w/328efc4209ed20ef683577e5/e/7632c65e05b88f4e1808b82c

Lid.stl(78.0 KB)
LED box liner.stl (625.6 KB)
Outer box.stl (280.0 KB)

使用した材料
フィラメント:
    赤 0.112インチPLA (RM-PL0127
        外箱の場合(フィラメントが42m)、lulzbotで約21時間かかりました。

    白 0.112インチPLA (RM-PL0128
        インナーライナーの場合(フィラメントが45.5m)、lulzbotで約18時間かかりました。

    黒 0.112インチPLA (RM-PL0121
        蓋の部分(フィラメントが10.4m)は、lulzbotで約4時間かかりました。

パネルジャック:2.10mm × 5.50mm(54-00063)1個

プラグ:2.10mm × 5.50mm(10-02225)付きケーブル 1本

NPNトランジスタ:(2N3904BU)24個

ワイヤキット:各種サイズ 22AWG 350pcs(WK-1)1組
    特定の使用
        100mm 黄色ワイヤ 18本
        78mm オレンジ色ワイヤ 6本

赤色単線ワイヤ 2本

黒色単線ワイヤ 2本

RGB 4リード・スルーホールLED:(HV-5RGB25) 6個

Arduino Mega2560:(A000067)1個

ショートブレッドボード:3.20インチ長さ × 2.00インチ幅(FIT0096)1個

100Ωスルーホール抵抗 :6個 すでに持っていたもので、特に品番はありません。しかし、CFM12JT100Rは使えるはずです。

470Ωスルーホール抵抗:(SFR16S0004700JA500) 6個

ネジ:(1551ATS100) 6個

下図は、回路図です。

Glow-Box

プロジェクトをご覧いただきありがとうございます!気に入っていただけましたか?




オリジナル・ソース(英語)