4x4x4 Interactive LED-cube With Arduino
by kenyer in Circuits > Arduino
84787 Views, 164 Favorites, 0 Comments
4x4x4 Interactive LED-cube With Arduino
To explain my 4x4x4 interactive LED-cube published before, a bit more clear, I will try to make my first step by step instructable.
This 4x4x4 cube is interactive by using the top four corner LEDs both as LEDs and as sensors that will react on light. Depending on what LED gets the least light, the cube will run a different show.
This 4x4x4 cube is interactive by using the top four corner LEDs both as LEDs and as sensors that will react on light. Depending on what LED gets the least light, the cube will run a different show.
You Will Need:
TOOLS
soldering iron
pliers
small screwdriver
some drillbits
drill
solder
piece of wood
pencil
ruler
computer with Arduino software
USB-cable
snips
sharpie
breadboard (optional)
PARTS
64 led's
4 resistors that go with the LED's (yes just 4)
1 Photocube
1 Arduino
some wire
some small COAX wire (isolated wire)
16 headerpins
soldering iron
pliers
small screwdriver
some drillbits
drill
solder
piece of wood
pencil
ruler
computer with Arduino software
USB-cable
snips
sharpie
breadboard (optional)
PARTS
64 led's
4 resistors that go with the LED's (yes just 4)
1 Photocube
1 Arduino
some wire
some small COAX wire (isolated wire)
16 headerpins
Making the Rig
Draw on a piece of wood a grid with the lines 12,5 mm apart. (12 or 13 or whatever will also do, but I did 12,5) Draw at least 4 lines horizontally and 4 lines vertically. (I did more, because you'll never know what plans I will have in the future) You will now have 16 crossings. Drill some 5 mm holes (if your LEDs are 5 mm) at the crossings of the lines. If you first drill small holes, the location of your holes will probably be more exact.
This plank with 16 holes will be the rig for your soldering.
This plank with 16 holes will be the rig for your soldering.
Bending the Legs of the LEDs
First I bended the legs of 16 LED's. Hold the led upside-down diagonally, with the short leg in the upper left and the long leg in the lower right. Bend the cathode (short leg) to the left and the anode (long leg) down. So the flat part on the side of the LED wil be in the upper-left corner (the film and pictures will make this more clear I hope).
You can also bend 32 LEDs already if you are on a roll.
You can also bend 32 LEDs already if you are on a roll.
Placing the LEDs in the Rig
When at least 16 LEDs have bended legs (leads), you can place them in your rig. You will have 4 rows of long legs (anode) touching each other and 4 rows of short legs (cathode) touching. On some places, the anodes will also touch the cathodes when they cross each other. That is not a problem. We will solve that later.
Soldering the First Grid
Where the anode from one LED touches the anode from an other LED we will solder them together. Make sure that you don't solder an anode to an cathode.
At the places where the anodes are crossing the cathodes, we want to make sure that the legs aren'd touching. (they probably are touching now) We do this by forcing some room between the anodes and cathodes with the use of a small screwdriver. Be sure that you make enough room, but also be careful enough not to break anything.
At the places where the anodes are crossing the cathodes, we want to make sure that the legs aren'd touching. (they probably are touching now) We do this by forcing some room between the anodes and cathodes with the use of a small screwdriver. Be sure that you make enough room, but also be careful enough not to break anything.
Start Playing
Sure you can work on until you are all the way finished, but isn't it much more fun to first start playing with your just creates 4x4 LED-grid?!
So place your anodes in a breadboard an run some resistors from each of your cathode-rows to some free lanes in your breadboard. (they must be the value that you will need to light one LED from the 5V of your Arduino. This could be something like 560 ohm)
Next run 4 wires from the anodes in your breadboard to ports 4 till 7 on the Arduino and 4 wires from the resistors in your breadboard to ports 0 till 3 on the Arduino. To make this already interactive you will place a LED with the anode (long leg) in analog-port 0 and the cathode in GND of the Arduino.
Next you run the following code (sketch) on the Arduino and when you go with your hand over the LED in the analog-port of the Arduino, you will see the lights of your LED-grid light up.
If it worked: yeah, you just multiplexed 16 LEDs. This means that you lighted up 16 LEDs individually by just using 8 Arduino ports, just by gritting them. We made just 4 anodes and 4 cathodes and with these 8 wires we can address 16 locations on the grid.
int basis = 0;
int sens = 0;
int x = 0;
int y = 0;
int totaal = 0;
int totaal1 = 0;
int led0 = 0;
int led1 = 1;
int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int led7 = 7;
int tijd = 300;
void setup() {
pinMode(led0, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
}
void loop()
{
for(x =0; x < 50; x++)
{
sens = analogRead(0);
totaal = totaal1 + sens;
totaal1 = totaal;
}
sens = totaal/x;
totaal = 0;
totaal1 = 0;
basis = sens-20; // instellen van de gevoeligheid
for(y=0;y<1000;y++){
for(x =0; x < 50; x++)
{
sens = analogRead(0);
totaal = totaal1 + sens;
totaal1 = totaal;
delay(10);
}
sens = totaal/x;
if (sens<basis)
splash1();
totaal = 0;
totaal1 = 0;
delay(10);
}
}
void splash1(){
test();
a();
b();
c();
d();
e();
f();
g();
h();
i();
j();
k();
l();
m();
n();
o();
p();
uit();
}
void uit(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void a(){
digitalWrite(led0, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void b(){
digitalWrite(led0, HIGH);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void c(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void d(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void e(){
digitalWrite(led0, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void f(){
digitalWrite(led0, HIGH);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void g(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void h(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void i(){
digitalWrite(led0, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
digitalWrite(led7, LOW);
delay (tijd);
}
void j(){
digitalWrite(led0, HIGH);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
digitalWrite(led7, LOW);
delay (tijd);
}
void k(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
digitalWrite(led7, LOW);
delay (tijd);
}
void l(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
digitalWrite(led7, LOW);
delay (tijd);
}
void m(){
digitalWrite(led0, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, HIGH);
delay (tijd);
}
void n(){
digitalWrite(led0, HIGH);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, HIGH);
delay (tijd);
}
void o(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, HIGH);
delay (tijd);
}
void p(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, HIGH);
delay (tijd);
}
void test(){
digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
delay (1000);
}
So place your anodes in a breadboard an run some resistors from each of your cathode-rows to some free lanes in your breadboard. (they must be the value that you will need to light one LED from the 5V of your Arduino. This could be something like 560 ohm)
Next run 4 wires from the anodes in your breadboard to ports 4 till 7 on the Arduino and 4 wires from the resistors in your breadboard to ports 0 till 3 on the Arduino. To make this already interactive you will place a LED with the anode (long leg) in analog-port 0 and the cathode in GND of the Arduino.
Next you run the following code (sketch) on the Arduino and when you go with your hand over the LED in the analog-port of the Arduino, you will see the lights of your LED-grid light up.
If it worked: yeah, you just multiplexed 16 LEDs. This means that you lighted up 16 LEDs individually by just using 8 Arduino ports, just by gritting them. We made just 4 anodes and 4 cathodes and with these 8 wires we can address 16 locations on the grid.
int basis = 0;
int sens = 0;
int x = 0;
int y = 0;
int totaal = 0;
int totaal1 = 0;
int led0 = 0;
int led1 = 1;
int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int led7 = 7;
int tijd = 300;
void setup() {
pinMode(led0, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
}
void loop()
{
for(x =0; x < 50; x++)
{
sens = analogRead(0);
totaal = totaal1 + sens;
totaal1 = totaal;
}
sens = totaal/x;
totaal = 0;
totaal1 = 0;
basis = sens-20; // instellen van de gevoeligheid
for(y=0;y<1000;y++){
for(x =0; x < 50; x++)
{
sens = analogRead(0);
totaal = totaal1 + sens;
totaal1 = totaal;
delay(10);
}
sens = totaal/x;
if (sens<basis)
splash1();
totaal = 0;
totaal1 = 0;
delay(10);
}
}
void splash1(){
test();
a();
b();
c();
d();
e();
f();
g();
h();
i();
j();
k();
l();
m();
n();
o();
p();
uit();
}
void uit(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void a(){
digitalWrite(led0, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void b(){
digitalWrite(led0, HIGH);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void c(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void d(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void e(){
digitalWrite(led0, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void f(){
digitalWrite(led0, HIGH);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void g(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void h(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd);
}
void i(){
digitalWrite(led0, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
digitalWrite(led7, LOW);
delay (tijd);
}
void j(){
digitalWrite(led0, HIGH);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
digitalWrite(led7, LOW);
delay (tijd);
}
void k(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
digitalWrite(led7, LOW);
delay (tijd);
}
void l(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
digitalWrite(led7, LOW);
delay (tijd);
}
void m(){
digitalWrite(led0, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, HIGH);
delay (tijd);
}
void n(){
digitalWrite(led0, HIGH);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, HIGH);
delay (tijd);
}
void o(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, HIGH);
delay (tijd);
}
void p(){
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, HIGH);
delay (tijd);
}
void test(){
digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
delay (1000);
}
Downloads
The Next Layer
The leg bending
The next layer is the same as the first but not exactly! You will have to bend the legs of the LEDs the other way around. This means that you need to hold the LEDs with the flat side in the under-righthand corner. The anode will now be on the upper-lefthand corner and has to be bend to the left. The cathode in the under-righthand corner will have to be bended down.
Next follows the soldering.
First we solder the grid like we did with the first one.
Now you bend the anodes (long leads) of the first grid upwards and the cathodes of the first grid downwards. The anodes and the cathodes of the second grid will be bended downwards. Solder the four anodes from the first grid to the four cathodes of the second grid. The anodes of the second grid must just reach the bends in the cathodes of the first grid and have to be soldered there.
Charlyplexing
By connecting the anodes to the cathodes we are charlyplexing. By using charlyplexing, we can connect and control 16 more LEDs with the same 8 ports on the Arduino.
LEDs are diodes (the D from LED stands for Diode), this means that current can only go through it in one direction, what means that if you connect the anode of one LED to the cathode of an other LED and the cathode of that first LED to the anode of the second, only one LED will light up when you put current trough it, but the other one will light up when you put the current the other way around through it. This is exactly what we are going to use here. (I hope my sketches make it a little bit more clear)
The next layer is the same as the first but not exactly! You will have to bend the legs of the LEDs the other way around. This means that you need to hold the LEDs with the flat side in the under-righthand corner. The anode will now be on the upper-lefthand corner and has to be bend to the left. The cathode in the under-righthand corner will have to be bended down.
Next follows the soldering.
First we solder the grid like we did with the first one.
Now you bend the anodes (long leads) of the first grid upwards and the cathodes of the first grid downwards. The anodes and the cathodes of the second grid will be bended downwards. Solder the four anodes from the first grid to the four cathodes of the second grid. The anodes of the second grid must just reach the bends in the cathodes of the first grid and have to be soldered there.
Charlyplexing
By connecting the anodes to the cathodes we are charlyplexing. By using charlyplexing, we can connect and control 16 more LEDs with the same 8 ports on the Arduino.
LEDs are diodes (the D from LED stands for Diode), this means that current can only go through it in one direction, what means that if you connect the anode of one LED to the cathode of an other LED and the cathode of that first LED to the anode of the second, only one LED will light up when you put current trough it, but the other one will light up when you put the current the other way around through it. This is exactly what we are going to use here. (I hope my sketches make it a little bit more clear)
Lets Play Again!
We are only halfway, but I think it is time to play again! So put the downwards facing leads in a breadboard and connect some resistors between the upwards facing leads and the breadboard. Connect them with the Arduino like before and run the following sketch. The extra LED is probably still in the analog port of the Arduino (if not, put it back in)
int basis = 0;
int sens = 0;
int x = 0;
int y = 0;
int totaal = 0;
int totaal1 = 0;
int led0 = 0;
int led1 = 1;
int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int led7 = 7;
int tijd = 100;
void setup() {
pinMode(led0, INPUT);
pinMode(led1, INPUT);
pinMode(led2, INPUT);
pinMode(led3, INPUT);
pinMode(led4, INPUT);
pinMode(led5, INPUT);
pinMode(led6, INPUT);
pinMode(led7, INPUT);
}
void loop()
{
for(x =0; x < 50; x++)
{
sens = analogRead(0);
totaal = totaal1 + sens;
totaal1 = totaal;
}
sens = totaal/x;
totaal = 0;
totaal1 = 0;
basis = sens-20; // instellen van de gevoeligheid
for(y=0;y<1000;y++){
for(x =0; x < 50; x++)
{
sens = analogRead(0);
totaal = totaal1 + sens;
totaal1 = totaal;
delay(10);
}
sens = totaal/x;
if (sens<basis)
splash1();
totaal = 0;
totaal1 = 0;
delay(10);
}
}
void splash1(){
test();
a1(); b1(); c1(); d1(); e1(); f1(); g1(); h1(); i1(); j1(); k1(); l1(); m1(); n1(); o1(); p1();
p2(); o2(); n2(); m2(); l2(); k2(); j2(); i2(); h2(); g2(); f2(); e2(); d2(); c2(); b2(); a2();
uit();
delay (tijd);
}
void uit(){
pinMode(led0, INPUT);
pinMode(led1, INPUT);
pinMode(led2, INPUT);
pinMode(led3, INPUT);
pinMode(led4, INPUT);
pinMode(led5, INPUT);
pinMode(led6, INPUT);
pinMode(led7, INPUT);
}
void a1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void b1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void c1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void d1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void e1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void f1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void g1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void h1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void i1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void j1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void k1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void l1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void m1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void n1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void o1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void p1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void a2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void b2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void c2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void d2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void e2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void f2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void g2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void h2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void i2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void j2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void k2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void l2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void m2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void n2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void o2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void p2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void test(){
pinMode(led0, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
delay (1000);
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (1000);
uit();
}
int basis = 0;
int sens = 0;
int x = 0;
int y = 0;
int totaal = 0;
int totaal1 = 0;
int led0 = 0;
int led1 = 1;
int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int led7 = 7;
int tijd = 100;
void setup() {
pinMode(led0, INPUT);
pinMode(led1, INPUT);
pinMode(led2, INPUT);
pinMode(led3, INPUT);
pinMode(led4, INPUT);
pinMode(led5, INPUT);
pinMode(led6, INPUT);
pinMode(led7, INPUT);
}
void loop()
{
for(x =0; x < 50; x++)
{
sens = analogRead(0);
totaal = totaal1 + sens;
totaal1 = totaal;
}
sens = totaal/x;
totaal = 0;
totaal1 = 0;
basis = sens-20; // instellen van de gevoeligheid
for(y=0;y<1000;y++){
for(x =0; x < 50; x++)
{
sens = analogRead(0);
totaal = totaal1 + sens;
totaal1 = totaal;
delay(10);
}
sens = totaal/x;
if (sens<basis)
splash1();
totaal = 0;
totaal1 = 0;
delay(10);
}
}
void splash1(){
test();
a1(); b1(); c1(); d1(); e1(); f1(); g1(); h1(); i1(); j1(); k1(); l1(); m1(); n1(); o1(); p1();
p2(); o2(); n2(); m2(); l2(); k2(); j2(); i2(); h2(); g2(); f2(); e2(); d2(); c2(); b2(); a2();
uit();
delay (tijd);
}
void uit(){
pinMode(led0, INPUT);
pinMode(led1, INPUT);
pinMode(led2, INPUT);
pinMode(led3, INPUT);
pinMode(led4, INPUT);
pinMode(led5, INPUT);
pinMode(led6, INPUT);
pinMode(led7, INPUT);
}
void a1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void b1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void c1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void d1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void e1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void f1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void g1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void h1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void i1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void j1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void k1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void l1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void m1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void n1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void o1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void p1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void a2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void b2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void c2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void d2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void e2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void f2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void g2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void h2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void i2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void j2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void k2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void l2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void m2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void n2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void o2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void p2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void test(){
pinMode(led0, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
delay (1000);
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (1000);
uit();
}
Downloads
More Leds
Third layer
The Third layer will be exactly the same as the second layer, only the inner two cathodes (short leads) need to be bended upwards. The anodes will be soldered to the bends of the cathodes of the second layer. You might want to ad a peace of blank wire to support this connection. This means that the third layer will be turned 90 degrees counterclockwise from the second layer. The two outer cathodes need to be clear of the second layer.
The final layer
The fourth grid is a little bit different. It is mostly the same as the first grid, only you leave out the four corner LEDs. So you solder the grid exactly the same way together as the first layer, leaving out the four corner LEDs.
All the leads will be bended down and soldered to the third layer. The two anodes called F and G on my drawing will be soldered to the upwards bended cathode-leads on the third layer. This means that the fourth layer is 90 degrees turned counterclockwise from the bottom layer. Where the rest of the leads go will speak for themselves now; The leads will be soldered where they touch the third layer. This means that the cathodes from the fourth layer will be soldered to the anodes of the third layer and the anodes of the fourth layer to the cathodes of the third layer.
Extra wires
Solder four wires on the four cathodes from the third layer (two of them still hanging lose somewhere). These wires have to run down but not touch the first and second layer.
Fritzing file
I added a Fritzing file to give you a high-res schematic. Just watch the schematic-view in Fritzing. The other views are rubbish. (Fritzing is open source software to design schematics and PCBs from your breadboard-experiments. See www.fritzing.org)
The Third layer will be exactly the same as the second layer, only the inner two cathodes (short leads) need to be bended upwards. The anodes will be soldered to the bends of the cathodes of the second layer. You might want to ad a peace of blank wire to support this connection. This means that the third layer will be turned 90 degrees counterclockwise from the second layer. The two outer cathodes need to be clear of the second layer.
The final layer
The fourth grid is a little bit different. It is mostly the same as the first grid, only you leave out the four corner LEDs. So you solder the grid exactly the same way together as the first layer, leaving out the four corner LEDs.
All the leads will be bended down and soldered to the third layer. The two anodes called F and G on my drawing will be soldered to the upwards bended cathode-leads on the third layer. This means that the fourth layer is 90 degrees turned counterclockwise from the bottom layer. Where the rest of the leads go will speak for themselves now; The leads will be soldered where they touch the third layer. This means that the cathodes from the fourth layer will be soldered to the anodes of the third layer and the anodes of the fourth layer to the cathodes of the third layer.
Extra wires
Solder four wires on the four cathodes from the third layer (two of them still hanging lose somewhere). These wires have to run down but not touch the first and second layer.
Fritzing file
I added a Fritzing file to give you a high-res schematic. Just watch the schematic-view in Fritzing. The other views are rubbish. (Fritzing is open source software to design schematics and PCBs from your breadboard-experiments. See www.fritzing.org)
Downloads
The Housing
To house your LED-cube you can be as creative as you like. I found an old-fashioned photo-cube. With a sharpie I mark where the wires need to go trough the bottom of the photo-cube. Four holes for the four wires coming from the upper two layers. Four holes for the four anodes coming from the first layer. Four holes under the four cathodes going up from the first layer to the second layer.
After I drilled the holes, I can stick the eight wires trough them.
Wiring the cube
From the anodes coming from the first layer I run wires to four headers that will go to port 8-9-10-11 of the Arduino. From the wires coming from the top two layers, wires will go to headers for port 4-5-6-7.
Trough the four remaining holes I stick the four resistors that will be soldered to the cathodes from the first layer. (Be careful not to melt the plastic with your soldering iron, like I did) These resistors will go to four headers entering ports 0-1-2-3 on the Arduino.
After I drilled the holes, I can stick the eight wires trough them.
Wiring the cube
From the anodes coming from the first layer I run wires to four headers that will go to port 8-9-10-11 of the Arduino. From the wires coming from the top two layers, wires will go to headers for port 4-5-6-7.
Trough the four remaining holes I stick the four resistors that will be soldered to the cathodes from the first layer. (Be careful not to melt the plastic with your soldering iron, like I did) These resistors will go to four headers entering ports 0-1-2-3 on the Arduino.
The Sensor-LEDs
Preparing the wire
I didn't like the looks of the black COAX cables. (this is slim COAX, not the thick one you use for your TV) The cable was to thick and to black, so I stripped off the outer plastic layer. I took four peaces and stripped the last 5 mm till the inner wire.
The leads on the four remaining LED's will be bended to one side so that they are not touching each other. 5 mm from the LED they are bended down again.
The anode is welded to the inner wire of the COAX and snipped of short enough that it doesn't touch the outer cable of the COAX. The cathode is soldered to the outer cable of the COAX.
Drilling the holes
Somewhere in the outer four squares of the grid, four holes are drilled that are just big enough for the COAX to go trough. (see the pictures)
Installing the sensor-LEDs
From the top down you can put the COAX-wires with the LEDs on them trough the holes. After you fiddled them in the correct location you connect the top of the four outer COAX-cables with pieces of wire all around. (see picture) This wires will support the sensor-LEDs and it will also connect the cathodes of the four LEDs.
The inner wires of the four COAX-wires will go to four headers going to analog-port 0-1-2-3 of the Arduino and one of the outer cables of the COAX-wires goes to the GND of the Arduino. (All the cathodes are already connected, so we have to take only one ground here)
Be sure that the COAX is not touching some of the other wires, ore use isolation-tape or hot glue or something to prevent this from happening.
I didn't like the looks of the black COAX cables. (this is slim COAX, not the thick one you use for your TV) The cable was to thick and to black, so I stripped off the outer plastic layer. I took four peaces and stripped the last 5 mm till the inner wire.
The leads on the four remaining LED's will be bended to one side so that they are not touching each other. 5 mm from the LED they are bended down again.
The anode is welded to the inner wire of the COAX and snipped of short enough that it doesn't touch the outer cable of the COAX. The cathode is soldered to the outer cable of the COAX.
Drilling the holes
Somewhere in the outer four squares of the grid, four holes are drilled that are just big enough for the COAX to go trough. (see the pictures)
Installing the sensor-LEDs
From the top down you can put the COAX-wires with the LEDs on them trough the holes. After you fiddled them in the correct location you connect the top of the four outer COAX-cables with pieces of wire all around. (see picture) This wires will support the sensor-LEDs and it will also connect the cathodes of the four LEDs.
The inner wires of the four COAX-wires will go to four headers going to analog-port 0-1-2-3 of the Arduino and one of the outer cables of the COAX-wires goes to the GND of the Arduino. (All the cathodes are already connected, so we have to take only one ground here)
Be sure that the COAX is not touching some of the other wires, ore use isolation-tape or hot glue or something to prevent this from happening.
Finishing Up
Finally we are going to finish this cube! We can close the photo cube. One last check to make sure that no wires are touching that are not supposed to touch and than put the headers in the ports of the Arduino!
Upload the following sketch (code) and start experimenting with it.
I hope you will make manny changes and improvements on it and invite you to post them in the comments.
int tijd = 50; // set the speed
int tijdx = 0;
int basis1 = 0;
int basis2 = 0;
int basis3 = 0;
int basis4 = 0;
int sens1 = 0;
int sens2 = 0;
int sens3 = 0;
int sens4 = 0;
int x = 0;
int y = 0;
int totaal1 = 0;
int totaal2 = 0;
int totaal3 = 0;
int totaal4 = 0;
int map1 = 0;
int map2 = 0;
int map3 = 0;
int map4 = 0;
int led0 = 8;
int led1 = 9;
int led2 = 10;
int led3 = 11;
int led4 = 0; // nul
int led5 = 1; // nul
int led6 = 2; // nul
int led7 = 3; // nul
int led8 = 4;
int led9 = 5;
int led10 = 6;
int led11 = 7;
void setup()
{
pinMode(led0, INPUT);
pinMode(led1, INPUT);
pinMode(led2, INPUT);
pinMode(led3, INPUT);
pinMode(led4, INPUT);
pinMode(led5, INPUT);
pinMode(led6, INPUT);
pinMode(led7, INPUT);
pinMode(led8, INPUT);
pinMode(led9, INPUT);
pinMode(led10, INPUT);
pinMode(led11, INPUT);
// Serial.begin(9600);
}
void loop()
{
for(x =0; x < 50; x++)
{
sens1 = analogRead(0);
totaal1 = totaal1 + sens1;
sens2 = analogRead(1);
totaal2 = totaal2 + sens2;
sens3 = analogRead(2);
totaal3 = totaal3 + sens3;
sens4 = analogRead(3);
totaal4 = totaal4 + sens4;
}
sens1 = totaal1/x;
totaal1 = 0;
basis1 = sens1-20; // instellen van de gevoeligheid
sens2 = totaal2/x;
totaal2 = 0;
basis2 = sens2-20;
sens3 = totaal3/x;
totaal3 = 0;
basis3 = sens3-20;
sens4 = totaal4/x;
totaal4 = 0;
basis4 = sens4-20;
for(y=0;y<2000;y++){
for(x =0; x < 30; x++)
{
sens1 = analogRead(0);
sens2 = analogRead(1);
sens3 = analogRead(2);
sens4 = analogRead(3);
totaal1 = totaal1 + sens1;
totaal2 = totaal2 + sens2;
totaal3 = totaal3 + sens3;
totaal4 = totaal4 + sens4;
// delay(10);
}
sens1 = totaal1/x;
sens2 = totaal2/x;
sens3 = totaal3/x;
sens4 = totaal4/x;
if (sens1<basis1){
if (sens1 < ((sens2 + sens3 + sens4)/3))
splash1();
}
if (sens2<basis2){
if (sens2 < ((sens1 + sens3 + sens4)/3))
splash2();
}
if (sens3<basis3){
if (sens3 < ((sens1 + sens2 + sens4)/3))
splash3();
}
if (sens4<basis4){
if (sens4 < ((sens1 + sens3 + sens2)/3))
splash4();
}
totaal1 = 0;
totaal2 = 0;
totaal3 = 0;
totaal4 = 0;
delay(5);
/*
Serial.print(sens1, DEC); Serial.print(" - "); Serial.print(basis1, DEC);
Serial.println();
Serial.print(sens2, DEC); Serial.print(" - "); Serial.print(basis2, DEC);
Serial.println();
Serial.print(sens3, DEC); Serial.print(" - "); Serial.print(basis3, DEC);
Serial.println();
Serial.print(sens4, DEC); Serial.print(" - "); Serial.print(basis4, DEC);
Serial.println(); Serial.println();
*/
}
}
void splash1()
{
a4(); b4(); c4(); d4(); h4(); l4(); p4(); o4(); n4(); m4(); i4(); e4(); f4(); g4(); k4(); j4();
j3(); f3(); g3(); k3(); o3(); n3(); m3(); i3(); e3(); a3(); b3(); c3(); d3(); h3(); l3(); p3();
p2(); o2(); n2(); m2(); i2(); e2(); a2(); b2(); c2(); d2(); h2(); l2(); k2(); j2(); f2(); g2();
g1(); k1(); j1(); f1(); b1(); c1(); d1(); h1(); l1(); p1(); o1(); n1(); m1(); i1(); e1(); a1();
}
void splash2()
{
p4(); o4(); n4(); m4(); l4(); k4(); j4(); i4(); h4(); g4(); f4(); e4(); d4(); c4(); b4(); a4();
a3(); b3(); c3(); d3(); e3(); f3(); g3(); h3(); i3(); j3(); k3(); l3(); m3(); n3(); o3(); p3();
p2(); o2(); n2(); m2(); l2(); k2(); j2(); i2(); h2(); g2(); f2(); e2(); d2(); c2(); b2(); a2();
a1(); b1(); c1(); d1(); e1(); f1(); g1(); h1(); i1(); j1(); k1(); l1(); m1(); n1(); o1(); p1();
uit();
}
void splash3()
{
tijdx = tijd;
tijd = 0;
for (y = 0; y < 5 ; y++)
{
for (x = 0; x < tijdx/4 ; x++)
{
a1(); a2(); a3(); a4(); f1(); f2(); f3(); f4();
}
for (x = 0; x < tijdx/4 ; x++)
{
b1(); b2(); b3(); b4(); f1(); f2(); f3(); f4();
}
for (x = 0; x < tijdx/4 ; x++)
{
c1(); c2(); c3(); c4(); g1(); g2(); g3(); g4();
}
for (x = 0; x < tijdx/4 ; x++)
{
d1(); d2(); d3(); d4(); g1(); g2(); g3(); g4();
}
for (x = 0; x < tijdx/4 ; x++)
{
h1(); h2(); h3(); h4(); g1(); g2(); g3(); g4();
}
for (x = 0; x < tijdx/4 ; x++)
{
l1(); l2(); l3(); l4(); k1(); k2(); k3(); k4();
}
for (x = 0; x < tijdx/4 ; x++)
{
p1(); p2(); p3(); p4(); k1(); k2(); k3(); k4();
}
for (x = 0; x < tijdx/4 ; x++)
{
o1(); o2(); o3(); o4(); k1(); k2(); k3(); k4();
}
for (x = 0; x < tijdx/4 ; x++)
{
n1(); n2(); n3(); n4(); j1(); j2(); j3(); j4();
}
for (x = 0; x < tijdx/4 ; x++)
{
m1(); m2(); m3(); m4(); j1(); j2(); j3(); j4();
}
for (x = 0; x < tijdx/4 ; x++)
{
i1(); i2(); i3(); i4(); j1(); j2(); j3(); j4();
}
for (x = 0; x < tijdx/4 ; x++)
{
e1(); e2(); e3(); e4(); f1(); f2(); f3(); f4();
}
}
tijd = tijdx;
}
void splash4()
{
test();
}
void uit(){
pinMode(led0, INPUT);
pinMode(led1, INPUT);
pinMode(led2, INPUT);
pinMode(led3, INPUT);
pinMode(led4, INPUT);
pinMode(led5, INPUT);
pinMode(led6, INPUT);
pinMode(led7, INPUT);
pinMode(led8, INPUT);
pinMode(led9, INPUT);
pinMode(led10, INPUT);
pinMode(led11, INPUT);
pinMode(14, INPUT);
digitalWrite(14, LOW);
pinMode(15, INPUT);
digitalWrite(15, LOW);
pinMode(16, INPUT);
digitalWrite(16, LOW);
pinMode(17, INPUT);
digitalWrite(17, LOW);
}
void a1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void b1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void c1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void d1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void e1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void f1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void g1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void h1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void i1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void j1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void k1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void l1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void m1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void n1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void o1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void p1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void a2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void b2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void c2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void d2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void e2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void f2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void g2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void h2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void i2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void j2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void k2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void l2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void m2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void n2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void o2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void p2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void a3(){
pinMode(led8, OUTPUT);
digitalWrite(led8, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void b3(){
pinMode(led9, OUTPUT);
digitalWrite(led9, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void c3(){
pinMode(led10, OUTPUT);
digitalWrite(led10, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void d3(){
pinMode(led11, OUTPUT);
digitalWrite(led11, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void e3(){
pinMode(led8, OUTPUT);
digitalWrite(led8, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void f3(){
pinMode(led9, OUTPUT);
digitalWrite(led9, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void g3(){
pinMode(led10, OUTPUT);
digitalWrite(led10, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void h3(){
pinMode(led11, OUTPUT);
digitalWrite(led11, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void i3(){
pinMode(led8, OUTPUT);
digitalWrite(led8, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void j3(){
pinMode(led9, OUTPUT);
digitalWrite(led9, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void k3(){
pinMode(led10, OUTPUT);
digitalWrite(led10, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void l3(){
pinMode(led11, OUTPUT);
digitalWrite(led11, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void m3(){
pinMode(led8, OUTPUT);
digitalWrite(led8, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void n3(){
pinMode(led9, OUTPUT);
digitalWrite(led9, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void o3(){
pinMode(led10, OUTPUT);
digitalWrite(led10, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void p3(){
pinMode(led11, OUTPUT);
digitalWrite(led11, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
uit();
}
void a4(){
digitalWrite(14, HIGH);
pinMode(14, OUTPUT);
digitalWrite(14, HIGH);
delay (tijd);
uit();
}
void b4(){
pinMode(led9, OUTPUT);
digitalWrite(led9, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void c4(){
pinMode(led10, OUTPUT);
digitalWrite(led10, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void d4(){
digitalWrite(15, HIGH);
pinMode(15, OUTPUT);
digitalWrite(15, HIGH);
delay (tijd);
uit();
}
void e4(){
pinMode(led8, OUTPUT);
digitalWrite(led8, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void f4(){
pinMode(led9, OUTPUT);
digitalWrite(led9, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void g4(){
pinMode(led10, OUTPUT);
digitalWrite(led10, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void h4(){
pinMode(led11, OUTPUT);
digitalWrite(led11, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void i4(){
pinMode(led8, OUTPUT);
digitalWrite(led8, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void j4(){
pinMode(led9, OUTPUT);
digitalWrite(led9, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void k4(){
pinMode(led10, OUTPUT);
digitalWrite(led10, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void l4(){
pinMode(led11, OUTPUT);
digitalWrite(led11, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void m4(){
digitalWrite(17, HIGH);
pinMode(17, OUTPUT);
digitalWrite(17, HIGH);
delay (tijd);
uit();
}
void n4(){
pinMode(led9, OUTPUT);
digitalWrite(led9, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void o4(){
pinMode(led10, OUTPUT);
digitalWrite(led10, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void p4(){
digitalWrite(16, HIGH);
pinMode(16, OUTPUT);
digitalWrite(16, HIGH);
delay (tijd);
uit();
}
void test(){
pinMode(led0, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, INPUT);
pinMode(led9, INPUT);
pinMode(led10, INPUT);
pinMode(led11, INPUT);
digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
delay (tijd*4);
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd*4);
pinMode(led0, INPUT);
pinMode(led1, INPUT);
pinMode(led2, INPUT);
pinMode(led3, INPUT);
pinMode(led8, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led10, OUTPUT);
pinMode(led11, OUTPUT);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
delay (tijd*4);
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10, HIGH);
digitalWrite(led11, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd*4);
uit();
}
Upload the following sketch (code) and start experimenting with it.
I hope you will make manny changes and improvements on it and invite you to post them in the comments.
int tijd = 50; // set the speed
int tijdx = 0;
int basis1 = 0;
int basis2 = 0;
int basis3 = 0;
int basis4 = 0;
int sens1 = 0;
int sens2 = 0;
int sens3 = 0;
int sens4 = 0;
int x = 0;
int y = 0;
int totaal1 = 0;
int totaal2 = 0;
int totaal3 = 0;
int totaal4 = 0;
int map1 = 0;
int map2 = 0;
int map3 = 0;
int map4 = 0;
int led0 = 8;
int led1 = 9;
int led2 = 10;
int led3 = 11;
int led4 = 0; // nul
int led5 = 1; // nul
int led6 = 2; // nul
int led7 = 3; // nul
int led8 = 4;
int led9 = 5;
int led10 = 6;
int led11 = 7;
void setup()
{
pinMode(led0, INPUT);
pinMode(led1, INPUT);
pinMode(led2, INPUT);
pinMode(led3, INPUT);
pinMode(led4, INPUT);
pinMode(led5, INPUT);
pinMode(led6, INPUT);
pinMode(led7, INPUT);
pinMode(led8, INPUT);
pinMode(led9, INPUT);
pinMode(led10, INPUT);
pinMode(led11, INPUT);
// Serial.begin(9600);
}
void loop()
{
for(x =0; x < 50; x++)
{
sens1 = analogRead(0);
totaal1 = totaal1 + sens1;
sens2 = analogRead(1);
totaal2 = totaal2 + sens2;
sens3 = analogRead(2);
totaal3 = totaal3 + sens3;
sens4 = analogRead(3);
totaal4 = totaal4 + sens4;
}
sens1 = totaal1/x;
totaal1 = 0;
basis1 = sens1-20; // instellen van de gevoeligheid
sens2 = totaal2/x;
totaal2 = 0;
basis2 = sens2-20;
sens3 = totaal3/x;
totaal3 = 0;
basis3 = sens3-20;
sens4 = totaal4/x;
totaal4 = 0;
basis4 = sens4-20;
for(y=0;y<2000;y++){
for(x =0; x < 30; x++)
{
sens1 = analogRead(0);
sens2 = analogRead(1);
sens3 = analogRead(2);
sens4 = analogRead(3);
totaal1 = totaal1 + sens1;
totaal2 = totaal2 + sens2;
totaal3 = totaal3 + sens3;
totaal4 = totaal4 + sens4;
// delay(10);
}
sens1 = totaal1/x;
sens2 = totaal2/x;
sens3 = totaal3/x;
sens4 = totaal4/x;
if (sens1<basis1){
if (sens1 < ((sens2 + sens3 + sens4)/3))
splash1();
}
if (sens2<basis2){
if (sens2 < ((sens1 + sens3 + sens4)/3))
splash2();
}
if (sens3<basis3){
if (sens3 < ((sens1 + sens2 + sens4)/3))
splash3();
}
if (sens4<basis4){
if (sens4 < ((sens1 + sens3 + sens2)/3))
splash4();
}
totaal1 = 0;
totaal2 = 0;
totaal3 = 0;
totaal4 = 0;
delay(5);
/*
Serial.print(sens1, DEC); Serial.print(" - "); Serial.print(basis1, DEC);
Serial.println();
Serial.print(sens2, DEC); Serial.print(" - "); Serial.print(basis2, DEC);
Serial.println();
Serial.print(sens3, DEC); Serial.print(" - "); Serial.print(basis3, DEC);
Serial.println();
Serial.print(sens4, DEC); Serial.print(" - "); Serial.print(basis4, DEC);
Serial.println(); Serial.println();
*/
}
}
void splash1()
{
a4(); b4(); c4(); d4(); h4(); l4(); p4(); o4(); n4(); m4(); i4(); e4(); f4(); g4(); k4(); j4();
j3(); f3(); g3(); k3(); o3(); n3(); m3(); i3(); e3(); a3(); b3(); c3(); d3(); h3(); l3(); p3();
p2(); o2(); n2(); m2(); i2(); e2(); a2(); b2(); c2(); d2(); h2(); l2(); k2(); j2(); f2(); g2();
g1(); k1(); j1(); f1(); b1(); c1(); d1(); h1(); l1(); p1(); o1(); n1(); m1(); i1(); e1(); a1();
}
void splash2()
{
p4(); o4(); n4(); m4(); l4(); k4(); j4(); i4(); h4(); g4(); f4(); e4(); d4(); c4(); b4(); a4();
a3(); b3(); c3(); d3(); e3(); f3(); g3(); h3(); i3(); j3(); k3(); l3(); m3(); n3(); o3(); p3();
p2(); o2(); n2(); m2(); l2(); k2(); j2(); i2(); h2(); g2(); f2(); e2(); d2(); c2(); b2(); a2();
a1(); b1(); c1(); d1(); e1(); f1(); g1(); h1(); i1(); j1(); k1(); l1(); m1(); n1(); o1(); p1();
uit();
}
void splash3()
{
tijdx = tijd;
tijd = 0;
for (y = 0; y < 5 ; y++)
{
for (x = 0; x < tijdx/4 ; x++)
{
a1(); a2(); a3(); a4(); f1(); f2(); f3(); f4();
}
for (x = 0; x < tijdx/4 ; x++)
{
b1(); b2(); b3(); b4(); f1(); f2(); f3(); f4();
}
for (x = 0; x < tijdx/4 ; x++)
{
c1(); c2(); c3(); c4(); g1(); g2(); g3(); g4();
}
for (x = 0; x < tijdx/4 ; x++)
{
d1(); d2(); d3(); d4(); g1(); g2(); g3(); g4();
}
for (x = 0; x < tijdx/4 ; x++)
{
h1(); h2(); h3(); h4(); g1(); g2(); g3(); g4();
}
for (x = 0; x < tijdx/4 ; x++)
{
l1(); l2(); l3(); l4(); k1(); k2(); k3(); k4();
}
for (x = 0; x < tijdx/4 ; x++)
{
p1(); p2(); p3(); p4(); k1(); k2(); k3(); k4();
}
for (x = 0; x < tijdx/4 ; x++)
{
o1(); o2(); o3(); o4(); k1(); k2(); k3(); k4();
}
for (x = 0; x < tijdx/4 ; x++)
{
n1(); n2(); n3(); n4(); j1(); j2(); j3(); j4();
}
for (x = 0; x < tijdx/4 ; x++)
{
m1(); m2(); m3(); m4(); j1(); j2(); j3(); j4();
}
for (x = 0; x < tijdx/4 ; x++)
{
i1(); i2(); i3(); i4(); j1(); j2(); j3(); j4();
}
for (x = 0; x < tijdx/4 ; x++)
{
e1(); e2(); e3(); e4(); f1(); f2(); f3(); f4();
}
}
tijd = tijdx;
}
void splash4()
{
test();
}
void uit(){
pinMode(led0, INPUT);
pinMode(led1, INPUT);
pinMode(led2, INPUT);
pinMode(led3, INPUT);
pinMode(led4, INPUT);
pinMode(led5, INPUT);
pinMode(led6, INPUT);
pinMode(led7, INPUT);
pinMode(led8, INPUT);
pinMode(led9, INPUT);
pinMode(led10, INPUT);
pinMode(led11, INPUT);
pinMode(14, INPUT);
digitalWrite(14, LOW);
pinMode(15, INPUT);
digitalWrite(15, LOW);
pinMode(16, INPUT);
digitalWrite(16, LOW);
pinMode(17, INPUT);
digitalWrite(17, LOW);
}
void a1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void b1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void c1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void d1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void e1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void f1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void g1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void h1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void i1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void j1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void k1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void l1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void m1(){
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void n1(){
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void o1(){
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void p1(){
pinMode(led3, OUTPUT);
digitalWrite(led3, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void a2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void b2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void c2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void d2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void e2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void f2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void g2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void h2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void i2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void j2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void k2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void l2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void m2(){
pinMode(led0, OUTPUT);
digitalWrite(led0, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void n2(){
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void o2(){
pinMode(led2, OUTPUT);
digitalWrite(led2, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void p2(){
pinMode(led3, OUTPUT);
digitalWrite(led3, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void a3(){
pinMode(led8, OUTPUT);
digitalWrite(led8, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void b3(){
pinMode(led9, OUTPUT);
digitalWrite(led9, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void c3(){
pinMode(led10, OUTPUT);
digitalWrite(led10, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void d3(){
pinMode(led11, OUTPUT);
digitalWrite(led11, LOW);
pinMode(led4, OUTPUT);
digitalWrite(led4, HIGH);
delay (tijd);
uit();
}
void e3(){
pinMode(led8, OUTPUT);
digitalWrite(led8, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void f3(){
pinMode(led9, OUTPUT);
digitalWrite(led9, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void g3(){
pinMode(led10, OUTPUT);
digitalWrite(led10, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void h3(){
pinMode(led11, OUTPUT);
digitalWrite(led11, LOW);
pinMode(led5, OUTPUT);
digitalWrite(led5, HIGH);
delay (tijd);
uit();
}
void i3(){
pinMode(led8, OUTPUT);
digitalWrite(led8, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void j3(){
pinMode(led9, OUTPUT);
digitalWrite(led9, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void k3(){
pinMode(led10, OUTPUT);
digitalWrite(led10, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void l3(){
pinMode(led11, OUTPUT);
digitalWrite(led11, LOW);
pinMode(led6, OUTPUT);
digitalWrite(led6, HIGH);
delay (tijd);
uit();
}
void m3(){
pinMode(led8, OUTPUT);
digitalWrite(led8, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void n3(){
pinMode(led9, OUTPUT);
digitalWrite(led9, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void o3(){
pinMode(led10, OUTPUT);
digitalWrite(led10, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
delay (tijd);
uit();
}
void p3(){
pinMode(led11, OUTPUT);
digitalWrite(led11, LOW);
pinMode(led7, OUTPUT);
digitalWrite(led7, HIGH);
uit();
}
void a4(){
digitalWrite(14, HIGH);
pinMode(14, OUTPUT);
digitalWrite(14, HIGH);
delay (tijd);
uit();
}
void b4(){
pinMode(led9, OUTPUT);
digitalWrite(led9, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void c4(){
pinMode(led10, OUTPUT);
digitalWrite(led10, HIGH);
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
delay (tijd);
uit();
}
void d4(){
digitalWrite(15, HIGH);
pinMode(15, OUTPUT);
digitalWrite(15, HIGH);
delay (tijd);
uit();
}
void e4(){
pinMode(led8, OUTPUT);
digitalWrite(led8, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void f4(){
pinMode(led9, OUTPUT);
digitalWrite(led9, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void g4(){
pinMode(led10, OUTPUT);
digitalWrite(led10, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void h4(){
pinMode(led11, OUTPUT);
digitalWrite(led11, HIGH);
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
delay (tijd);
uit();
}
void i4(){
pinMode(led8, OUTPUT);
digitalWrite(led8, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void j4(){
pinMode(led9, OUTPUT);
digitalWrite(led9, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void k4(){
pinMode(led10, OUTPUT);
digitalWrite(led10, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void l4(){
pinMode(led11, OUTPUT);
digitalWrite(led11, HIGH);
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
delay (tijd);
uit();
}
void m4(){
digitalWrite(17, HIGH);
pinMode(17, OUTPUT);
digitalWrite(17, HIGH);
delay (tijd);
uit();
}
void n4(){
pinMode(led9, OUTPUT);
digitalWrite(led9, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void o4(){
pinMode(led10, OUTPUT);
digitalWrite(led10, HIGH);
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
delay (tijd);
uit();
}
void p4(){
digitalWrite(16, HIGH);
pinMode(16, OUTPUT);
digitalWrite(16, HIGH);
delay (tijd);
uit();
}
void test(){
pinMode(led0, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, INPUT);
pinMode(led9, INPUT);
pinMode(led10, INPUT);
pinMode(led11, INPUT);
digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
delay (tijd*4);
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd*4);
pinMode(led0, INPUT);
pinMode(led1, INPUT);
pinMode(led2, INPUT);
pinMode(led3, INPUT);
pinMode(led8, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led10, OUTPUT);
pinMode(led11, OUTPUT);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
delay (tijd*4);
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10, HIGH);
digitalWrite(led11, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay (tijd*4);
uit();
}
Downloads
Tinkering the Code
This appendix is some explanation about the code, so just read this part if you want to change (or understand) the code.
I broke the code up in lots of parts. These parts are called "void" and you can call them from the loop (who is also a void).
In this way I hoped to make the code easy to play with. So on every sensor, the code goes to an other "void".
If sensor 1 is the darkest the loop goes to a void called: "splash1". With sensor 2 to splash2, 3 to splash3 and 4 to splash4.
These void tells the cube that LEDs to light up.
To make it even easier, I gave each and every LED its own void. Now I don't need to write the piece of program to light a LED every time I need to light one, I can just call the void that does that and than wait a little while and turn it off again.
To make it a little bit understandable, I tried to put some logic in the names of the voids that light the LEDs.
All the LEDs on the first layer end with 1, the second layer ends with 2, third with 3 and fourth with 4. They all start with a letter, from a to p. (16 for every layer)
Lets see some code:
It is very clear to see here that it lights first all the LEDs on the fourth layer, one by one, next the third, the second and the first.
To understand the order of the LEDs, you need to know what each letter is:
I think this makes it a lot clearer. I think you can see what "splash" this is if you see the video.
So if you want that if you put your hand above sensor one, just the top left LED lights up, than the void would look like this:
I hope this clarifies the code a little.
I broke the code up in lots of parts. These parts are called "void" and you can call them from the loop (who is also a void).
In this way I hoped to make the code easy to play with. So on every sensor, the code goes to an other "void".
If sensor 1 is the darkest the loop goes to a void called: "splash1". With sensor 2 to splash2, 3 to splash3 and 4 to splash4.
These void tells the cube that LEDs to light up.
To make it even easier, I gave each and every LED its own void. Now I don't need to write the piece of program to light a LED every time I need to light one, I can just call the void that does that and than wait a little while and turn it off again.
To make it a little bit understandable, I tried to put some logic in the names of the voids that light the LEDs.
All the LEDs on the first layer end with 1, the second layer ends with 2, third with 3 and fourth with 4. They all start with a letter, from a to p. (16 for every layer)
Lets see some code:
void splash1()
{
a4(); b4(); c4(); d4(); h4(); l4(); p4(); o4(); n4(); m4(); i4(); e4(); f4(); g4(); k4(); j4();
j3(); f3(); g3(); k3(); o3(); n3(); m3(); i3(); e3(); a3(); b3(); c3(); d3(); h3(); l3(); p3();
p2(); o2(); n2(); m2(); i2(); e2(); a2(); b2(); c2(); d2(); h2(); l2(); k2(); j2(); f2(); g2();
g1(); k1(); j1(); f1(); b1(); c1(); d1(); h1(); l1(); p1(); o1(); n1(); m1(); i1(); e1(); a1();
}
It is very clear to see here that it lights first all the LEDs on the fourth layer, one by one, next the third, the second and the first.
To understand the order of the LEDs, you need to know what each letter is:
a b c d
e f g h
i j k l
m n o p
I think this makes it a lot clearer. I think you can see what "splash" this is if you see the video.
So if you want that if you put your hand above sensor one, just the top left LED lights up, than the void would look like this:
void splash1()
{
a4();
}
I hope this clarifies the code a little.