#define STROBE 6
#define CLOCK 7
#define DATA 5
// 8 MSB = ROWS , ACTIVE = LOW
// 8 LSB = COLUMNS , ACTIVE = HIGH
uint8_t selRow = 0;
volatile uint8_t displayData[8] = {0x30,0x78,0xCC,0xCC,0xFC,0xCC,0xCC,0x00};
ISR(TIMER1_COMPA_vect) //500hz -> 2ms
{
uint8_t bm = 0x80;
while (bm)
{
if (bm & (1<<selRow)) digitalWrite(DATA, LOW);
else digitalWrite(DATA, HIGH);
digitalWrite(CLOCK, HIGH);
digitalWrite(CLOCK, LOW);
bm>>=1;
}
bm = 0x80;
while (bm)
{
if (bm & displayData[7-selRow]) digitalWrite(DATA, HIGH);
else digitalWrite(DATA, LOW);
digitalWrite(CLOCK, HIGH);
digitalWrite(CLOCK, LOW);
bm>>=1;
}
selRow++;
selRow&=0x07;
digitalWrite(STROBE, HIGH);
digitalWrite(STROBE, LOW);
}
void allOFF()
{
digitalWrite(DATA, HIGH);
for (int i = 0; i < 8; i++)
{
digitalWrite(CLOCK, HIGH);
delay(10);
digitalWrite(CLOCK, LOW);
delay(10);
}
digitalWrite(DATA, LOW);
for (int i = 0; i < 8; i++)
{
digitalWrite(CLOCK, HIGH);
delay(10);
digitalWrite(CLOCK, LOW);
delay(10);
}
digitalWrite(STROBE, HIGH);
delay(10);
digitalWrite(STROBE, LOW);
delay(10);
}
void allON()
{
digitalWrite(DATA, LOW);
for (int i = 0; i < 8; i++)
{
digitalWrite(CLOCK, HIGH);
delay(10);
digitalWrite(CLOCK, LOW);
delay(10);
}
digitalWrite(DATA, HIGH);
for (int i = 0; i < 8; i++)
{
digitalWrite(CLOCK, HIGH);
delay(10);
digitalWrite(CLOCK, LOW);
delay(10);
}
digitalWrite(STROBE, HIGH);
delay(10);
digitalWrite(STROBE, LOW);
delay(10);
}
void setup() {
// put your setup code here, to run once:
pinMode(STROBE, OUTPUT);
pinMode(CLOCK, OUTPUT);
pinMode(DATA, OUTPUT);
digitalWrite(STROBE, LOW);
digitalWrite(CLOCK, LOW);
digitalWrite(DATA, LOW);
for (int i = 0; i < 2; i++)
{
allON();
delay(500);
allOFF();
delay(500);
}
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
// turn on CTC mode
TCCR1B = _BV(WGM12) | _BV(WGM13) | _BV(CS12) ;
ICR1 = 700; //
OCR1A = 0;
TIMSK1 = _BV(OCIE1A); // enable int. on OCR1A
}
uint8_t FontA[26][8] = {
{0x30,0x78,0xCC,0xCC,0xFC,0xCC,0xCC,0x00},
{0xFC,0x66,0x66,0x7C,0x66,0x66,0xFC,0x00},
{0x3C,0x66,0xC0,0xC0,0xC0,0x66,0x3C,0x00},
{0xF8,0x6C,0x66,0x66,0x66,0x6C,0xF8,0x00},
{0xFE,0x62,0x68,0x78,0x68,0x62,0xFE,0x00},
{0xFE,0x62,0x68,0x78,0x68,0x60,0xF0,0x00},
{0x3C,0x66,0xC0,0xC0,0xCE,0x66,0x3E,0x00},
{0xCC,0xCC,0xCC,0xFC,0xCC,0xCC,0xCC,0x00},
{0x78,0x30,0x30,0x30,0x30,0x30,0x78,0x00},
{0x1E,0x0C,0x0C,0x0C,0xCC,0xCC,0x78,0x00},
{0xE6,0x66,0x6C,0x78,0x6C,0x66,0xE6,0x00},
{0xF0,0x60,0x60,0x60,0x62,0x66,0xFE,0x00},
{0xC6,0xEE,0xFE,0xFE,0xD6,0xC6,0xC6,0x00},
{0xC6,0xE6,0xF6,0xDE,0xCE,0xC6,0xC6,0x00},
{0x38,0x6C,0xC6,0xC6,0xC6,0x6C,0x38,0x00},
{0xFC,0x66,0x66,0x7C,0x60,0x60,0xF0,0x00},
{0x78,0xCC,0xCC,0xCC,0xDC,0x78,0x1C,0x00},
{0xFC,0x66,0x66,0x7C,0x6C,0x66,0xE6,0x00},
{0x78,0xCC,0xE0,0x70,0x1C,0xCC,0x78,0x00},
{0xFC,0xB4,0x30,0x30,0x30,0x30,0x78,0x00},
{0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xFC,0x00},
{0xCC,0xCC,0xCC,0xCC,0xCC,0x78,0x30,0x00},
{0xC6,0xC6,0xC6,0xD6,0xFE,0xEE,0xC6,0x00},
{0xC6,0xC6,0x6C,0x38,0x38,0x6C,0xC6,0x00},
{0xCC,0xCC,0xCC,0x78,0x30,0x30,0x78,0x00},
{0xFE,0xC6,0x8C,0x18,0x32,0x66,0xFE,0x00}};
void loop() {
// put your main code here, to run repeatedly:
for(int i=0;i<26;i++)
{
cli();
for(int j=0;j<8;j++) displayData[j] = FontA[i][j];
sei();
delay(2000);
}
}