Pages: [1]   Go Down
Author Topic: serial connectivity  (Read 569 times)
0 Members and 1 Guest are viewing this topic.
wellington
Offline Offline
Newbie
*
Karma: 0
Posts: 14
FTW!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Edison Member
*
Karma: 0
Posts: 1103
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

wellington
Offline Offline
Newbie
*
Karma: 0
Posts: 14
FTW!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

so i need to make it send 1 or 2 instead of camera or lights?
Thanks

--edit

Code:
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 ???
« Last Edit: August 21, 2010, 05:42:28 am by radexito » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26621
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if(input = 1){

This is an assignment, not a comparison and its result will always be true.
Logged

"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.

wellington
Offline Offline
Newbie
*
Karma: 0
Posts: 14
FTW!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i knew it smiley-wink

i knew somthing wass smelly smiley-razz

----edit===
Code:
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
« Last Edit: August 21, 2010, 06:32:51 am by radexito » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26621
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

This is an assignment (=), not a comparison (==) and its result will always be true.
Logged

"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.

UK
Offline Offline
Sr. Member
****
Karma: 1
Posts: 491
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Andrew
Logged

Pages: [1]   Go Up
Jump to: