Digital Etcha Sketch

From NYC Resistor Wiki

Digital Etch-A-Sketch[edit]

No Pics yet.

Description[edit]

This is a work in progress currently.

Hardware[edit]

* LED Array ( Sure Electronics 6432 R/G LED Array board )
* Arduino Deumilinov 
* 5 Arcade Buttons
* Some laser cut Acryllic

Source Code[edit]

#include <avr/pgmspace.h>

char STRING[ ] = "AWESOME  AUGUST  ";

int A_pin = 2; // Data pin for rows selection A  PORTD 4
int B_pin = 3; // Data pin for rows selection B  PORTD 5
int C_pin = 4; // Data pin for rows selection C  PORTD 6
int D_pin = 5; // Data pin for rows selection D  PORTD 7

int G1_pin = 6; //green leds for uppwer rows  PORTD 11
int G2_pin = 7; //green leds for lower rows   PORTD 12
int R1_pin = 11; //red leds for uppwer rows   PORTB 4
int R2_pin = 12; //red leds for lower rows    PORTB 5

int S_pin = 8; //Clock pin
int L_pin = 9; //Latch pin
int E_pin = 10; //Enable pin

int xdelay = 0;
char buffer[8][8];

//Start the letter definition and put it in the FLASH memory

//Spc 20
char CH200[] PROGMEM = "11111111";
char CH201[] PROGMEM = "11111111";
char CH202[] PROGMEM = "11111111";
char CH203[] PROGMEM = "11111111";
char CH204[] PROGMEM = "11111111";
char CH205[] PROGMEM = "11111111";
char CH206[] PROGMEM = "11111111";
char CH207[] PROGMEM = "11111111";
//! 21
char CH210[] PROGMEM = "11110111";
char CH211[] PROGMEM = "11100011";
char CH212[] PROGMEM = "11100011";
char CH213[] PROGMEM = "11100011";
char CH214[] PROGMEM = "11110111";
char CH215[] PROGMEM = "11111111";
char CH216[] PROGMEM = "11110111";
char CH217[] PROGMEM = "11111111";
//qt 22
char CH220[] PROGMEM = "11001100";
char CH221[] PROGMEM = "11001100";
char CH222[] PROGMEM = "11001100";
char CH223[] PROGMEM = "11001100";
char CH224[] PROGMEM = "11111111";
char CH225[] PROGMEM = "11111111";
char CH226[] PROGMEM = "11111111";
char CH227[] PROGMEM = "11111111";
//# 23
char CH230[] PROGMEM = "11101101";
char CH231[] PROGMEM = "11101101";
char CH232[] PROGMEM = "11000000";
char CH233[] PROGMEM = "11101101";
char CH234[] PROGMEM = "11000000";
char CH235[] PROGMEM = "11101101";
char CH236[] PROGMEM = "11101101";
char CH237[] PROGMEM = "11111111";
//$ 24
char CH240[] PROGMEM = "11110111";
char CH241[] PROGMEM = "11000001";
char CH242[] PROGMEM = "10110111";
char CH243[] PROGMEM = "11000001";
char CH244[] PROGMEM = "11110110";
char CH245[] PROGMEM = "11000001";
char CH246[] PROGMEM = "11110111";
char CH247[] PROGMEM = "11111111";
//% 25
char CH250[] PROGMEM = "11011110";
char CH251[] PROGMEM = "10101101";
char CH252[] PROGMEM = "11011011";
char CH253[] PROGMEM = "11110111";
char CH254[] PROGMEM = "11101101";
char CH255[] PROGMEM = "11011010";
char CH256[] PROGMEM = "10111101";
char CH257[] PROGMEM = "11111111";
//& 26
char CH260[] PROGMEM = "11100111";
char CH261[] PROGMEM = "11011011";
char CH262[] PROGMEM = "11010111";
char CH263[] PROGMEM = "11101111";
char CH264[] PROGMEM = "11010110";
char CH265[] PROGMEM = "11011001";
char CH266[] PROGMEM = "11100010";
char CH267[] PROGMEM = "11111111";
//' 27
char CH270[] PROGMEM = "11111100";
char CH271[] PROGMEM = "11111001";
char CH272[] PROGMEM = "11110011";
char CH273[] PROGMEM = "11100111";
char CH274[] PROGMEM = "11001111";
char CH275[] PROGMEM = "11111111";
char CH276[] PROGMEM = "11111111";
char CH277[] PROGMEM = "11111111";
//( 28
char CH280[] PROGMEM = "11100111";
char CH281[] PROGMEM = "11011111";
char CH282[] PROGMEM = "10111111";
char CH283[] PROGMEM = "10111111";
char CH284[] PROGMEM = "10111111";
char CH285[] PROGMEM = "11011111";
char CH286[] PROGMEM = "11100111";
char CH287[] PROGMEM = "11111111";
//) 29
char CH290[] PROGMEM = "11110011";
char CH291[] PROGMEM = "11111101";
char CH292[] PROGMEM = "11111110";
char CH293[] PROGMEM = "11111110";
char CH294[] PROGMEM = "11111110";
char CH295[] PROGMEM = "11111101";
char CH296[] PROGMEM = "11110011";
char CH297[] PROGMEM = "11111111";
//* 2A
char CH2A0[] PROGMEM = "10111110";
char CH2A1[] PROGMEM = "11011101";
char CH2A2[] PROGMEM = "11101011";
char CH2A3[] PROGMEM = "10000000";
char CH2A4[] PROGMEM = "11101011";
char CH2A5[] PROGMEM = "11011101";
char CH2A6[] PROGMEM = "10111110";
char CH2A7[] PROGMEM = "11111111";
//+ 2B
char CH2B0[] PROGMEM = "11110111";
char CH2B1[] PROGMEM = "11110111";
char CH2B2[] PROGMEM = "11110111";
char CH2B3[] PROGMEM = "10000000";
char CH2B4[] PROGMEM = "11110111";
char CH2B5[] PROGMEM = "11110111";
char CH2B6[] PROGMEM = "11110111";
char CH2B7[] PROGMEM = "11111111";
//, 2C
char CH2C0[] PROGMEM = "11111111";
char CH2C1[] PROGMEM = "11111111";
char CH2C2[] PROGMEM = "11111111";
char CH2C3[] PROGMEM = "11100111";
char CH2C4[] PROGMEM = "11000111";
char CH2C5[] PROGMEM = "11000111";
char CH2C6[] PROGMEM = "11011111";
char CH2C7[] PROGMEM = "11111111";
// 2D
char CH2D0[] PROGMEM = "11111111";
char CH2D1[] PROGMEM = "11111111";
char CH2D2[] PROGMEM = "11111111";
char CH2D3[] PROGMEM = "11000000";
char CH2D4[] PROGMEM = "11000000";
char CH2D5[] PROGMEM = "11111111";
char CH2D6[] PROGMEM = "11111111";
char CH2D7[] PROGMEM = "11111111";
//. 2E
char CH2E0[] PROGMEM = "11111111";
char CH2E1[] PROGMEM = "11111111";
char CH2E2[] PROGMEM = "11111111";
char CH2E3[] PROGMEM = "11100011";
char CH2E4[] PROGMEM = "11000001";
char CH2E5[] PROGMEM = "11000001";
char CH2E6[] PROGMEM = "11100011";
char CH2E7[] PROGMEM = "11111111";
/// 2F
char CH2F0[] PROGMEM = "11111110";
char CH2F1[] PROGMEM = "11111100";
char CH2F2[] PROGMEM = "11111001";
char CH2F3[] PROGMEM = "11110011";
char CH2F4[] PROGMEM = "11100111";
char CH2F5[] PROGMEM = "11001111";
char CH2F6[] PROGMEM = "11011111";
char CH2F7[] PROGMEM = "11111111";
//0 30
char CH300[] PROGMEM = "11100011";
char CH301[] PROGMEM = "11011101";
char CH302[] PROGMEM = "10111010";
char CH303[] PROGMEM = "10110110";
char CH304[] PROGMEM = "10101110";
char CH305[] PROGMEM = "11011101";
char CH306[] PROGMEM = "11100011";
char CH307[] PROGMEM = "11111111";
//1 31
char CH310[] PROGMEM = "11110111";
char CH311[] PROGMEM = "11100111";
char CH312[] PROGMEM = "11010111";
char CH313[] PROGMEM = "11110111";
char CH314[] PROGMEM = "11110111";
char CH315[] PROGMEM = "11110111";
char CH316[] PROGMEM = "11000001";
char CH317[] PROGMEM = "11111111";
//2 32
char CH320[] PROGMEM = "11100011";
char CH321[] PROGMEM = "11011101";
char CH322[] PROGMEM = "11111101";
char CH323[] PROGMEM = "11111011";
char CH324[] PROGMEM = "11110111";
char CH325[] PROGMEM = "11101111";
char CH326[] PROGMEM = "11000000";
char CH327[] PROGMEM = "11111111";
//3 33
char CH330[] PROGMEM = "11000001";
char CH331[] PROGMEM = "10111110";
char CH332[] PROGMEM = "11111110";
char CH333[] PROGMEM = "11110001";
char CH334[] PROGMEM = "11111110";
char CH335[] PROGMEM = "10111110";
char CH336[] PROGMEM = "11000001";
char CH337[] PROGMEM = "11111111";
//4 34
char CH340[] PROGMEM = "11110011";
char CH341[] PROGMEM = "11101011";
char CH342[] PROGMEM = "11011011";
char CH343[] PROGMEM = "10000000";
char CH344[] PROGMEM = "11111011";
char CH345[] PROGMEM = "11111011";
char CH346[] PROGMEM = "11100001";
char CH347[] PROGMEM = "11111111";
//5 35
char CH350[] PROGMEM = "10000000";
char CH351[] PROGMEM = "10111111";
char CH352[] PROGMEM = "10100001";
char CH353[] PROGMEM = "10011110";
char CH354[] PROGMEM = "11111110";
char CH355[] PROGMEM = "10111110";
char CH356[] PROGMEM = "11000001";
char CH357[] PROGMEM = "11111111";
//6 36
char CH360[] PROGMEM = "11100001";
char CH361[] PROGMEM = "11011110";
char CH362[] PROGMEM = "10111111";
char CH363[] PROGMEM = "10100001";
char CH364[] PROGMEM = "10011110";
char CH365[] PROGMEM = "10111110";
char CH366[] PROGMEM = "11000001";
char CH367[] PROGMEM = "11111111";
//7 37
char CH370[] PROGMEM = "10000000";
char CH371[] PROGMEM = "10111110";
char CH372[] PROGMEM = "11111101";
char CH373[] PROGMEM = "11111011";
char CH374[] PROGMEM = "11110111";
char CH375[] PROGMEM = "11110111";
char CH376[] PROGMEM = "11110111";
char CH377[] PROGMEM = "11111111";
//8 38
char CH380[] PROGMEM = "11000001";
char CH381[] PROGMEM = "10111110";
char CH382[] PROGMEM = "10111110";
char CH383[] PROGMEM = "11000001";
char CH384[] PROGMEM = "10111110";
char CH385[] PROGMEM = "10111110";
char CH386[] PROGMEM = "11000001";
char CH387[] PROGMEM = "11111111";
//9 39
char CH390[] PROGMEM = "11000001";
char CH391[] PROGMEM = "10111110";
char CH392[] PROGMEM = "10111110";
char CH393[] PROGMEM = "11000000";
char CH394[] PROGMEM = "11111110";
char CH395[] PROGMEM = "10111101";
char CH396[] PROGMEM = "11000011";
char CH397[] PROGMEM = "11111111";
//: 3A
char CH3A0[] PROGMEM = "11100011";
char CH3A1[] PROGMEM = "11000001";
char CH3A2[] PROGMEM = "11100011";
char CH3A3[] PROGMEM = "11111111";
char CH3A4[] PROGMEM = "11100011";
char CH3A5[] PROGMEM = "11000001";
char CH3A6[] PROGMEM = "11100011";
char CH3A7[] PROGMEM = "11111111";
//; 3B
char CH3B0[] PROGMEM = "11100011";
char CH3B1[] PROGMEM = "11100011";
char CH3B2[] PROGMEM = "11100011";
char CH3B3[] PROGMEM = "11111111";
char CH3B4[] PROGMEM = "11100011";
char CH3B5[] PROGMEM = "11100011";
char CH3B6[] PROGMEM = "11101111";
char CH3B7[] PROGMEM = "11111111";
//< 3C
char CH3C0[] PROGMEM = "11110011";
char CH3C1[] PROGMEM = "11100111";
char CH3C2[] PROGMEM = "11001111";
char CH3C3[] PROGMEM = "10011111";
char CH3C4[] PROGMEM = "11001111";
char CH3C5[] PROGMEM = "11100111";
char CH3C6[] PROGMEM = "11110011";
char CH3C7[] PROGMEM = "11111111";
//= 3D
char CH3D0[] PROGMEM = "11111111";
char CH3D1[] PROGMEM = "10000000";
char CH3D2[] PROGMEM = "10000000";
char CH3D3[] PROGMEM = "11111111";
char CH3D4[] PROGMEM = "10000000";
char CH3D5[] PROGMEM = "10000000";
char CH3D6[] PROGMEM = "11111111";
char CH3D7[] PROGMEM = "11111111";
//> 3E
char CH3E0[] PROGMEM = "11100111";
char CH3E1[] PROGMEM = "11110011";
char CH3E2[] PROGMEM = "11111001";
char CH3E3[] PROGMEM = "11111100";
char CH3E4[] PROGMEM = "11111001";
char CH3E5[] PROGMEM = "11110011";
char CH3E6[] PROGMEM = "11100111";
char CH3E7[] PROGMEM = "11111111";
//? 3F
char CH3F0[] PROGMEM = "11000001";
char CH3F1[] PROGMEM = "10111110";
char CH3F2[] PROGMEM = "11111001";
char CH3F3[] PROGMEM = "11110111";
char CH3F4[] PROGMEM = "11110111";
char CH3F5[] PROGMEM = "11111111";
char CH3F6[] PROGMEM = "11110111";
char CH3F7[] PROGMEM = "11111111";
//@ 40
char CH400[] PROGMEM = "11100001";
char CH401[] PROGMEM = "11011110";
char CH402[] PROGMEM = "10110010";
char CH403[] PROGMEM = "10101010";
char CH404[] PROGMEM = "10100001";
char CH405[] PROGMEM = "10111111";
char CH406[] PROGMEM = "11000001";
char CH407[] PROGMEM = "11111111";
//A 07
char CH070[] PROGMEM = "11110011";
char CH071[] PROGMEM = "11101101";
char CH072[] PROGMEM = "11011110";
char CH073[] PROGMEM = "11000000";
char CH074[] PROGMEM = "11011110";
char CH075[] PROGMEM = "11011110";
char CH076[] PROGMEM = "11011110";
char CH077[] PROGMEM = "11111111";
//B 815
char CH8150[] PROGMEM = "11000001";
char CH8151[] PROGMEM = "11011110";
char CH8152[] PROGMEM = "11011110";
char CH8153[] PROGMEM = "11000001";
char CH8154[] PROGMEM = "11011110";
char CH8155[] PROGMEM = "11011110";
char CH8156[] PROGMEM = "11000001";
char CH8157[] PROGMEM = "11111111";
//C 1623
char CH16230[] PROGMEM = "11100001";
char CH16231[] PROGMEM = "11011110";
char CH16232[] PROGMEM = "11011111";
char CH16233[] PROGMEM = "11011111";
char CH16234[] PROGMEM = "11011111";
char CH16235[] PROGMEM = "11011110";
char CH16236[] PROGMEM = "11100001";
char CH16237[] PROGMEM = "11111111";
//D 2431
char CH24310[] PROGMEM = "11000001";
char CH24311[] PROGMEM = "11011110";
char CH24312[] PROGMEM = "11011110";
char CH24313[] PROGMEM = "11011110";
char CH24314[] PROGMEM = "11011110";
char CH24315[] PROGMEM = "11011110";
char CH24316[] PROGMEM = "11000001";
char CH24317[] PROGMEM = "11111111";
//E 3138
char CH31380[] PROGMEM = "11000000";
char CH31381[] PROGMEM = "11011111";
char CH31382[] PROGMEM = "11011111";
char CH31383[] PROGMEM = "11000011";
char CH31384[] PROGMEM = "11011111";
char CH31385[] PROGMEM = "11011111";
char CH31386[] PROGMEM = "11000000";
char CH31387[] PROGMEM = "11111111";
//F 3946
char CH39460[] PROGMEM = "11000000";
char CH39461[] PROGMEM = "11011111";
char CH39462[] PROGMEM = "11011111";
char CH39463[] PROGMEM = "11000011";
char CH39464[] PROGMEM = "11011111";
char CH39465[] PROGMEM = "11011111";
char CH39466[] PROGMEM = "11011111";
char CH39467[] PROGMEM = "11111111";
//G 4754
char CH47540[] PROGMEM = "11100001";
char CH47541[] PROGMEM = "11011110";
char CH47542[] PROGMEM = "11011111";
char CH47543[] PROGMEM = "11011000";
char CH47544[] PROGMEM = "11011110";
char CH47545[] PROGMEM = "11011110";
char CH47546[] PROGMEM = "11100000";
char CH47547[] PROGMEM = "11111111";
//H 5562
char CH55620[] PROGMEM = "11011110";
char CH55621[] PROGMEM = "11011110";
char CH55622[] PROGMEM = "11011110";
char CH55623[] PROGMEM = "11000000";
char CH55624[] PROGMEM = "11011110";
char CH55625[] PROGMEM = "11011110";
char CH55626[] PROGMEM = "11011110";
char CH55627[] PROGMEM = "11111111";
//I 5663
char CH0[] PROGMEM = "11000000";
char CH1[] PROGMEM = "11110011";
char CH2[] PROGMEM = "11110011";
char CH3[] PROGMEM = "11110011";
char CH4[] PROGMEM = "11110011";
char CH5[] PROGMEM = "11110011";
char CH6[] PROGMEM = "11000000";
char CH7[] PROGMEM = "11111111";
//J 6471
char CH64710[] PROGMEM = "11000000";
char CH64711[] PROGMEM = "11111110";
char CH64712[] PROGMEM = "11111110";
char CH64713[] PROGMEM = "11111110";
char CH64714[] PROGMEM = "11011110";
char CH64715[] PROGMEM = "11011110";
char CH64716[] PROGMEM = "11100001";
char CH64717[] PROGMEM = "11111111";
//K 7279
char CH72790[] PROGMEM = "11011110";
char CH72791[] PROGMEM = "11011101";
char CH72792[] PROGMEM = "11011011";
char CH72793[] PROGMEM = "11000111";
char CH72794[] PROGMEM = "11011011";
char CH72795[] PROGMEM = "11011101";
char CH72796[] PROGMEM = "11011110";
char CH72797[] PROGMEM = "11111111";
//L 8087
char CH80870[] PROGMEM = "11011111";
char CH80871[] PROGMEM = "11011111";
char CH80872[] PROGMEM = "11011111";
char CH80873[] PROGMEM = "11011111";
char CH80874[] PROGMEM = "11011111";
char CH80875[] PROGMEM = "11011111";
char CH80876[] PROGMEM = "11000000";
char CH80877[] PROGMEM = "11111111";
//M 8895
char CH88950[] PROGMEM = "11011110";
char CH88951[] PROGMEM = "11001100";
char CH88952[] PROGMEM = "11010010";
char CH88953[] PROGMEM = "11011110";
char CH88954[] PROGMEM = "11011110";
char CH88955[] PROGMEM = "11011110";
char CH88956[] PROGMEM = "11011110";
char CH88957[] PROGMEM = "11111111";
//N 96103
char CH961030[] PROGMEM = "11011110";
char CH961031[] PROGMEM = "11001110";
char CH961032[] PROGMEM = "11000110";
char CH961033[] PROGMEM = "11010010";
char CH961034[] PROGMEM = "11011000";
char CH961035[] PROGMEM = "11011100";
char CH961036[] PROGMEM = "11011110";
char CH961037[] PROGMEM = "11111111";
//O 104111
char CH1041110[] PROGMEM = "11000001";
char CH1041111[] PROGMEM = "10111110";
char CH1041112[] PROGMEM = "10111110";
char CH1041113[] PROGMEM = "10111110";
char CH1041114[] PROGMEM = "10111110";
char CH1041115[] PROGMEM = "10111110";
char CH1041116[] PROGMEM = "11000001";
char CH1041117[] PROGMEM = "11111111";
//P 112119
char CH1121190[] PROGMEM = "11000001";
char CH1121191[] PROGMEM = "11011110";
char CH1121192[] PROGMEM = "11011110";
char CH1121193[] PROGMEM = "11000001";
char CH1121194[] PROGMEM = "11011111";
char CH1121195[] PROGMEM = "11011111";
char CH1121196[] PROGMEM = "11011111";
char CH1121197[] PROGMEM = "11111111";
//Q 120127
char CH1201270[] PROGMEM = "11100001";
char CH1201271[] PROGMEM = "11011110";
char CH1201272[] PROGMEM = "11011110";
char CH1201273[] PROGMEM = "11011110";
char CH1201274[] PROGMEM = "11011010";
char CH1201275[] PROGMEM = "11011100";
char CH1201276[] PROGMEM = "11100000";
char CH1201277[] PROGMEM = "11111111";
//R 128135
char CH1281350[] PROGMEM = "11000001";
char CH1281351[] PROGMEM = "11011110";
char CH1281352[] PROGMEM = "11011110";
char CH1281353[] PROGMEM = "11000001";
char CH1281354[] PROGMEM = "11011011";
char CH1281355[] PROGMEM = "11011101";
char CH1281356[] PROGMEM = "11011110";
char CH1281357[] PROGMEM = "11111111";
//S 136143
char CH1361430[] PROGMEM = "11100001";
char CH1361431[] PROGMEM = "11011110";
char CH1361432[] PROGMEM = "11011111";
char CH1361433[] PROGMEM = "11100001";
char CH1361434[] PROGMEM = "11111110";
char CH1361435[] PROGMEM = "11011110";
char CH1361436[] PROGMEM = "11100001";
char CH1361437[] PROGMEM = "11111111";
//T 144151
char CH1441510[] PROGMEM = "11000000";
char CH1441511[] PROGMEM = "11110011";
char CH1441512[] PROGMEM = "11110011";
char CH1441513[] PROGMEM = "11110011";
char CH1441514[] PROGMEM = "11110011";
char CH1441515[] PROGMEM = "11110011";
char CH1441516[] PROGMEM = "11110011";
char CH1441517[] PROGMEM = "11111111";
//U 152159
char CH1521590[] PROGMEM = "11011110";
char CH1521591[] PROGMEM = "11011110";
char CH1521592[] PROGMEM = "11011110";
char CH1521593[] PROGMEM = "11011110";
char CH1521594[] PROGMEM = "11011110";
char CH1521595[] PROGMEM = "11011110";
char CH1521596[] PROGMEM = "11100001";
char CH1521597[] PROGMEM = "11111111";
//V 160167
char CH1601670[] PROGMEM = "10111110";
char CH1601671[] PROGMEM = "10111110";
char CH1601672[] PROGMEM = "11011101";
char CH1601673[] PROGMEM = "11011101";
char CH1601674[] PROGMEM = "11101011";
char CH1601675[] PROGMEM = "11101011";
char CH1601676[] PROGMEM = "11110111";
char CH1601677[] PROGMEM = "11111111";
//W 168175
char CH1681750[] PROGMEM = "10111110";
char CH1681751[] PROGMEM = "10111110";
char CH1681752[] PROGMEM = "10111110";
char CH1681753[] PROGMEM = "10110110";
char CH1681754[] PROGMEM = "10101010";
char CH1681755[] PROGMEM = "10011100";
char CH1681756[] PROGMEM = "10111110";
char CH1681757[] PROGMEM = "11111111";
//X 176183
char CH1761830[] PROGMEM = "10111110";
char CH1761831[] PROGMEM = "11011101";
char CH1761832[] PROGMEM = "11101011";
char CH1761833[] PROGMEM = "11110111";
char CH1761834[] PROGMEM = "11101011";
char CH1761835[] PROGMEM = "11011101";
char CH1761836[] PROGMEM = "10111110";
char CH1761837[] PROGMEM = "11111111";
//Y 184191
char CH1841910[] PROGMEM = "10111110";
char CH1841911[] PROGMEM = "11011101";
char CH1841912[] PROGMEM = "11101011";
char CH1841913[] PROGMEM = "11110111";
char CH1841914[] PROGMEM = "11110111";
char CH1841915[] PROGMEM = "11110111";
char CH1841916[] PROGMEM = "11110111";
char CH1841917[] PROGMEM = "11111111";
//Z 192199
char CH1921990[] PROGMEM = "10000000";
char CH1921991[] PROGMEM = "11111101";
char CH1921992[] PROGMEM = "11111011";
char CH1921993[] PROGMEM = "11110111";
char CH1921994[] PROGMEM = "11101111";
char CH1921995[] PROGMEM = "11011111";
char CH1921996[] PROGMEM = "10000000";
char CH1921997[] PROGMEM = "11111111";


