Skip to main content

Scrolling Letters

int colArray[] = {A4, 6, 9, 10, 3};
int rowArray[] = {11, A3, 12, 4, 8, 2, 7};

int myWord[7][7] = {{ //[letterNum][7]
0b01110,
0b10001,
0b10000,
0b01110,
0b00001,
0b10001,
0b01110
}, {
0b11111,
0b00100,
0b00100,
0b00100,
0b00100,
0b00100,
0b00100,
}
, {
0b11111,
0b10000,
0b10000,
0b11110,
0b10000,
0b10000,
0b11111,
}
, {
0b11110,
0b10001,
0b10001,
0b11110,
0b10000,
0b10000,
0b10000,
}, {
0b10001,
0b10001,
0b10001,
0b11111,
0b10001,
0b10001,
0b10001,
}, {
0b11111,
0b10000,
0b10000,
0b11110,
0b10000,
0b10000,
0b11111,
}, {
0b10001,
0b11001,
0b10101,
0b10101,
0b10101,
0b10011,
0b10001,
}
};

int pattern[7][5];
int row[7];

void setup() {
Serial.begin(115200);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(A5, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(A3, OUTPUT);
}
int rowBinBit = 0;

void loop() {
for (int a = 0; a <= 30; ++a) { //(letterNum-1)*5
int startChar = a / 5;
int startPos = a % 5;
row[0] = 0;
for (int b = 0; b < 5; ++b) { //repeat 5 times (for each bit)
//Serial.println(myWord[startChar][0] & 1 << (4 - (startPos + b)));
for (int k = 0; k < 7; ++k) {
if (myWord[startChar][k] & 1 << (4 - (startPos + b))) {
//Serial.print("HERE");
//Serial.print(1<<b, BIN);
row[k] |= ((1 << (4 - b))) & 0b11111;
}
}
//Serial.print(startChar);
// Serial.print(", ");
//Serial.println(1<<(4-(startPos+b)));
if ((startPos + b) >= 4) { //gap between characters
startChar++;
startPos -= 6; //5 works
}
}
long timer = millis();
while (millis() - timer < 100) {
displayNow();
}
for (int k = 0; k < 7; ++k) {
row[k] = 0;
}
// for(int v=0; v<7; ++v){
// Serial.println(row[7], BIN);
// delay(20);
// }
}
//Serial.print(rowBinConv);
// delay(200000);

//
// row[0] = 0b01110;
// row[1] = 0b01110;
// row[2] = 0b00100;
// row[3] = 0b11111;
// row[4] = 0b00100;
// row[5] = 0b01110;
// row[6] = 0b01010;
// long timer = millis();
// while (millis() - timer < 200) {
// displayNow();
// }
}

void displayNow() {

for (int j = 0; j < 7; ++j) {
for (int i = 4; i >= 0; --i) {
if (row[j] & (1 << 4 - i)) {
pattern[j][i] = 1;
} else {
pattern[j][i] = 0;
}
}
}
for (int col = 0; col < 5; ++col) {
digitalWrite(colArray[col], HIGH);
for (int row = 0; row < 7; ++row) {
digitalWrite(rowArray[row], !pattern[row][col]);
}
delay(2);
clearAll();
}
}

void clearAll() {
//turn all off:
for (int col = 0; col < 5; ++col) {
digitalWrite(colArray[col], 0);
}
for (int row = 0; row < 7; ++row) {
digitalWrite(rowArray[row], 1);
}
}