Go Down

Topic: Error in my code - please help (Read 527 times) previous topic - next topic

Donmerrick

Hi all

I am using a lm35dz to send temp to serial through adruino, The code I have modified from someone else gives this error.
Expected unqualified-id before ' { ' token

Code: [Select]
float tempC;
int tempPin = 0;
int led = 13;
int val = 25;

void setup()
{
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

void loop()

{
  tempC=analogRead(tempPin);
  tempC=(5.0*tempC*100.0)/1024.0;
  Serial.println((byte)tempC);
  delay(1000);
}

{
  if (val = >++);
  digitalWrite(led, HIGH);
}



Can some one please advise where I am going wrong here.
Please don't shoot me, I am just learning...

jack wp

Code: [Select]

{
  if (val = >++);
  digitalWrite(led, HIGH);
}
Good luck, Jack

Code: [Select]

{
 if (val = >++);
 digitalWrite(led, HIGH);
}


You have code here outside a function. You can't do that. The "loop" function ended a couple of lines earlier at the curly brace.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

el_supremo

What is this supposed to do?
Code: [Select]
  if (val = >++);

Pete

Oh yeah, about three things wrong with this line:

Code: [Select]

 if (val = >++);
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Donmerrick

Thanks guys, think I understand now.

Code: [Select]
{
 
  tempC=analogRead(tempPin);
  tempC=(5.0*tempC*100.0)/1024.0;
  Serial.println((byte)tempC);
  delay(1000);
  if (val > 25) digitalWrite(led, HIGH);
}
Please don't shoot me, I am just learning...

Donmerrick

Well, atleast it compiles now due to a few changes, but, still will not flash the led on pin 13

Code: [Select]
float tempC;
int tempPin = 0;
int ledPin = 13;
int val = 25;

void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop()

{
 
  tempC=analogRead(tempPin);
  tempC=(5.0*tempC*100.0)/1024.0;
  Serial.println((byte)tempC);
  delay(1000);
  if (val > 26) digitalWrite(13, HIGH);
}
Please don't shoot me, I am just learning...

Not surprised. You only ever turn the pin HIGH, but never LOW.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

UKHeliBob

In order for the LED to flash it must turn on and off.  I don't see any code to turn it off, or do you mean it never turns on ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Donmerrick

never turns on but I have tried again with this. and still no good even though it compiles.

Code: [Select]
float tempC;
int tempPin = 0;
int led = 13;
int val = 25;

void setup()
{
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

void loop()

{
 
  tempC=analogRead(tempPin);
  tempC=(5.0*tempC*100.0)/1024.0;
  Serial.println((byte)tempC);
  delay(1000);
  if (val > 26) digitalWrite(13, HIGH);
  else digitalWrite(13, LOW);
}
Please don't shoot me, I am just learning...

Donmerrick

I think I have it now.

Code: [Select]
float tempC;
int tempPin = 0;
int led = 13;
//int val = 25;

void setup()
{
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

void loop()

{
 
  tempC=analogRead(tempPin);
  tempC=(5.0*tempC*100.0)/1024.0;
  Serial.println((byte)tempC);
  delay(1000);
  if (tempC > 26) digitalWrite(13, HIGH);
  else digitalWrite(13, LOW);
}


now if i warm the sensor, the led lights.

Jesus C is hard, only been learning it for 4 hours now!!!

Thanks for your help guys.
Please don't shoot me, I am just learning...

Go Up