Go Down

Topic: serial connectivity (Read 655 times) previous topic - next topic

radexito

\hello i have a vb code and im trying to make arduino so stuff when recives "camera" or "lights"
my code:
Code: [Select]
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
Code: [Select]
error: invalid conversion from 'char' to 'char*' :'(

deSilva

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 ;-)

radexito

#2
Aug 21, 2010, 12:16 pm Last Edit: Aug 21, 2010, 12:42 pm by radexito Reason: 1
so i need to make it send 1 or 2 instead of camera or lights?
Thanks

--edit

Code: [Select]
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 ???

AWOL

Quote
if(input = 1){


This is an assignment, not a comparison and its result will always be true.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

radexito

#4
Aug 21, 2010, 01:29 pm Last Edit: Aug 21, 2010, 01:32 pm by radexito Reason: 1
i knew it ;)

i knew somthing wass smelly :P

----edit===
Code: [Select]
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

AWOL

Quote
if(input [glow]=[/glow] 3){


This is an assignment (=), not a comparison (==) and its result will always be true.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Andrew

Hint: http://arduino.cc/en/Reference/Assignment versus http://arduino.cc/en/Reference/If

Andrew

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy