Hello!
Im working on an Arduino UNO project that will take a string from user input (maximum 20 characters), (also to be a single word or number at once, with no space or punctuation).
Then print out the string but each character or number is to be printed individually on a separate line.
Also, turn on one LED at a time corresponding to the letter or number. With only using a 10 LED bar.
All LEDs are to be turned on to represent zero.
FOR EXAMPLE:
Number "1918" has been inputted,
1 (LED nr. 1 has been turned on) [delay(1500)] then..
9 (LED nr. 9 has been turned on) [delay(1500)] then..
1 (LED nr. 1 has been turned on) [delay(1500)] then..
8 (LED nr. 8 has been turned on)
Then Ask User Input For Another String..
FOR EXAMPLE:
String "cat" has been inputted,
"c" (is the 3rd letter in the alphabet) and so (LED nr. 3 has been turned on) [delay(1500)] then..
"a" (is the 1st letter in the alphabet) and so (LED nr. 1 has been turned on) [delay(1500)] then..
"t" (is the 20th letter in the alphabet) and so (LED nr. 2 has been turned on, [delay(500)] then all LEDs turn on to represent the 0)
Then Ask User Input For Another String and so on...
The code I have so far:
int delayChoice = 1500;
int delayPause = 500;
char userInput[20];
int i;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;
int pin6 = 6;
int pin7 = 7;
int pin8 = 8;
int pin9 = 9;
int pin10 = 10;
int pin11 = 11;
int pin12 = 12;
String askStr = "Enter a word or number from 20 Characters: "; // String object
String num; // String object
void setup()
{
Serial.begin(9600);
pinMode(pin3,OUTPUT);
pinMode(pin4,OUTPUT);
pinMode(pin5,OUTPUT);
pinMode(pin6,OUTPUT);
pinMode(pin7,OUTPUT);
pinMode(pin8,OUTPUT);
pinMode(pin9,OUTPUT);
pinMode(pin10,OUTPUT);
pinMode(pin11,OUTPUT);
pinMode(pin12,OUTPUT);
}
void loop()
{
#include <string.h>
Serial.println(askStr);
while (Serial.available() == 0)
{
}
if(Serial.available() > 0)
{
Serial.readBytesUntil(' ', userInput, 20); //Read 20 characters from Serial into userInput
for(i = 0; i < 20; i++) //Loop 20 times
{
if(userInput[i] == '\0') //If the character at i is the null character
{
break; //Break out of the loop
}
else //If the character is not the null character
{
Serial.println(userInput[i]), digitalWrite(pin5, HIGH); //Print the character
}
}
}
delay(delayChoice);
}