Arduino UserInput, with LEDs

Hello
I have used this information

grafik

Using this information I´ve built this array:

constexpr int Text2Braille[][6]
{
  {0, 0, 0, 0, 0, 0}, // space
  {0, 1, 1, 1, 0, 1}, // !
  {0, 0, 0, 0, 1, 0}, // "
  {0, 0, 1, 1, 1, 1}, // #
};

and this array has to be completed with the missing characters.

I added a "programming-element" called "struct"

The reason I did this is for easier identifying which array element is which letter
and to be able to keep the two columm three-rows order of the braille-dot indexing

brailledot-numbering

  // brailledot-numeration
  // 1,4 
  // 2 5 
  // 3 6 

So you can write down all letters in the same order / same visual position as in the braille-definition you posted

Additionally the letter inside the struct could be used for searching the letter with a for-loop.
Of course this is not the most effective way to get the correct array-index
This would be something with switch-case and index-calculation based on ASCII-code

But this is another thing to learn.
And so far most users posting in this thread posted epxlanations that leave some questions open as you can see

This addtion is not needed due to the fact that the Braille ASCI table is structured already.

I guess with "this" you mean adding the letter. It is not nescessary. That is the reason why I wrote could be used. And I explained the reason why I added it:
more comfort when searching for a certain letter in the source-code beeing forced to add a letter.
additional possability to do a brute-force (in the sense always "try" all letters )search for each letter with a for-loop.

Iv'e tried adding in a few new arrays, but it doesn't seem to work properly with the LEDs. Any suggestions??

// Arduino UserInput, with LEDs
constexpr byte Leds[] {3, 4, 5, 6, 7, 8};
// Braille ASCII - Wikipedia

constexpr int Text2Braille[][6]
{
{0, 0, 0, 0, 0, 0}, // space
{0, 1, 1, 1, 0, 1}, // !
{0, 0, 0, 0, 1, 0}, // "
{0, 0, 1, 1, 1, 1}, // #
{0, 0, 1, 0, 1, 1}, //0
{0, 1, 0, 0, 0, 0}, //1
{0, 1, 1, 0, 0, 0}, //2
{0, 1, 0, 0, 1, 0}, //3
{0, 1, 0, 0, 1, 1}, //4
};

String askStr = "Enter a word or number from 20 Characters: ";

void setup()
{
Serial.begin(9600);
for (auto Led : Leds) pinMode(Led, OUTPUT);
}
void loop()
{
Serial.println(askStr);
while (Serial.available() == 0)
{
}

if (Serial.available() != 0)
{
char inChar = Serial.read();
if (inChar >= ' ' && inChar <= '_')
{
for (auto Led : Leds) digitalWrite(Led, LOW);
int element = 0;
for (auto Led : Leds) digitalWrite(Led, Text2Braille[inChar - ' '][element++]);
delay(1500);
}

}
}

forget to change symbol range

That one is ok the way it is, its including all of them, "_" is the very last one, after all the numbers and letters, and " " is the first one.

if the condition "including all of them", but an array not, you will face with critical array out bonds error in this line:

ok, im still lost. I dont understand what you mean. Please help me out!!

Was the code worked before you start to edit the array?

Yes. It worked very well but only for the first 4 characters off Ascii. And i wanted to add numbers and letters but i cant seem to get it to work. Help me

You edit the array incorrectly

if you look at the table Braille ASCII - Wikipedia, you will see that after the # symbol there are about a dozen more characters before the numbers begin.
The characters in your array must go in order exactly as in a table, you cannot skip.
Another option - you can organize another array separately for digits:

constexpr byte Leds[] {3, 4, 5, 6, 7, 8};
// [Braille ASCII - Wikipedia](https://en.wikipedia.org/wiki/Braille_ASCII)

constexpr int Text2Braille[][6]
{
{0, 0, 0, 0, 0, 0}, // space
{0, 1, 1, 1, 0, 1}, // !
{0, 0, 0, 0, 1, 0}, // "
{0, 0, 1, 1, 1, 1}, // #

};