char chl[ ] = {' ','!','q','#','$','%','&','\'','(',')','*','+',',','-', '.','/',
              '0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@',
              'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

PGM_P CHL[] PROGMEM= {
CH200,CH201,CH202,CH203,CH204,CH205,CH206,CH207,
CH210,CH211,CH212,CH213,CH214,CH215,CH216,CH217,
CH220,CH221,CH222,CH223,CH224,CH225,CH226,CH227,
CH230,CH231,CH232,CH233,CH234,CH235,CH236,CH237,
CH240,CH241,CH242,CH243,CH244,CH245,CH246,CH247,
CH250,CH251,CH252,CH253,CH254,CH255,CH256,CH257,
CH260,CH261,CH262,CH263,CH264,CH265,CH266,CH267,
CH270,CH271,CH272,CH273,CH274,CH275,CH276,CH277,
CH280,CH281,CH282,CH283,CH284,CH285,CH286,CH287,
CH290,CH291,CH292,CH293,CH294,CH295,CH296,CH297,
CH2A0,CH2A1,CH2A2,CH2A3,CH2A4,CH2A5,CH2A6,CH2A7,
CH2B0,CH2B1,CH2B2,CH2B3,CH2B4,CH2B5,CH2B6,CH2B7,
CH2C0,CH2C1,CH2C2,CH2C3,CH2C4,CH2C5,CH2C6,CH2C7,
CH2D0,CH2D1,CH2D2,CH2D3,CH2D4,CH2D5,CH2D6,CH2D7,
CH2E0,CH2E1,CH2E2,CH2E3,CH2E4,CH2E5,CH2E6,CH2E7,
CH2F0,CH2F1,CH2F2,CH2F3,CH2F4,CH2F5,CH2F6,CH2F7,
CH300,CH301,CH302,CH303,CH304,CH305,CH306,CH307,
CH310,CH311,CH312,CH313,CH314,CH315,CH316,CH317,
CH320,CH321,CH322,CH323,CH324,CH325,CH326,CH327,
CH330,CH331,CH332,CH333,CH334,CH335,CH336,CH337,
CH340,CH341,CH342,CH343,CH344,CH345,CH346,CH347,
CH350,CH351,CH352,CH353,CH354,CH355,CH356,CH357,
CH360,CH361,CH362,CH363,CH364,CH365,CH366,CH367,
CH370,CH371,CH372,CH373,CH374,CH375,CH376,CH377,
CH380,CH381,CH382,CH383,CH384,CH385,CH386,CH387,
CH390,CH391,CH392,CH393,CH394,CH395,CH396,CH397,
CH3A0,CH3A1,CH3A2,CH3A3,CH3A4,CH3A5,CH3A6,CH3A7,
CH3B0,CH3B1,CH3B2,CH3B3,CH3B4,CH3B5,CH3B6,CH3B7,
CH3C0,CH3C1,CH3C2,CH3C3,CH3C4,CH3C5,CH3C6,CH3C7,
CH3D0,CH3D1,CH3D2,CH3D3,CH3D4,CH3D5,CH3D6,CH3D7,
CH3E0,CH3E1,CH3E2,CH3E3,CH3E4,CH3E5,CH3E6,CH3E7,
CH3F0,CH3F1,CH3F2,CH3F3,CH3F4,CH3F5,CH3F6,CH3F7,
CH400,CH401,CH402,CH403,CH404,CH405,CH406,CH407,
CH070,CH071,CH072,CH073,CH074,CH075,CH076,CH077,
CH8150,CH8151,CH8152,CH8153,CH8154,CH8155,CH8156,CH8157,
CH16230,CH16231,CH16232,CH16233,CH16234,CH16235,CH16236,CH16237,
CH24310,CH24311,CH24312,CH24313,CH24314,CH24315,CH24316,CH24317,
CH31380,CH31381,CH31382,CH31383,CH31384,CH31385,CH31386,CH31387,
CH39460,CH39461,CH39462,CH39463,CH39464,CH39465,CH39466,CH39467,
CH47540,CH47541,CH47542,CH47543,CH47544,CH47545,CH47546,CH47547,
CH55620,CH55621,CH55622,CH55623,CH55624,CH55625,CH55626,CH55627,
CH0,CH1,CH2,CH3,CH4,CH5,CH6,CH7,
CH64710,CH64711,CH64712,CH64713,CH64714,CH64715,CH64716,CH64717,
CH72790,CH72791,CH72792,CH72793,CH72794,CH72795,CH72796,CH72797,
CH80870,CH80871,CH80872,CH80873,CH80874,CH80875,CH80876,CH80877,
CH88950,CH88951,CH88952,CH88953,CH88954,CH88955,CH88956,CH88957,
CH961030,CH961031,CH961032,CH961033,CH961034,CH961035,CH961036,CH961037,
CH1041110,CH1041111,CH1041112,CH1041113,CH1041114,CH1041115,CH1041116,CH1041117,
CH1121190,CH1121191,CH1121192,CH1121193,CH1121194,CH1121195,CH1121196,CH1121197,
CH1201270,CH1201271,CH1201272,CH1201273,CH1201274,CH1201275,CH1201276,CH1201277,
CH1281350,CH1281351,CH1281352,CH1281353,CH1281354,CH1281355,CH1281356,CH1281357,
CH1361430,CH1361431,CH1361432,CH1361433,CH1361434,CH1361435,CH1361436,CH1361437,
CH1441510,CH1441511,CH1441512,CH1441513,CH1441514,CH1441515,CH1441516,CH1441517,
CH1521590,CH1521591,CH1521592,CH1521593,CH1521594,CH1521595,CH1521596,CH1521597,
CH1601670,CH1601671,CH1601672,CH1601673,CH1601674,CH1601675,CH1601676,CH1601677,
CH1681750,CH1681751,CH1681752,CH1681753,CH1681754,CH1681755,CH1681756,CH1681757,
CH1761830,CH1761831,CH1761832,CH1761833,CH1761834,CH1761835,CH1761836,CH1761837,
CH1841910,CH1841911,CH1841912,CH1841913,CH1841914,CH1841915,CH1841916,CH1841917,
CH1921990,CH1921991,CH1921992,CH1921993,CH1921994,CH1921995,CH1921996,CH1921997};

//END letter def



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);
  
  Serial.begin(9600);
  
}

