Trying to create Arduino program with 7 segment displays

Hello all,
I am trying to create a program that reads four letters at once from a user, then displays them on four 7-segment displays, with a delay between each display. I keep getting errors about the array meant to hold the four letters. I'd appreciate any help with this.

int g = 1;
int f = 2;
int a = 3;
int b = 4;
int e = 5;
int d = 6;
int c = 7;
int h = 8; //period

int i;
int j;
int k;

char word[4]={};

const char letters[28] = {'A', 'a', 'b', 'C', 'c', 'd', 'E', 'F', 'G', 'H', 'h',
'I', 'i', 'J', 'L', 'l', 'n', 'O', 'o', 'P', 'q', 'r',
'S', 't', 'U', 'u', 'y', 'Z'};
const int binlt[28] = {0B11111010,0B10111110,0B11001110,0B01101100,0B10001100,0B10011110,0B11101100, //A-E
0B11101000,0B11101110,0B11011010,0B11001010,0B01001000,0B00001000,0B00011110, //F-J
0B01001100,0B00110010,0B10001010,0B01111110,0B10001110,0B11111000,0B11110010, //L-q
0B10001000,0B11100110,0B11001100,0B01011110,0B00001110,0B11010110,0B10111100}; //r-Z

void setup()
{
pinMode(1, OUTPUT);
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);
Serial.begin(9600);
Serial.println("Enter 4 letters from the list below with a space between letters: ");
Serial.println("A, a, b, C, c, d, E, F, G, H, h, I, i, J, L, l, n, O, o, P, q, r, S, t, U, u, y, Z");
}

void loop()
{
word = Serial.read();
digitalWrite(9,0);
digitalWrite(10,0);
digitalWrite(11,0);
digitalWrite(12,0);
for (int i=9; i<13; i++)
{
digitalWrite(9,0);
digitalWrite(10,0);
digitalWrite(11,0);
digitalWrite(12,0);
digitalWrite(i,1);
for (int j=0; j<28; j++)
{
if (word[j]==letters[j])
{
digitalWrite(a, bitRead(binlt[i],1));
digitalWrite(b, bitRead(binlt[i],2));
digitalWrite(c, bitRead(binlt[i],3));
digitalWrite(d, bitRead(binlt[i],4));
digitalWrite(e, bitRead(binlt[i],5));
digitalWrite(f, bitRead(binlt[i],6));
digitalWrite(g, bitRead(binlt[i],7));
digitalWrite(h, bitRead(binlt[i],8));
delay(500);
}
}
}
}
word has a size of 4 and so is indexed from 0 to 3.
But you are indexing it with j which goes from 0 to 27.
Maybe you mean to index it with i-9 ?
Also, binlt looks like it should be indexed with j, not i.
1. Use code tags when you post code.
https://www.cplusplus.com/articles/jEywvCM9/

2. Check your loop ranges.
1
2
3
for (int j=0; j<28; j++)
{
    if (word[j]==letters[j])

word[j] is out of bounds WAY before you get to 28.

3. digitalWrite(a, bitRead(binlt[i],1));
Bits are numbered from 0, not 1.
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bitread/
Last edited on
Registered users can post here. Sign in or register to post.