system
August 21, 2010, 9:58am
#1
\hello i have a vb code and im trying to make arduino so stuff when recives "camera" or "lights"
my code:
char input;
void setup(){
Serial.begin(9600);
pinMode(2, OUTPUT);
}
void loop(){
if (Serial.available() > 0) {
input = Serial.read();
if(input = "camera"){
digitalWrite(2, HIGH);
delay(50)
digitalWrite(2, LOW);
}
}
}
gives
error: invalid conversion from 'char' to 'char*'
:'(
system
August 21, 2010, 10:10am
#2
Serial.read() reads one byte only.
Note that something like
xx == "string"
is not a C concept. C ist not very much aware of strings and you have to do all string handling in the non-BASIC way ;-)
system
August 21, 2010, 10:16am
#3
so i need to make it send 1 or 2 instead of camera or lights?
Thanks
--edit
int input;
void setup(){
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}
void loop(){
if (Serial.available() > 0) {
input = Serial.read();
if(input = 1){
digitalWrite(2, HIGH);
delay(50);
digitalWrite(2, LOW);
}
if(input = 2){
digitalWrite(3, HIGH);
delay(50);
digitalWrite(3, LOW);
}
}
}
no matter what i send to arduino it blinks both ???
system
August 21, 2010, 10:47am
#4
if(input = 1){
This is an assignment, not a comparison and its result will always be true.
system
August 21, 2010, 11:29am
#5
i knew it ;)
i knew somthing wass smelly :P
----edit===
void loop(){
if (Serial.available() > 0) {
input = Serial.read();
if(input = 3){
digitalWrite(2, HIGH);
delay(50);
digitalWrite(2, LOW);
}
if(input = 2){
digitalWrite(3, HIGH);
delay(50);
digitalWrite(3, LOW);
}
}
}
still doesnt work triggers all of them :S
system
August 21, 2010, 11:50am
#6
if(input = 3){
This is an assignment (=), not a comparison (==) and its result will always be true.