CrossRoads:
Please explain the idea behind changing the pin modes?
The design I proposed had the cathodes being driven high to disable the LEDs. If you change the pin to an input and let if float, the voltage becomes some unknown on the cathode, and +5 on the anode, so if you have efficient LEDs they could appear somewhat on.
I'm setting the pins to INPUT to disable them. But you are probably right, thats not grounding them and some voltage might be leaking out.
However I can't seem to figure out your method =/
How would you program the lightup() function?
I tried setting everything to OUTPUT and LOW but that just makes every LED light up for some reason. And still some are brighter than others.
This is what i have atm and need to re-program
void lightup(int led, char lens){
static int last = 0;
switch(lens){
case 'r':
//turn the last one off
pinMode(leftLensA[last], OUTPUT);
digitalWrite(leftLensA[last], LOW);
pinMode(leftLensC[last], OUTPUT);
digitalWrite(leftLensC[last], LOW);
//turn on given LED position
pinMode(leftLensA[led], OUTPUT);
digitalWrite(leftLensA[led], HIGH);
pinMode(leftLensC[led], OUTPUT);
digitalWrite(leftLensC[led], LOW);
last = led;
break;
case 'l':
//turn the last one off
pinMode(rightLensA[last], OUTPUT);
digitalWrite(rightLensA[last], LOW);
pinMode(rightLensC[last], OUTPUT);
digitalWrite(rightLensC[last], LOW);
//turn on given LED position
pinMode(rightLensA[led], OUTPUT);
digitalWrite(rightLensA[led], HIGH);
pinMode(rightLensC[led], OUTPUT);
digitalWrite(rightLensC[led], LOW);
last = led;
break;
}
}
On another note, still trying to figure out how to delay some instructions so i can actually animate the LED's.
FULL SOURCE CODE:
int leftLensA[] = {11,12,10,11,12,10,11,12,10};
int leftLensC[] = {13,13,13,A1,A1,A1,A0,A0,A0};
int rightLensA[] = {8,9,7,8,9,7,8,9,7};
int rightLensC[] = {6,6,6,4,4,4,5,5,5};
int wait = 3000;
void lightup(int led, char lens){
static int last = 0;
switch(lens){
case 'r':
//turn the last one off
pinMode(leftLensA[last], OUTPUT);
digitalWrite(leftLensA[last], LOW);
pinMode(leftLensC[last], OUTPUT);
digitalWrite(leftLensC[last], LOW);
//turn on given LED position
pinMode(leftLensA[led], OUTPUT);
digitalWrite(leftLensA[led], HIGH);
pinMode(leftLensC[led], OUTPUT);
digitalWrite(leftLensC[led], LOW);
last = led;
break;
case 'l':
//turn the last one off
pinMode(rightLensA[last], OUTPUT);
digitalWrite(rightLensA[last], LOW);
pinMode(rightLensC[last], OUTPUT);
digitalWrite(rightLensC[last], LOW);
//turn on given LED position
pinMode(rightLensA[led], OUTPUT);
digitalWrite(rightLensA[led], HIGH);
pinMode(rightLensC[led], OUTPUT);
digitalWrite(rightLensC[led], LOW);
last = led;
break;
}
}
void setup(){
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
digitalWrite(A0, LOW);
digitalWrite(A1, LOW);
Serial.begin(9600);
}
void loop(){
// cylon(10, 'v');
// fu();
xx();
}
ANIMATIONS.pde
void fu(){
lightup(0, 'l');
lightup(1, 'l');
lightup(2, 'l');
lightup(5, 'l');
lightup(4, 'l');
lightup(8, 'l');
lightup(0, 'r');
lightup(3, 'r');
lightup(6, 'r');
lightup(7, 'r');
lightup(8, 'r');
lightup(5, 'r');
lightup(2, 'r');
}
void xx(){
lightup(0, 'l');
lightup(2, 'l');
lightup(4, 'l');
lightup(5, 'l');
lightup(6, 'l');
lightup(8, 'l');
lightup(0, 'r');
lightup(2, 'r');
lightup(4, 'r');
lightup(5, 'r');
lightup(6, 'r');
lightup(8, 'r');
}
// COLUMNS AND LINES
//FOR EASIER MANIPULATION
void c1(){
lightup(2,'l');
lightup(5,'l');
lightup(8,'l');
}
void c2(){
lightup(1,'l');
lightup(4,'l');
lightup(7,'l');
}
void c3(){
lightup(0,'l');
lightup(3,'l');
lightup(6,'l');
}
void c4(){
lightup(2,'r');
lightup(5,'r');
lightup(8,'r');
}
void c5(){
lightup(1,'r');
lightup(4,'r');
lightup(7,'r');
}
void c6(){
lightup(0,'r');
lightup(3,'r');
lightup(6,'r');
}
void l1(){
lightup(8,'l');
lightup(7,'l');
lightup(6,'l');
lightup(8,'r');
lightup(7,'r');
lightup(6,'r');
}
void l2(){
lightup(5,'l');
lightup(4,'l');
lightup(3,'l');
lightup(5,'r');
lightup(4,'r');
lightup(3,'r');
}
void l3(){
lightup(2,'l');
lightup(1,'l');
lightup(0,'l');
lightup(2,'r');
lightup(1,'r');
lightup(0,'r');
}
void cylon(int hop, char orientation){
switch(orientation){
//HORIZONTAL CYLON
case 'h':
c1();
delay(hop); //this seems to get C1 stuck on the last lightup() instruction of c1() lighting up only 1 LED brightly.
c2();
delay(hop);
c3();
delay(hop);
c4();
delay(hop);
c5();
delay(hop);
c6();
delay(hop*2); //Reached end of the goggles, going back after hop*2
c5();
delay(hop);
c4();
delay(hop);
c3();
delay(hop);
c2();
delay(hop);
c1();
break;
//VERTICAL CYLON
case 'v':
l1();
delay(hop);
l2();
delay(hop);
l3();
delay(hop*2); //Reached the top of the gogglles, going back after hop*2
l2();
delay(hop);
l1();
break;
}
}
void clscr(){
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
}