Hello world,
I'm trying to create some 'animations' to my LEDs, I copied the example from the Arduino's website and I'm modifying it, but How can I add more animations? (I'm using the Truth Table to create them, but it is not working).
The animation I set is working like this: it lights one row at a time, but I want to add more.
I'm simulating it on ISIS Proteus (I bought some tons of LEDS and resistors but it didn't arrive yet, here's a picture:
Here's the code:
//Pino conectado ao ST_CP do 74HC595
int latchPin = 8;
//Pino conectado ao SH_CP do 74HC595
int clockPin = 12;
//Pino conectado ao DS do 74HC595
int dataPin = 11;
//Armazena as informações
byte dataRED;
byte dataGREEN;
byte dataYELLOW;
byte dataBLUE;
byte dataR1;
byte dataArrayRED[10];
byte dataArrayGREEN[10];
byte dataArrayYELLOW[10];
byte dataArrayBLUE[10];
byte dataArrayR1[9];
void setup() {
//Pinos configurados para ser OUTPUT porque estão endereçados no looping principal
pinMode(latchPin, OUTPUT);
Serial.begin(9600);
//0xYY = Hexadecimal, BXXXXXXX = Binário
dataArrayRED[0] = 0x01; //00000001
dataArrayRED[1] = 0x02; //00000010
dataArrayRED[2] = 0x04; //00000100
dataArrayRED[3] = 0x08; //00001000
dataArrayRED[4] = 0x10; //00010000
dataArrayRED[5] = 0x20; //00100000
dataArrayRED[6] = 0x40; //01000000
dataArrayRED[7] = 0x80; //10000000
dataArrayGREEN[0] = 0x01; //00000001
dataArrayGREEN[1] = 0x02; //00000010
dataArrayGREEN[2] = 0x04; //00000100
dataArrayGREEN[3] = 0x08; //00001000
dataArrayGREEN[4] = 0x10; //00010000
dataArrayGREEN[5] = 0x20; //00100000
dataArrayGREEN[6] = 0x40; //01000000
dataArrayGREEN[7] = 0x80; //10000000
dataArrayYELLOW[0] = 0x01; //00000001
dataArrayYELLOW[1] = 0x02; //00000010
dataArrayYELLOW[2] = 0x04; //00000100
dataArrayYELLOW[3] = 0x08; //00001000
dataArrayYELLOW[4] = 0x10; //00010000
dataArrayYELLOW[5] = 0x20; //00100000
dataArrayYELLOW[6] = 0x40; //01000000
dataArrayYELLOW[7] = 0x80; //10000000
dataArrayBLUE[0] = 0x01; //00000001
dataArrayBLUE[1] = 0x02; //00000010
dataArrayBLUE[2] = 0x04; //00000100
dataArrayBLUE[3] = 0x08; //00001000
dataArrayBLUE[4] = 0x10; //00010000
dataArrayBLUE[5] = 0x20; //00100000
dataArrayBLUE[6] = 0x40; //01000000
dataArrayBLUE[7] = 0x80; //10000000
dataArrayR1[0] = 0x1; //00000001
dataArrayR1[1] = 0x3; //00000011
dataArrayR1[2] = 0x6; //00000110
dataArrayR1[3] = 0xc; //00001100
dataArrayR1[4] = 0x18; //00011000
dataArrayR1[5] = 0x30; //00110000
dataArrayR1[6] = 0x60; //01100000
dataArrayR1[7] = 0xc0; //11000000
dataArrayR1[8] = 0x80; //10000000
blinkAll_2Bytes(5,100); //Pisca todos os LEDs(Quantidade,Tempo [ms])
}
void loop() {
for (int j = 0; j < 8; j++) {
//load the light sequence you want from array
dataRED = dataArrayRED[j];
dataGREEN = dataArrayGREEN[j];
dataYELLOW = dataArrayYELLOW[j];
dataBLUE = dataArrayBLUE[j];
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, dataGREEN);
shiftOut(dataPin, clockPin, dataRED);
shiftOut(dataPin, clockPin, dataYELLOW);
shiftOut(dataPin, clockPin, dataBLUE);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(100);
}
for (int j1 = 0; j1 < 8; j1++) {
//load the light sequence you want from array
dataRED = dataArrayR1[j1];
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, dataR1);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(100);
}
}
// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut�
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}
//blinks the whole register based on the number of times you want to
//blink "n" and the pause between them "d"
//starts with a moment of darkness to make sure the first blink
//has its full visual effect.
void blinkAll_2Bytes(int n, int d) {
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 0);
shiftOut(dataPin, clockPin, 0);
digitalWrite(latchPin, 1);
delay(100);
for (int x = 0; x < n; x++) {
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 255);
shiftOut(dataPin, clockPin, 255);
digitalWrite(latchPin, 1);
delay(d);
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 0);
shiftOut(dataPin, clockPin, 0);
digitalWrite(latchPin, 1);
delay(d);
}
}