For one of my projects I have to use code to program 2 595n Shift registers, and I was going to use EEPROM code and BYTEs to program it. My issue is that I don't have the full knowledge about EEPROM and BYTE, and I was wondering if there were another other types of code that could be used in the same working function as EEPROM, but easier to understand/read.
This is my code right now and I want to simplify it by using easier code to understand instead of EEPROM.
#include <EEPROM.h>
byte letter_one = 0;
byte letter_two = 0;
uint16_t letter_one_binary = 0;
uint16_t letter_two_binary = 0;
uint16_t segmentletters[] = {
0b1110110010001000, //A
0b1111001010100000, //B
0b1001110000000000, //C
0b1111001000100000, //D
0b1001110010001000, //E
0b1000110010001000, //F
0b1011110010000000, //G
0b0110110010001000, //H
0b1001001000100000, //I
0b0111100000000000, //J
0b0000110101001000, //K
0b0001110000000000, //L
0b0110110100000100, //M
0b0110110001000100, //N
0b1111110000000000, //O
0b1100110010001000, //P
0b1111110001000000, //Q
0b1100110011001000, //R
0b1011010010001000, //S
0b1000001000100000, //T
0b0111110000000000, //U
0b0000110100010000, //V
0b0110110001010000, //W
0b0000000101010100, //X
0b0000000100100100, //Y
0b1001000100010000 //Z
};
uint8_t clockPin = 11;// define the pin usage for the MBv3
uint8_t clockPin1 = 5;
uint8_t dataPin = 9; //
uint8_t latchPin = 10; //
uint8_t outputEnablePin = 8;
uint8_t sizeMap = sizeof(segmentletters) >> 1; //number of entries in the LUT
void setup() {
Serial.begin(9600);
for (uint8_t i = 0; i <= sizeMap; i++) { //iterate through the LUT array
EEPROM.write('A' + i << 1, lowByte(segmentletters[i])); // writing the segment data to EEPROM
EEPROM.write(('A' + i << 1) + 1, highByte(segmentletters[i]));
}
pinMode(clockPin, OUTPUT);
pinMode(clockPin1, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(outputEnablePin, OUTPUT);
digitalWrite(latchPin, LOW);
}
void loop() {
Serial.println("Write two letters");
while (Serial.available() == 0);
byte letter_one = Serial.read();
if (letter_one >= 'A' && letter_one <= 'Z' ) {
letter_one = letter_one - 'A';
letter_one_binary = segmentletters[letter_one];
Serial.println(letter_one_binary, BIN);
Serial.println(letter_one);
}
delay(1);
if (Serial.available() >= 1) {
byte letter_two = Serial.read();
if (letter_two >= 'A' && letter_two <= 'Z' ) {
letter_two = letter_two - 65;
letter_two_binary = (segmentletters[letter_two]);
Serial.println(letter_two_binary, BIN);
Serial.println(letter_two);
}
delay(1);
while (Serial.available() >= 1) \
//Serial.println(Serial.available());
Serial.read();
}
}
while (Serial.available() == 0) {
digitalWrite(clockPin1, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, letter_one_binary);
shiftOut(dataPin, clockPin, LSBFIRST, letter_one_binary >> 8);
digitalWrite(latchPin, HIGH);
delay(1);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 00000000);
shiftOut(dataPin, clockPin, LSBFIRST, 00000000);
digitalWrite(latchPin, HIGH);
digitalWrite(clockPin1, LOW);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, letter_two_binary);
shiftOut(dataPin, clockPin, LSBFIRST, letter_two_binary >> 8);
digitalWrite(latchPin, HIGH);
delay(1);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 00000000);
shiftOut(dataPin, clockPin, LSBFIRST, 00000000);
digitalWrite(latchPin, HIGH);
}
}