Please help!! Multiple errors on 'simple' code!!

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:

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

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

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.

'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').

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.

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.

'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').

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!!

Did you fix this too?

if ('input' = 'on'){

Need == for a comparison test

CrossRoads:
Did you fix this too?

if ('input' = 'on'){

Need == for a comparison test

No, didn't fix this, but i have now!