First off, my code, which works, but I really don't like it.
#include <LCD4Bit_mod.h>
LCD4Bit_mod lcd = LCD4Bit_mod(2);
char* ascii_chart[96] = { // as the lcd lib wants to print in decimal i'm using this to look up the character
" ", "!", "x", "#", "$", "%", "&", "x", "(", ")", "*", "+", ",", "-", ".", "/",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?",
"@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "x", "x", "x", "x",
"`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~"
};
int incomingByte = 0;
int charconv = 0; // incomingByte less 32 as my array starts at [space]
int position = 0; // horizontal position of cursor
int line = 1; // vertical positioin of cursor
void setup(){
lcd.init();
delay(100);
lcd.clear();
Serial.begin(9600);
}
void loop() {
// back to the top left position
if (line == 2 && position == 16){
line = 1;
position = 0;
lcd.clear();}
// next line
if(line == 1 && position == 16){
line = 2;
position = 0;}
lcd.cursorTo(line, position);
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
charconv = incomingByte - 32;
// say what you got:
lcd.printIn(ascii_chart[charconv]);
position ++;
}
}
The random x's in the array are due to various characters that evidently don't like being between "".
And now my little problem, if I get lcd.printIn to print incomingByte it prints the ascii code as decimal (after going through itoa()), if I make incomingByte a byte variable it errors with invalid conversion from 'byte' to 'char*. I'm thinking there must be a similar function to itoa() that will do what I need.
Any ideas? I'm sure it has to be extremely simple, but like my previous question no amount of reading sparks an answer. :-[