Hey
I'm working on a 24x8 led matrix based on this http://www.instructables.com/id/Make-a-24X6-LED-matrix/#step1
I'm trying to add next button to the display but i need help programming. example it would read off one set of words and then not switch to the next until a switch is pushed.
example,
byte hello_world[11][8] ={Mike,courtney};
I was thinking having a push button switch on one of the inputs on the arduino but i am unsure of how to program it.
any help is appreciated
here is the code
int latchPin = 10;
int clockPin = 13;
int dataPin = 11;
int clock = 9;
int Reset = 8;
int latchPinPORTB = latchPin - 8;
int clockPinPORTB = clockPin - 8;
int dataPinPORTB = dataPin - 8;
int i = 0;
long scrolling_word[8];
int array_turn=0;
byte hello_world[11][8] ={H,I,SPACE,G,U,Y,S}; // here is what is scrolling across the display
byte ALIVE[10][8] ={I,T,SPACE,W,O,R,K,S,EXCLAMATION};
void setup(){
Serial.begin(9600);
pinMode(dataPin,OUTPUT);
pinMode(clockPin,OUTPUT);
pinMode(latchPin,OUTPUT);
pinMode(clock,OUTPUT);
pinMode(Reset,OUTPUT);
digitalWrite(Reset,HIGH);
digitalWrite(Reset,LOW);
setupSPI();
}
void display_word(int loops,byte word_print[][8],int num_patterns,int delay_langth){
i = 0;
for(int g=0;g<8;g++)
scrolling_word[g] = 0;
for(int x=0;x<num_patterns;x++){
for(int r=0;r<8;r++)
scrolling_word[r] |= word_print[x][r];
for (int z=0;z<6;z++){
for(int p=0;p<8;p++)
scrolling_word[p] = scrolling_word[p] << 1;
for(int t=0;t<delay_langth;t++){
for(int y=0;y<8;y++){
if(i == 8){
digitalWrite(Reset,HIGH);
digitalWrite(Reset,LOW);
i = 0;
}
latchOff();
spi_transfer(make_word(0x01000000,y));
spi_transfer(make_word(0x00010000,y));
spi_transfer(make_word(0x00000100,y));
latchOn();
delayMicroseconds(800);
latchOff();
spi_transfer(0);
spi_transfer(0);
spi_transfer(0);
latchOn();
digitalWrite(clock,HIGH);
digitalWrite(clock,LOW);
i++;
}
}
}
}
finish_scroll(delay_langth);
}
void finish_scroll(int delay_scroll){
for (int n=0;n<24;n++){
for(int h=0;h<8;h++)
scrolling_word[h] = scrolling_word[h] << 1;
for(int w=0;w<delay_scroll;w++){
for(int k=0;k<8;k++){
if(i == 8){
digitalWrite(Reset,HIGH);
digitalWrite(Reset,LOW);
i = 0;
}
latchOff();
spi_transfer(make_word(0x01000000,k));
spi_transfer(make_word(0x00010000,k));
spi_transfer(make_word(0x00000100,k));
latchOn();
delayMicroseconds(800);
latchOff();
spi_transfer(0);
spi_transfer(0);
spi_transfer(0);
latchOn();
digitalWrite(clock,HIGH);
digitalWrite(clock,LOW);
i++;
}
}
}
}
byte make_word (long posistion,byte turn){
byte dummy_word = 0;
for(int q=0;q<8;q++){
if(scrolling_word[turn] & (posistion<<q))
dummy_word |= 0x01<<q;
}
return dummy_word;
}
void loop() {
display_word(1,hello_world,11,15);
display_word(1,ALIVE,11,15);
}
void latchOn(){
bitSet(PORTB,latchPinPORTB);
}
void latchOff(){
bitClear(PORTB,latchPinPORTB);
}
void setupSPI(){
byte clr;
SPCR |= ( (1<<SPE) | (1<<MSTR) ); // enable SPI as master
//SPCR |= ( (1<<SPR1) | (1<<SPR0) ); // set prescaler bits
SPCR &= ~( (1<<SPR1) | (1<<SPR0) ); // clear prescaler bits
clr=SPSR; // clear SPI status reg
clr=SPDR; // clear SPI data reg
SPSR |= (1<<SPI2X); // set prescaler bits
//SPSR &= ~(1<<SPI2X); // clear prescaler bits
delay(10);
}
byte spi_transfer(byte data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
return SPDR; // return the received byte, we don't need that
}