HI,
In c# you can use string to house a string, I just can's find out how to do this is the arduino code.
I now use char, but I can only house one character.
Please help!
greetings,
Luc
HI,
In c# you can use string to house a string, I just can's find out how to do this is the arduino code.
I now use char, but I can only house one character.
Please help!
greetings,
Luc
You need a char array.
ie
char areYouAPieceOfString[]={"No I'm a fraid knot"};
Don't need the braces though:
char areYouAPieceOfString[]="No I'm a fraid knot";
You can use an array of chars. Just make sure that the next character position after the text has a value of 0 to mark the end of the string (small s).
...R
Now my code does not work, my current code is:
char i;
int i_int;
void setup() {
pinMode(10, OUTPUT);
Serial.begin(9600);
delay(50);
}
void loop() {
char i[]={Serial.read()};
if(i == "1"){
digitalWrite(10, HIGH);
}
if(i == "0"){
digitalWrite(10, LOW);
}}
my sending code sends 0 and 1.
I need the longer string to do something like: led3state0
Moderator edit: nice try, but code tags corrected
Very simple code that captures a string of characters sent from the serial monitor and then evaluates the captured String for the desired LED commands.
// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later
//A very simple example of sending a string of characters
//from the serial monitor, capturing the individual
//characters into a String, then evaluating the contents
//of the String to possibly perform an action (on/off board LED).
int ledPin = 13;
String readString;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
Serial.println("serial on/off test 0021"); // so I can keep track
}
void loop() {
while (Serial.available()) {
delay(3);
char c = Serial.read();
readString += c;
}
if (readString.length() >0) {
Serial.println(readString);
if(readString.indexOf("on") >=0)
{
digitalWrite(ledPin, HIGH);
}
if(readString.indexOf("off") >=0)
{
digitalWrite(ledPin, LOW);
}
readString="";
}
}
When I wrote my earlier reply I didn't know you were trying to receive data from a serial input. Look at the Thread serial input basics
...R
char i[]={Serial.read()};
A long string, huh?
PaulS:
char i[]={Serial.read()};
A long string, huh?
:))