void loop(){

   
 //  PORTD |= 0x12;
  // PORTD |= 0x13; 
  PORTD |= 0x08;
 //  digitalWrite(G1_pin, HIGH); // PIN 6
 //  digitalWrite(G2_pin, HIGH); // PIN 7
  // PORTB |= 0x17;
  PORTB |= 0x18;
//  PORTB &= ~0x18;
  // digitalWrite(R1_pin, HIGH); // PIN 11
  // digitalWrite(R2_pin, HIGH); // PIN 12


  while(1){
    
    for(int j=0;j<16;j++){ // start a line scan
       spi_number(j, G2_pin);
    }
  }
}


// Additional functions

void spi_number(int row, int MOUT) {

  // function to transfer a char to the SPI inteface
  
  int div, imp, j;
    
  int str_pos;
  int prev_str_pos;
  
  PORTB |= 0x03;
  sel_row(row % 16);
 
  PORTB &= 0xfc;
  
  for(int i = 1; i <=64; i++) { // setup a scan of 64 iterations to find out the column led
     str_pos= (i/8)+ ((row/8)*8);
     

     if(sizeof(STRING) -1 > str_pos){         
       if(prev_str_pos != str_pos){
         //Serial.println(STRING[str_pos]);
         get_buffer(STRING[str_pos]);
         prev_str_pos = str_pos;
       }  
     }else if(sizeof(STRING) -1 == str_pos){
         null_buffer();
         //print_buffer();      
     }
     if(((int)(buffer[row%8][(i)%8]) == 48) && (sizeof(STRING) -1 > str_pos)) //48 = 0 in ASCII
       digitalWrite(MOUT, LOW);
     else  
       digitalWrite(MOUT, HIGH); 
     /*
     digitalWrite(S_pin,LOW);
     digitalWrite(S_pin,HIGH);
     */
     PORTB &= 0xfe;
     PORTB |= 0x01;
}
  PORTB &= 0xfd;
  PORTB |= 0x02;

}

void sel_row(int row){
  PORTD &= 0xC0;
  PORTD |= (row<<2);
}

void get_buffer(char chr){

  for(int i=0; i<sizeof(chl); i++){
  
    if(chl[i] == chr){     
    
        int pos = i*8;
        
        for(int j=0;j<8;j++){
    
        strcpy_P(buffer[j], (PGM_P)pgm_read_word(&(CHL[j+pos])));
       
        }
    
    }
    
  }

}


void null_buffer(){

  for(int i=0;i<8;i++)
    for(int j=0; j<8;j++)
      buffer[i][j] = 0;

}