So, the String is one character/byte long? Really? And you need to waste (mod edit) away resources using a String to wrap, and then immediately unwrap, one character? Get real.
The String class is really a crutch in most cases...easy to use, but a horrible waste of memory. Your version of the code below uses 3622 bytes of memory.
void setup() {
Serial.begin(9600);
char copy[50];
// strcpy(copy, "Pissing away resources uselessly"); // Uncomment for string use
String aStupidWasteOfResource = "Pissing away resources uselessly"; // Comment these two out...
aStupidWasteOfResource.toCharArray(copy, 50);
Serial.println(copy);
}
void loop() {
}
Comment out the String class variable and method (note uppercase 'S') and uncomment the call to strcpy() and the code size shrinks to 2166. There are few things the String class brings to the table that you can't do with the string processing functions offered in the C string library. See:
Hola de nuevo Surbyte, gracias por tu respuesta...si funciona, pero no enciende el rele, como que no hace la comparacion del if..
#include <SoftwareSerial.h>
String cadena;
void setup()
{
Serial.begin(9600);
//Serial.setTimeout(500);
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);
}
void loop()
{
if (Serial.available() > 0) {
//Serial.println(Serial.readString());
cadena = Serial.readString();
//Serial.println("Cadena es igual a:");
Serial.println(cadena);
if (cadena == 'A') { // "A" con comillas tampoco
digitalWrite(5, LOW);
}
if (cadena == 'B') {
digitalWrite(5, HIGH);
}
}
}
la variable si tiene ahora lo que mando por monitor, pero no se porque en el if no compara o si compara no lo hace correctamente, y al final el rele no se enciende..