// pass plus task q2
const int dataPin = 2; /* DS */
const int clockPin = 3; /* SHCP */
const int latchPin = 4; /* STCP */
// format is row1 leds,row2 etc
byte testimage[] = {B11000011,B11000011,B11000011,B11111111,B11111111,B11000011,B11000011,B11000011}; //H test
byte H[] = {B11000011,B11000011,B11000011,B11111111,B11111111,B11000011,B11000011,B11000011}; //H
byte O[] = {B11111111,B11111111,B11000011,B11000011,B11000011,B11000011,B11111111,B11111111}; //O
byte R[] = {B11111100,B11000011,B11000011,B11000011,B11111100,B11011000,B11001100,B11000110}; //R may still need some improvment
byte A[] = {B00011000,B00111100,B01100110,B11000011,B11111111,B11111111,B11000011,B11000011}; //A
byte T[] = {B11111111,B11111111,B00011000,B00011000,B00011000,B00011000,B00011000,B00011000}; //T
byte I[] = {B01111110,B01111110,B00011000,B00011000,B00011000,B00011000,B01111110,B01111110}; //I
// diffine colams to match wires
#define COL_1 37
#define COL_2 36
#define COL_3 35
#define COL_4 34
#define COL_5 33
#define COL_6 32
#define COL_7 31
#define COL_8 30
int timer1 = 1;
void setup() {
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
//y
pinMode(22, INPUT); // row 1
pinMode(23, INPUT); // row 2
pinMode(24, INPUT); // row 3
pinMode(25, INPUT); // row 4
pinMode(26, INPUT); // row 5
pinMode(27, INPUT); // row 6
pinMode(28, INPUT); // row 7
pinMode(29, INPUT); // row 8
// pinMode(22, INPUT_PULLUP); // row 1
// pinMode(23, INPUT_PULLUP); // row 2
// pinMode(24, INPUT_PULLUP); // row 3
// pinMode(25, INPUT_PULLUP); // row 4
// pinMode(26, INPUT_PULLUP); // row 5
// pinMode(27, INPUT_PULLUP); // row 6
// pinMode(28, INPUT_PULLUP); // row 7
// pinMode(29, INPUT_PULLUP); // row 8
// pinMode(22, OUTPUT); // row 1
// pinMode(23, OUTPUT); // row 2
// pinMode(24, OUTPUT); // row 3
// pinMode(25, OUTPUT); // row 4
// pinMode(26, OUTPUT); // row 5
// pinMode(27, OUTPUT); // row 6
// pinMode(28, OUTPUT); // row 7
// pinMode(29, OUTPUT); // row 8
//x
pinMode(30, OUTPUT); // coliam 8
pinMode(31, OUTPUT);
pinMode(32, OUTPUT);
pinMode(33, OUTPUT);
pinMode(34, OUTPUT);
pinMode(35, OUTPUT);
pinMode(36, OUTPUT);
pinMode(37, OUTPUT);
//digitalWrite(22, LOW);
}
void loop() {
delay(5);
timer1 += 1;
//for testing what letters look like
//cleardisplay();
//displayw(I);
// repetetly puts my name on screen 1 letter at a time
if (timer1 < 50) {
cleardisplay();
displayw(H,0); //do repetedly for some time then dislay next letter
//timer1++;
}
else if (timer1 < 60) {
//cleardisplay();
displayw(H,1);
}
else if (timer1 < 70) {
//cleardisplay();
displayw(H,2);
}
else if (timer1 < 80) {
//cleardisplay();
displayw(H,3);
}
// displaying O
else if (timer1 < 100) {
cleardisplay();
displayw(O,0);
//timer1++;
}
else if (timer1 < 150) {
cleardisplay();
displayw(R,0);
//timer1++;
}
else if (timer1 < 200) {
cleardisplay();
displayw(A,0);
//timer1++;
}
else if (timer1 < 250) {
cleardisplay();
displayw(T,0);
//timer1++;
}
else if (timer1 < 300) {
cleardisplay();
displayw(I,0);
//timer1++;
}
else if (timer1 < 350) {
cleardisplay();
displayw(O,0);
//timer1++;
}
else {
timer1 = 1;
}
//displayw(O);
}
void displayw(byte buffer[],int shift) {
int rown = 22;
for (byte i = 0; i < 8; i++) {
setColumns(buffer[i],shift); // Set columns for row i
digitalWrite(rown, LOW);
delay(5);
digitalWrite(rown, HIGH);
rown++ ;
}
rown = 22;
}
void setColumns(byte a,int shiftoffset) {
digitalWrite(COL_1, (a >> (0+shiftoffset)) & 0x01); // Get the 1st bit: 10000000
digitalWrite(COL_2, (a >> (1+shiftoffset)) & 0x01); // Get the 2nd bit: 01000000
digitalWrite(COL_3, (a >> (2+shiftoffset)) & 0x01); // Get the 3rd bit: 00100000
digitalWrite(COL_4, (a >> (3+shiftoffset)) & 0x01); // Get the 4th bit: 00010000
digitalWrite(COL_5, (a >> (4+shiftoffset)) & 0x01); // Get the 5th bit: 00001000
digitalWrite(COL_6, (a >> (5+shiftoffset)) & 0x01); // Get the 6th bit: 00000100
digitalWrite(COL_7, (a >> (6+shiftoffset)) & 0x01); // Get the 7th bit: 00000010
digitalWrite(COL_8, (a >> (7+shiftoffset)) & 0x01); // Get the 8th bit: 00000001
//note using & 0x01(bitwise and) to write bits one at a time taking the least significant bit for each a restriction ie. only write the bit in position a of the byte
}
void cleardisplay() {
for (int i = 22; i < 30; i++) {
digitalWrite(i, HIGH);
}
}