Go Down

Topic: Please help!! Multiple errors on 'simple' code!! (Read 408 times) previous topic - next topic

biggles2206

Code: [Select]
void setup() {
int ledPin = 13;
pinMode (ledPin , OUTPUT);
boolean input = 'off';
Serial.begin(9600);
}

void loop() {
 if (Serial.available()){
 'input' = Serial.read();
 }  
 
 if ('input' = 'on'){
   
  digitalWrite('ledPin' , HIGH);
  delay(500);
 digitalWrite('ledPin' , LOW);
   
 }
 
}


I get the following errors:

Quote
LED_CONTROL.ino: In function 'void loop()':
LED_CONTROL:10: error: lvalue required as left operand of assignment
LED_CONTROL:13: error: lvalue required as left operand of assignment

Please help!
Thanks in advanced
- Thomas
Code Add Aurduino Times Gaming Equals BOSS

Arrch

#1
Mar 19, 2013, 09:35 pm Last Edit: Mar 19, 2013, 09:38 pm by Arrch Reason: 1
Get rid of all those single quotes and take a look at some of the serial communication examples.

ledPin also needs to be declared in the global scope if you want to access it from both setup and loop

johnwasser

You are getting a bunch of errors because you are making things up as you go along.  Look at the many example sketches to see what a sketch should look like.

Code: [Select]
'input' = Serial.read();

Don't quote variable names.  It turns them into character constants.  You can't assign a new value to a character constant (which is why it is called a 'constant').

Code: [Select]
boolean input = 'off';

This will set the variable named "input" to the value 1.  If you want the value 0, use 0 or something equivalent, like false.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

biggles2206


You are getting a bunch of errors because you are making things up as you go along.  Look at the many example sketches to see what a sketch should look like.

Code: [Select]
'input' = Serial.read();

Don't quote variable names.  It turns them into character constants.  You can't assign a new value to a character constant (which is why it is called a 'constant').

Code: [Select]
boolean input = 'off';

This will set the variable named "input" to the value 1.  If you want the value 0, use 0 or something equivalent, like false.


All Fixed! Thanks!!
Code Add Aurduino Times Gaming Equals BOSS

CrossRoads

Did you fix this too?

if ('input' = 'on'){

Need == for a comparison test
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

biggles2206


Did you fix this too?

if ('input' = 'on'){

Need == for a comparison test

No, didn't fix this, but i have now!
Code Add Aurduino Times Gaming Equals BOSS

Go Up