Pages: [1]   Go Down
Author Topic: Please help!! Multiple errors on 'simple' code!!  (Read 316 times)
0 Members and 1 Guest are viewing this topic.
England
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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
Logged

Code Add Aurduino Times Gaming Equals BOSS

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: March 19, 2013, 03:38:30 pm by Arrch » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 179
Posts: 8067
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
'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:
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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

England
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
'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:
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!!
Logged

Code Add Aurduino Times Gaming Equals BOSS

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23718
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you fix this too?

if ('input' = 'on'){

Need == for a comparison test
Logged

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.

England
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you fix this too?

if ('input' = 'on'){

Need == for a comparison test
No, didn't fix this, but i have now!
Logged

Code Add Aurduino Times Gaming Equals BOSS

Pages: [1]   Go Up
Jump to: