Instructables

Step 12: 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();

}  
 
Remove these adsRemove these ads by Signing Up
walnut232 years ago
Hey Kenyer, I have been fooling around with the delays and am wondering how to get the cube to stop lighting up until I put my hand over the sensors


Thanks,
Christian
kenyer (author)  walnut232 years ago
You can play around with the sensitivity of the sensors.

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;

"instellen van de gevoeligheid" means setting the sensitivity in Dutch. Here it is set on 20 for all four sensors. If you increase this number for all four sensors, they will be less sensitive.

It is also very important that you use cable with the anode connected to the inside and the cathode connected to a wire that is totally surrounding the inside cable and shielding it for interference that is all around us.