Took me a bit to get the order and timing of everything straight. The digitalWrite function is too slow and direct i/o had to be used.
In this code, I removed the font definitions to save space. I just grabbed them from: http://www.dattalo.com/gnupic/lcdfont.inc
Also the setting and positioning of the text is half assed, I haven't cleaned it up yet.
#include <avr/pgmspace.h>
int A_pin = 2; // Data pin for rows selection A
int B_pin = 3; // Data pin for rows selection B
int C_pin = 4; // Data pin for rows selection C
int D_pin = 5; // Data pin for rows selection D
int G1_pin = 9; //6; //green leds for uppwer rows
int G2_pin = 10; //7; //green leds for lower rows
int R1_pin = 11; //red leds for uppwer rows
int R2_pin = 12; //red leds for lower rows
int S_pin = 8; //Clock pin
int L_pin = 6; //9; //Latch pin
int E_pin = 7; //10; //Enable pin
int g1;
int g2;
int r1;
int r2;
int xdelay = 250;
unsigned long byte_checker = (unsigned long)1 << 0;
unsigned long displayBitmap[2*32*2]; // Bitmap for display
// The bitmap (64x32) is arranged with 8 bytes per row aligned on long.
// The upper 32 rows controls the Red LED's
// The lower 32 rows controls the Green LED's
// To get yellow, set both green and red at the same time... ;-)
prog_uchar PROGMEM myfont[256][5] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00 }, // 0
..
{ 0x00, 0x00, 0x00, 0x00, 0x00 } // 255
};
char *disp[] = {" FUN WITH ", "ARDUINO!!!!!", " fun with ", "arduino :)"};
void setup(){
pinMode(A_pin, OUTPUT);
pinMode(B_pin, OUTPUT);
pinMode(C_pin, OUTPUT);
pinMode(D_pin, OUTPUT);
pinMode(G1_pin, OUTPUT);
pinMode(G2_pin, OUTPUT);
pinMode(R1_pin, OUTPUT);
pinMode(R2_pin, OUTPUT);
pinMode(S_pin, OUTPUT);
pinMode(L_pin, OUTPUT);
pinMode(E_pin, OUTPUT);
//set_pixel(1,3,3);
Serial.begin(9600);
for (byte line=0; line < 4; ++line) {
for (byte c=0; c<11; ++c) {
for (byte y=0; y<5; ++y) {
byte data = (byte) pgm_read_byte (&myfont[disp[line][c]][y]); // fetch data from program memory
for (byte x=0; x<7; ++x) {
if (data & (1<<x)) {
// on is off
int color = 2;
if (line > 1)
color = 1;
set_pixel((6-x) + (line * 8),y + (c*6),color);
} else {
//set_pixel(x,y,1);
}
}
}
}
}
}
void loop(){
for(int x=0;x<16;x++){ // start a line scan
digitalWrite(E_pin, HIGH);
byte_checker = (unsigned long)1 << 0;
for(int y = 0; y < 64; y++) { // setup a scan of 64 iterations to find out the column led
//000 R2 R1 G2 G1 CLK
byte row = B00011110; // Default to R[1|2] G[1|2] off and CLOCK to low.
// G1
g1 = x*2;
g2 = (x*2) + 32;
r1 = (x*2) + 64;
r2 = (x*2) + 96;
if (y==32)
byte_checker = (unsigned long)1 << 0;
if (y > 31) {
g1++;
g2++;
r1++;
r2++;
}
if (displayBitmap[g1] & byte_checker)
row ^= (1 << 1);
if (displayBitmap[g2] & byte_checker)
row ^= (1 << 2);
if (displayBitmap[r1] & byte_checker)
row ^= (1 << 4);
if (displayBitmap[r2] & byte_checker)
row ^= (1 << 3);
byte_checker <<= 1;
PORTB = row;
delayMicroseconds(1); //needed to not toggle the clock too fast
PORTB |= B00000001; // Clock back to HIGH
}
digitalWrite(E_pin, LOW);
digitalWrite(L_pin,HIGH); // latch the data
digitalWrite(L_pin,LOW);
int pinState = 0;
int abcd_pins[] = {A_pin,B_pin,C_pin,D_pin};
for (int i=4; i>=0; i--) {
if ( x & (1<<i) )
pinState= 1;
else
pinState= 0;
digitalWrite(abcd_pins[i], pinState);
}
digitalWrite(E_pin, HIGH);
delayMicroseconds(xdelay);
}
}
void set_pixel(int x, int y, int color) {
// find byte location
int location = x*2;
if (y>31)
location++;
if ((color == 1) || (color == 3))
displayBitmap[location] ^= (unsigned long)1<<y%32;
if ((color == 2) || (color == 3))
displayBitmap[location+64] ^= (unsigned long)1<<y%32;
}