Hi. My arduino is able to read text sent from a webpage that uses form. The arduino receives a 4 number char type variable and I want to transmit this over to 3 other arduinos ( this has been done but im just explaining). However, I need each arduino to extract their own character. For example:
Arduino A reads the first character out of the 4.
Arduino B reads the second character out of the 4.
Arduino C reads the third character out of the 4.
Is there any existing codes that can allows the arduino to extract SPECIFIC characters from their POSITIONS?
Please note that the 4 numbers character type variable are NOT constant. It ranges from 0000~9999.
@AWOL I'm sorry I didn't know I made a duplicate I thought my internet has problem because I refreshed and it doesnt come out so i thought my post was voided and made another. sorry
UKHeliBob:
If the 4 characters are in an array of chars then you can reference each of them using the array index
char aNumber[] = {"5678"};
void setup()
{
Serial.begin(115200);
for (int x = 0; x < 4; x++)
{
Serial.println(aNumber[x]);
}
}
void loop(){}
@UKHelibob Erm.. If my code doesn't show the characters then how should i write? It reprints it like this
if (GetText(txt_buf, TXT_BUF_SZ)) {
Serial.println("\r\nReceived Text:");
Serial.println(txt_buf);
the txt_buf is the one that contains the 4 characters..
@UKHeliBob My arduino program cannot be compiled when I do this.
if (GetText(txt_buf, TXT_BUF_SZ)) {
Serial.println("\r\nReceived Text:");
Serial.println(txt_buf);
Serial.println(txt_buf[1]);
It displays an error msg "error: invalid conversion from 'char*' to 'char' [-fpermissive]".
Please help me and sorry for bothering you so much!!
Oh!! I fixed it. But I cannot see what it displays at the moment because I dont have the webshield with me. Can I get back to you on what it displays a few days later? I am so sorry but please help me
so this line "char aNumber[] = {txt_buf};" was causing the error and all i had to do was removed it. I can't see the outcome of the code but it has no problems compiling! I will test it in a few days and will get back to you ok?? thanks for helping me up till now I really appreciate it!! thank you so much
Simple code example of a string of characters captured in a String, and parsed based on position in the String.
//send string using serial monitor
String readString, data1, data2, data3;
void setup() {
Serial.begin(9600);
Serial.println("parse-test-3"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
delay(2);
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
}
}
if (readString.length() >0) {
Serial.println(readString); //see what was received
// expect a string like 123456789 with three data partts
data1 = readString.substring(0, 3); //get the first three characters
data2 = readString.substring(3, 6); //get the next three characters
data3 = readString.substring(6, 9); //get the next three characters
Serial.println(data1); //print to serial monitor to see results
Serial.println(data2);
Serial.println(data3);
readString="";
data1="";
data2="";
data3="";
}
}