I want to store some data in an array and display it.
The data will be variable in between the length of 5 to 20. This data will be given through Serial keyboard.
I have tried to search codes but it doesn't show as i require. Most of the codes have array inputs given already and doesn't allow the user the liberty to change the input, like i want to, using the Keyboard.
Sorry if problem seems too easy,but i am a newbie to programming.
I want to store some data in an array and display it.
Permission granted.
The data will be variable in between the length of 5 to 20.
5 to 20 what? Inches? Meters? Light years? Characters?
but it doesn't show as i require.
What doesn't? What do you require?
Most of the codes have array inputs given already and doesn't allow the user the liberty to change the input, like i want to, using the Keyboard.
Serial Input Basics
- Get your serial data
- Convert it to an integer - if that is what you want to store in your array
- store it in the array
int array[20]
byte element_count = get_element_count_from serial();
for (int i=0; i<element_count; i++) {
array[i] = get_next_element_from_serial();
}
You might want to interleave the serial interaction with storing the array in loop() for less blocking and better error handling.
I have written this code, but it gives very illogical output.
char incomingByte[10]; // for incoming serial data
int i=0;
void setup() {
-
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps*
}
void loop() {
-
// send data only when you receive data:*
-
if (Serial.available() > 0) {*
-
// read the incoming byte:*
_ incomingByte = Serial.read();_
* i++;*
* // say what you got:*
* Serial.print(incomingByte);*
* }*
* }*
OUTPUT for serial input :
abcd ----> aababcabcd
1)how can i correct this.
2)Also, how will i use the " * " key of my keyboard to print the whole data in the array at the single stroke of " * " .
OUTPUT for serial input :
abcd ----> aababcabcd
There is nothing illogical about that. You read a character, 'a', and print the string, "a". Then, you read a character, 'b', and print the string "ab". Then, you read a character, 'c', and print the string "abc". Then, you read a character, 'd', and print the string "abcd".
Use println(), instead, to prove that to yourself.
1)how can i correct this.
How is it wrong?
2)Also, how will i use the " * " key of my keyboard to print the whole data in the array at the single stroke of " * " .
Before you add the character to the array, determine what the character is. If it is not '*', add it to the array. If it is, don't. Instead, use the array at that point.
PaulS:
How is it wrong?
Hello Sir,
i actually want to display what i write,i.e. if i serially write "abcd" it should print "abcd".
And this is to be stored in array because i want this input (i.e. abcd) to be printed in one stroke of " * ".
Thanks a lot.
char incomingByte[10]; // for incoming serial data
int i=0;
void setup() {
-
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps*
}
void loop() {
-
// send data only when you receive data:*
-
if (Serial.available() > 0) {*
-
// read the incoming byte:*
_ incomingByte = Serial.read();_
* // say what you got:*
* Serial.print(incomingByte);*
* }*
* }*
[i/]
here t is.. I got solution to my first problem.
But the second question remains. How will i define * key to perform print array data at a single stroke?
@VivuStriker: You've had enough posts to know that you should use code tags when posting code to this Forum. If not, please read the two posts at the top of this Forum on how to post properly.