hm.... I am making progress, but I have stumbled upon a new problem.
So I have a set up now that if I press a button I get one type of response on the matrix, and if I press it again I get another.
The problem is they seam to be getting mixed up a bit. Like: if switchstate is 'on' I get a flash of switchstate 'off'.
any thoughts on why? any help is greatly appreciated...
I have the following code:
#define CHIPSELECT 10//ss
#define SPICLOCK 13//sck
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO
int switchPin = 2; // digital input pin for a switch
int switchState = 0; // the state of the switch
byte *out_buffer; // Pointer to next image to be sent.
byte C2[] = {
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0
};
byte C3[] = {
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0
};
byte C4[] = {
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0
};
byte C5[] = {
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0
};
byte C6[] = {
0,0,0,1,0xC0,0,0,0,
0,0,0,1,0xC0,0,0,0,
0,0,0,1,0xC0,0,0,0,
0,0,0,1,0xC0,0,0,0,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,0xC0
};
byte CHECKED8[] = {
1,1,1,1,0xC0,0xC0,0xC0,0xC0,
1,0xC0,0xC0,1,0xC0,1,1,0xC0,
1,0xC0,0xC0,1,0xC0,1,1,0xC0,
1,1,1,1,0xC0,0xC0,0xC0,0xC0,
0xC0,0xC0,0xC0,0xC0,1,1,1,1,
0xC0,1,1,0xC0,1,0xC0,0xC0,1,
0xC0,1,1,0xC0,1,0xC0,0xC0,1,
0xC0,0xC0,0xC0,0xC0,1,1,1,1
};
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
}
/*
Write image to display.
/
void write_buffer(){
digitalWrite(CHIPSELECT,LOW); // enable
delay(5);
for(int i = 0; i < 64; i++){
spi_transfer(out_buffer);*
}
digitalWrite(CHIPSELECT,HIGH); // disable device
delay(5);
}
void setup()
{
-
pinMode(switchPin, INPUT); // set the switch pin to be an input*
byte clr;
pinMode(DATAOUT,OUTPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(CHIPSELECT,OUTPUT);
digitalWrite(CHIPSELECT,HIGH); //disable device
SPCR = B01010001; //SPI Registers
SPSR = SPSR & B11111110; //make sure the speed is 125KHz
clr=SPSR;
clr=SPDR;
delay(10);
}
*void loop() { *
-
switchState = digitalRead(switchPin);*
if (switchState == 1) {
out_buffer = C2;
write_buffer();
delay(50);
-
out_buffer = C3;*
write_buffer();
delay(50);
-
out_buffer = C4;*
write_buffer();
delay(50);
-
out_buffer = C5;*
write_buffer();
delay(50);
-
out_buffer = C6;*
write_buffer();
delay(50);
-
out_buffer = C7;*
write_buffer();
delay(50);
out_buffer = C8;
write_buffer();
delay(50);
out_buffer = C9;
write_buffer();
delay(50);
-
out_buffer = C10;*
write_buffer();
delay(50);
-
}*
-
else {*
-
// if the switch is open:*
-
out_buffer = CHECKED1;*
write_buffer();
delay(100);
out_buffer = CHECKED2;
write_buffer();
delay(100);
-
out_buffer = CHECKED3;*
write_buffer();
delay(100);
-
out_buffer = CHECKED4;*
write_buffer();
delay(100);
-
out_buffer = CHECKED5;*
write_buffer();
delay(100);
-
out_buffer = CHECKED6;*
write_buffer();
delay(100);
-
out_buffer = CHECKED7;*
write_buffer();
delay(100);
-
out_buffer = CHECKED8;*
write_buffer();
delay(100);
-
}*
}