#include "atoz.h" // external library containing arrays for all the letters
// defining the column pins
#define C1 15
#define C2 16
#define C3 17
#define C4 18
#define C5 2
#define C6 3
#define C7 4
#define C8 5
// defining the row pins
#define R1 13
#define R2 12
#define R3 11
#define R4 10
#define R5 9
#define R6 8
#define R7 7
#define R8 6
void setup() {
Serial.begin(9600);
pinMode(21, INPUT);
Serial.println("Type in String.");
Serial.println("This is your text:");
for (int i = 2; i < 19; i++) { // for loop to set pins 2-19 as output and set to LOW
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
for (int j = 6; j < 14; j++) { // for loop to set pin 6-14 as HIGH
digitalWrite(j, HIGH);
}
}
// Function to select rows
void SelectRow(int row) {
if (row == 1) digitalWrite(R1, LOW); else digitalWrite(R1, HIGH);
if (row == 2) digitalWrite(R2, LOW); else digitalWrite(R2, HIGH);
if (row == 3) digitalWrite(R3, LOW); else digitalWrite(R3, HIGH);
if (row == 4) digitalWrite(R4, LOW); else digitalWrite(R4, HIGH);
if (row == 5) digitalWrite(R5, LOW); else digitalWrite(R5, HIGH);
if (row == 6) digitalWrite(R6, LOW); else digitalWrite(R6, HIGH);
if (row == 7) digitalWrite(R7, LOW); else digitalWrite(R7, HIGH);
if (row == 8) digitalWrite(R8, LOW); else digitalWrite(R8, HIGH); // if said row is selected write it on LOW otherwise set to HIGH
}
void Select_Columns(int column, int state) {
if (column == 1) digitalWrite(C1, state); // once row is picked it will cycle through the columns
if (column == 2) digitalWrite(C2, state); // if that columns value is on it will turn on the LED
if (column == 3) digitalWrite(C3, state); // the state variable checks if the value is 0 or 1
if (column == 4) digitalWrite(C4, state);
if (column == 5) digitalWrite(C5, state);
if (column == 6) digitalWrite(C6, state);
if (column == 7) digitalWrite(C7, state);
if (column == 8) digitalWrite(C8, state);
}
String inp;
String inpUpper;
int position = 0;
void loop() {
delay(1500);
int butread = digitalRead(21); // reads the button whether its pressed or not
while (Serial.available() > 0) {
inp = Serial.readStringUntil('\n');
inp.toUpperCase();// converts all input into upper case
}
int inputlen = inp.length(); // the length of the input
// first if statement that would run when the button is not pressed
// under this the letters scroll from right to left
if (butread == 0) {
for (int i = 0; i < inputlen; i++) { // for loop to iterate through all the letter in the input
//Serial.print(inp.charAt(i)); // prints the individual letters on serial monitor
switch (inp.charAt(i)) { // switch statement that iterates for every letter entered
case ' ': // accounting for spaces in input
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, blank[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
// following are the case statements for each letter
// Set_LED_in_Acitve_Row function's second parameter makes it so that the leds moved over by 1 to the left
// thus creating a scrolling effect
// for each iteration it moves it to one position to the right
case 'A':
for (int x = 0; x < 15; x++) { // for loop to set the speed of the scroll
for (int j = 0; j < 8; j++) { // loop to iterate through the rows
SelectRow(j + 1);
for (int i = 0; i < 8; i++) { // calls the column function
Select_Columns(i + 1, A[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1; // position increments by 1 for each interation
delay(10);
}
break;
case 'B':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, B[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'C':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, C[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'D':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, D[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'E':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, E[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'F':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, F[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'G':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, G[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'H':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, H[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'I':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, I[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'J':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, J[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'K':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, K[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'L':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, L[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'M':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, M[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'N':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, N[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'O':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, O[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'P':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, P[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'Q':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, Q[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'R':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, R[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'S':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, S[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'T':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, T[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'U':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, U[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'V':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, V[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'X':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, X[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'Y':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, Y[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
case 'Z':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 0; i < 8; i++) {
Select_Columns(i + 1, Z[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position + 1;
delay(10);
}
break;
}
}
}
// next else if statement runs when button is pressed
// under this the letters scroll from left to right
else if (butread == 1) {
for (int i = 0; i < inputlen; i++) {
Serial.print(inp.charAt(i));
// starts the position from the other side of the led matrix
// by default postion = 0 is on the right side
position = 8; // starts from the left
switch (inp.charAt(i)) {
case ' ':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) { // reverses the order through which the for loop iterates through the columns
Select_Columns(i + 1, blank[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1; // position decrements by 1 for each iterations
delay(10);
}
break;
case 'A':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, A[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'B':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, B[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'C':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, C[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'D':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, D[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'E':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, E[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'F':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, F[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'G':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, G[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'H':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, H[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'I':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, I[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'J':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, J[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'K':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, K[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'L':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, L[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'M':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, M[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'N':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, N[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'O':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, O[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'P':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, P[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'Q':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, Q[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'R':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, R[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'S':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, S[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'T':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, T[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'U':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, U[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'V':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, V[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'X':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, X[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'Y':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, Y[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
case 'Z':
for (int x = 0; x < 15; x++) {
for (int j = 0; j < 8; j++) {
SelectRow(j + 1);
for (int i = 8 ; i > 0; i--) {
Select_Columns(i + 1, Z[j][(i + position) - abs((i + position) / 16) * 16]);
}
delay(10);
}
position = position - 1;
delay(10);
}
break;
}
}
}
}