constexpr int Digit2Braille[][6]
{
{0, 0, 1, 0, 1, 1}, //0
{0, 1, 0, 0, 0, 0}, //1
{0, 1, 1, 0, 0, 0}, //2
{0, 1, 0, 0, 1, 0}, //3
{0, 1, 0, 0, 1, 1}, //4
};

String askStr = "Enter a word or number from 20 Characters: ";

void setup()
{
Serial.begin(9600);
for (auto Led : Leds) pinMode(Led, OUTPUT);
}
void loop()
{
Serial.println(askStr);
while (Serial.available() == 0)
{
}

if (Serial.available() != 0)
{
char inChar = Serial.read();
if (inChar >= ' ' && inChar <= '#')
{
for (auto Led : Leds) digitalWrite(Led, LOW);
int element = 0;
for (auto Led : Leds) digitalWrite(Led, Text2Braille[inChar - ' '][element++]);
delay(1500);
}

else if (inChar >= '0' && inChar <= '4')
{
for (auto Led : Leds) digitalWrite(Led, LOW);
int element = 0;
for (auto Led : Leds) digitalWrite(Led, Digit2Braille[inChar - '0'][element++]);
delay(1500);
}

}
}

I'm following the philiosphy

easier to understand and to apply
With adding the character the sequence of the characters becomes irrelevant

// MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START *
// Take it for granted at the moment scroll down to void setup
// start of macros dbg and dbgi
#define dbg(myFixedText, variableName) \
  Serial.print( F(#myFixedText " "  #variableName"=") ); \
  Serial.println(variableName);
// usage: dbg("1:my fixed text",myVariable);
// myVariable can be any variable or expression that is defined in scope

#define dbgi(myFixedText, variableName,timeInterval) \
  do { \
    static unsigned long intervalStartTime; \
    if ( millis() - intervalStartTime >= timeInterval ){ \
      intervalStartTime = millis(); \
      Serial.print( F(#myFixedText " "  #variableName"=") ); \
      Serial.println(variableName); \
    } \
  } while (false);
// usage: dbgi("2:my fixed text",myVariable,1000);
// myVariable can be any variable or expression that is defined in scope
// third parameter is the time in milliseconds that must pass by until the next time a
// Serial.print is executed
// end of macros dbg and dbgi
// print only once when value has changed
#define dbgc(myFixedText, variableName) \
  do { \
    static long lastState; \
    if ( lastState != variableName ){ \
      Serial.print( F(#myFixedText " "  #variableName" changed from ") ); \
      Serial.print(lastState); \
      Serial.print( F(" to ") ); \
      Serial.println(variableName); \
      lastState = variableName; \
    } \
  } while (false);
// MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END *

// Arduino UserInput, with LEDs
constexpr byte Leds[] {3, 4, 5, 6, 7, 8};


struct Letter2Braille_type {
  char letter;
  byte brailleDots[6]; // 6 elements with index-numbers 0,1,2,3,4,5
};

// this array has the letters as an element of a struct
// this means the order in which the elements are defined
// is irrelevant if all elements are crawled through with
// a for-loop
Letter2Braille_type myLetter2BrailleArray[]
{ { .letter = 'A',
    1, 0,
    0, 0,
    0, 0
  },

  { .letter = 'B',
    1, 0,
    1, 0,
    0, 0
  },

  { .letter = 'C',
    1, 1,
    0, 0,
    0, 0
  },

  { .letter = '1',
    0, 1,
    0, 0,
    0, 0
  },

  { .letter = '2',
    0, 1,
    1, 0,
    0, 0
  },

  { .letter = '3',
    0, 1,
    0, 0,
    1, 0
  },

  { .letter = '4',
    0, 1,
    0, 0,
    1, 1
  } // last one is WITHOUT comma

};

String askStr = "Enter a word or number from 20 Characters: ";

void SetLEDsAndPrint(byte p_myIdx) {
  int element = 0;
  // the "0" and "1" are comming from READING the IO-pin
  // this means you read in the REAL IO-state of the IO-pins
  for (byte LedNr = 0; LedNr < 6; LedNr++ ) {
    digitalWrite(Leds[LedNr], myLetter2BrailleArray[p_myIdx].brailleDots[LedNr]);
    // this lines make visible in the serial monitor what is going on
    Serial.print("Leds[");
    Serial.print(LedNr);
    Serial.print("]=");
    Serial.println( digitalRead(Leds[LedNr]) );
  }
  // this for-loop prints the braille-dots in dot-order
  Serial.println("Braille-Dots");
  for (byte LedNr = 0; LedNr < 6; LedNr += 2 ) {
    Serial.print(digitalRead(Leds[LedNr]) );
    Serial.print(" ");
    Serial.println(digitalRead(Leds[LedNr + 1]) );
  }
}


byte findIndexNrOfChar(char p_myChar) {
            // no of bytes of complete array / number of bytes of one array-element
            // result= number of array-elements 
  byte MaxIdx (sizeof(myLetter2BrailleArray) / (sizeof(myLetter2BrailleArray[0])) );
  dbg("M:",MaxIdx );
  // iterate through array to find matching character
  for (byte Idx = 0; Idx < MaxIdx; Idx++) {
    if (myLetter2BrailleArray[Idx].letter == p_myChar) {
      return Idx;
    }
  }
  return 0;
}

void setup() {
  Serial.begin(115200);
  Serial.println( F("Setup-Start") );
  for (byte LedNr = 0; LedNr < 6; LedNr++ ) {
    pinMode(Leds[LedNr], OUTPUT);
  }
}

void loop() {
  Serial.println(askStr);
  while (Serial.available() == 0) {}
  if (Serial.available() != 0) {
    char inChar = Serial.read();
    dbgc("1:", inChar);
    if (inChar >= ' ' && inChar <= '_') {
      //dbgi("2:inChar >= ' ' && inChar <= '_' ist TRUE", 2, 1000);
      for (byte LedNr = 0; LedNr < 6; LedNr++ ) {
        digitalWrite(Leds[LedNr], LOW);
      }
      byte IDX = findIndexNrOfChar(inChar);
      SetLEDsAndPrint(IDX);
      delay(1500);
    }
  }
}

Hello and good morning andreighet

As correctly noticed by

Insert the next entries of the Braille ASCII tabelle simply until character '_'.

After the last character '#' the character '$' must follow inside the array until character '_'. That´s all to do to day.

In this way you will have all character for your braille device available.

So used UltraEdit for columwise editing the website table
then used LibreOffice to create the array
and di d some refinements to the code

// MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START *
// Take it for granted at the moment scroll down to void setup
// start of macros dbg and dbgi
#define dbg(myFixedText, variableName) \
  Serial.print( F(#myFixedText " "  #variableName"=") ); \
  Serial.println(variableName);
// usage: dbg("1:my fixed text",myVariable);
// myVariable can be any variable or expression that is defined in scope

#define dbgi(myFixedText, variableName,timeInterval) \
  do { \
    static unsigned long intervalStartTime; \
    if ( millis() - intervalStartTime >= timeInterval ){ \
      intervalStartTime = millis(); \
      Serial.print( F(#myFixedText " "  #variableName"=") ); \
      Serial.println(variableName); \
    } \
  } while (false);
// usage: dbgi("2:my fixed text",myVariable,1000);
// myVariable can be any variable or expression that is defined in scope
// third parameter is the time in milliseconds that must pass by until the next time a
// Serial.print is executed
// end of macros dbg and dbgi
// print only once when value has changed
#define dbgc(myFixedText, variableName) \
  do { \
    static long lastState; \
    if ( lastState != variableName ){ \
      Serial.print( F(#myFixedText " "  #variableName" changed from ") ); \
      Serial.print(lastState); \
      Serial.print( F(" to ") ); \
      Serial.println(variableName); \
      lastState = variableName; \
    } \
  } while (false);
// MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END *

// Arduino UserInput, with LEDs
constexpr byte Leds[] {3, 4, 5, 6, 7, 8};


struct Letter2Braille_type {
  char letter;
  byte brailleDots[6]; // 6 elements with index-numbers 0,1,2,3,4,5
};

// this array has the letters as an element of a struct
// this means the order in which the elements are defined
// is irrelevant if all elements are crawled through with
// a for-loop
Letter2Braille_type myLetter2BrailleArray[]
{
  { .letter = ' ',
    0, 0,
    0, 0,
    0, 0
  },

  { .letter = '!',
    0, 1,
    1, 1,
    0, 1
  },

  { .letter = '"',
    0, 0,
    0, 0,
    1, 0
  },

  { .letter = '#',
    0, 0,
    1, 1,
    1, 1
  },

  { .letter = '$',
    1, 1,
    0, 1,
    0, 1
  },

  { .letter = '%',
    1, 0,
    0, 1,
    0, 1
  },

  { .letter = '&',
    1, 1,
    1, 1,
    0, 1
  },

  { .letter = '\'',
    0, 0,
    1, 0,
    0, 0
  },

  { .letter = '(',
    1, 1,
    1, 0,
    1, 1
  },

  { .letter = ')',
    0, 1,
    1, 1,
    1, 1
  },

  { .letter = '*',
    1, 0,
    0, 0,
    0, 1
  },

  { .letter = '+',
    0, 0,
    1, 1,
    0, 1
  },

  { .letter = ',',
    0, 0,
    0, 0,
    0, 1
  },

  { .letter = '-',
    0, 0,
    1, 0,
    0, 1
  },

  { .letter = '.',
    0, 0,
    0, 1,
    0, 1
  },

  { .letter = '/',
    0, 0,
    1, 1,
    0, 0
  },

  { .letter = '0',
    0, 0,
    1, 0,
    1, 1
  },

  { .letter = '1',
    0, 1,
    0, 0,
    0, 0
  },

  { .letter = '2',
    0, 1,
    1, 0,
    0, 0
  },

  { .letter = '3',
    0, 1,
    0, 0,
    1, 0
  },

  { .letter = '4',
    0, 1,
    0, 0,
    1, 1
  },

  { .letter = '5',
    0, 1,
    0, 0,
    0, 1
  },

  { .letter = '6',
    0, 1,
    1, 0,
    1, 0
  },

  { .letter = '7',
    0, 1,
    1, 0,
    1, 1
  },

  { .letter = '8',
    0, 1,
    1, 0,
    0, 1
  },

  { .letter = '9',
    0, 0,
    1, 0,
    1, 0
  },

  { .letter = ':',
    1, 0,
    0, 0,
    1, 1
  },

  { .letter = ';',
    0, 0,
    0, 0,
    1, 1
  },

  { .letter = '<',
    1, 1,
    0, 0,
    0, 1
  },

  { .letter = '=',
    1, 1,
    1, 1,
    1, 1
  },

  { .letter = '>',
    0, 0,
    1, 1,
    1, 0
  },

  { .letter = '?',
    1, 0,
    0, 1,
    1, 1
  },

  { .letter = '@',
    0, 0,
    0, 1,
    0, 0
  },

  { .letter = 'A',
    1, 0,
    0, 0,
    0, 0
  },

  { .letter = 'B',
    1, 1,
    0, 0,
    0, 0
  },

  { .letter = 'C',
    1, 0,
    0, 1,
    0, 0
  },

  { .letter = 'D',
    1, 0,
    0, 1,
    1, 0
  },

  { .letter = 'E',
    1, 0,
    0, 0,
    1, 0
  },

  { .letter = 'F',
    1, 1,
    0, 1,
    0, 0
  },

  { .letter = 'G',
    1, 1,
    0, 1,
    1, 0
  },

  { .letter = 'H',
    1, 1,
    0, 0,
    1, 0
  },

  { .letter = 'I',
    0, 1,
    0, 1,
    0, 0
  },

  { .letter = 'J',
    0, 1,
    0, 1,
    1, 0
  },

  { .letter = 'K',
    1, 0,
    1, 0,
    0, 0
  },

  { .letter = 'L',
    1, 1,
    1, 0,
    0, 0
  },

  { .letter = 'M',
    1, 0,
    1, 1,
    0, 0
  },

  { .letter = 'N',
    1, 0,
    1, 1,
    1, 0
  },

  { .letter = 'O',
    1, 0,
    1, 0,
    1, 0
  },

  { .letter = 'P',
    1, 1,
    1, 1,
    0, 0
  },

  { .letter = 'Q',
    1, 1,
    1, 1,
    1, 0
  },

  { .letter = 'R',
    1, 1,
    1, 0,
    1, 0
  },

  { .letter = 'S',
    0, 1,
    1, 1,
    0, 0
  },

  { .letter = 'T',
    0, 1,
    1, 1,
    1, 0
  },

  { .letter = 'U',
    1, 0,
    1, 0,
    0, 1
  },

  { .letter = 'V',
    1, 1,
    1, 0,
    0, 1
  },

  { .letter = 'W',
    0, 1,
    0, 1,
    1, 1
  },

  { .letter = 'X',
    1, 0,
    1, 1,
    0, 1
  },

  { .letter = 'Y',
    1, 0,
    1, 1,
    1, 1
  },

  { .letter = 'Z',
    1, 0,
    1, 0,
    1, 1
  },

  { .letter = '[',
    0, 1,
    0, 1,
    0, 1
  },

  { .letter = '\\',
    1, 1,
    0, 0,
    1, 1
  },

  { .letter = ']',
    1, 1,
    0, 1,
    1, 1
  },

  { .letter = '^',
    0, 0,
    0, 1,
    1, 0
  },

  { .letter = '_',
    0, 0,
    0, 1,
    1, 1
  } // last one is WITHOUT comma
};

String askStr = "Enter a word or number from 20 Characters: ";

void SetLEDsAndPrint(byte p_myIdx) {
  int element = 0;
  // the "0" and "1" are comming from READING the IO-pin
  // this means you read in the REAL IO-state of the IO-pins
  for (byte LedNr = 0; LedNr < 6; LedNr++ ) {
    digitalWrite(Leds[LedNr], myLetter2BrailleArray[p_myIdx].brailleDots[LedNr]);
    // this lines make visible in the serial monitor what is going on
    Serial.print("Leds[");
    Serial.print(LedNr);
    Serial.print("]=");
    Serial.println( digitalRead(Leds[LedNr]) );
  }
  // this for-loop prints the braille-dots in dot-order
  Serial.println("Braille-Dots");
  for (byte LedNr = 0; LedNr < 6; LedNr += 2 ) {
    Serial.print(digitalRead(Leds[LedNr]) );
    Serial.print(" ");
    Serial.println(digitalRead(Leds[LedNr + 1]) );
  }
}


int findIndexNrOfChar(char p_myChar) {
  // no of bytes of complete array / number of bytes of one array-element
  // result= number of array-elements
  byte MaxIdx (sizeof(myLetter2BrailleArray) / (sizeof(myLetter2BrailleArray[0])) );
  //dbg("M:", MaxIdx );
  // iterate through array to find matching character
  for (byte Idx = 0; Idx < MaxIdx; Idx++) {
    if (myLetter2BrailleArray[Idx].letter == p_myChar) {
      return Idx; // if character is found return with Indexnumber of this character
    }
  }
  return -1; // if character is not found return -1
}

void setup() {
  Serial.begin(115200);
  Serial.println( F("Setup-Start") );
  for (byte LedNr = 0; LedNr < 6; LedNr++ ) {
    pinMode(Leds[LedNr], OUTPUT);
  }
  Serial.println(askStr);
}

void loop() {
  while (Serial.available() == 0) {}
  
  if (Serial.available() != 0) {
    char inChar = Serial.read();
    inChar = toupper(inChar);
    if (inChar >= ' ' ) { // only in case the received character is printable
      Serial.print("received character #");
      Serial.print(inChar);
      Serial.println("#");
    
      for (byte LedNr = 0; LedNr < 6; LedNr++ ) {
        digitalWrite(Leds[LedNr], LOW);
      }
      
      int IDX = findIndexNrOfChar(inChar);
      
      dbgc("I:",IDX);
      if (IDX >= 0) { // if character is found
        SetLEDsAndPrint(IDX);
        delay(1500);
      }
      Serial.println(askStr);
    }
  }
}