Hello. I'm working on this code:
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
void setup() {
Serial.begin(9600);
Serial.println("<Arduino is ready>");
}
void loop() {
recvWithEndMarker();
showNewData();
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData() {
String num = String(receivedChars);
long numeretto = num.toInt;
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
newData = false;
}
}
What I want is to get a number in the Serial monitor and turn on and off a led N times (n = monitor input).
The monitor can only send chars, that I save into received chars. In the showNewData function I tried to convert it to a string and then to an int, but I get this error:
cannot convert 'String::toInt' from type 'long int (String::)() const' to type 'long int'
What do I have to do? Thanks