Try
char var[100];
Arrays may need constant size at compile time. I see you have missed the ';' at the end of that line.
Question
I got the following Arduino code for receiving text from Bluetooth and display it back to a LCD display.
When Enter is inputted detectarClase()
should be called with IP String as argument.
This is the .ino
code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <string.h>
LiquidCrystal_I2C lcd(0x20,16,2);
boolean borrar = false;
String IP;
String detectarClase(String ip) {
char var[ip.length()]
ip.toCharArray(var, ip.length());
int num= atoi(var);
if (num < 127 )
return "Clase A";
if (num == 127 )
return "Direccion reservada";
if (num > 127 && num < 192 )
return "Clase B";
if (num >= 192 && num < 224 )
return "Clase C";
if (num >= 224 && num < 240 )
return "Clase D";
if (num >= 240 && num < 255 )
return "Clase E";
}
void setup()
{
lcd.init();
lcd.backlight();
pinMode(13,OUTPUT);
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
while (Serial1.available()) {
char caracter = Serial1.read(); //Comprobamos el caracter
switch(caracter) {
default:
if (borrar) {
IP = "";
lcd.clear();
}
lcd.print(caracter);
delay(125);
borrar = false;
IP.concat(caracter);
break;
case '\r':
case 0x0F:
case 0x0A:
borrar = true;
lcd.print(detectarClase(IP));
break;
} //fin switch
}//serial disponible
}//fin programa
When I try to compile I get the following output:
BluetoothLCD.cpp: In function ‘String detectarClase(String)’: BluetoothLCD.cpp:17:3: error: expected initializer before ‘ip’ BluetoothLCD.cpp:19:25: error: ‘var’ was not declared in this scope
I really can't see how I should declare the function, how can I amend this?
La solution
Try
char var[100];
Arrays may need constant size at compile time. I see you have missed the ';' at the end of that line.