Pages: [1]   Go Down
Author Topic: Error in my code - please help  (Read 480 times)
0 Members and 1 Guest are viewing this topic.
Dorset. UK
Offline Offline
Newbie
*
Karma: 1
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Please don't shoot me, I am just learning...

Texas
Offline Offline
Edison Member
*
Karma: 25
Posts: 1298
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Good luck, Jack

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19335
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
{
  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.
Logged

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Edison Member
*
Karma: 50
Posts: 1699
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pete
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19335
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh yeah, about three things wrong with this line:

Code:
 if (val = >++);
Logged

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Dorset. UK
Offline Offline
Newbie
*
Karma: 1
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys, think I understand now.

Code:
{
 
  tempC=analogRead(tempPin);
  tempC=(5.0*tempC*100.0)/1024.0;
  Serial.println((byte)tempC);
  delay(1000);
  if (val > 25) digitalWrite(led, HIGH);
}
Logged

Please don't shoot me, I am just learning...

Dorset. UK
Offline Offline
Newbie
*
Karma: 1
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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);
}
Logged

Please don't shoot me, I am just learning...

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19335
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not surprised. You only ever turn the pin HIGH, but never LOW.
Logged

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

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4398
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Dorset. UK
Offline Offline
Newbie
*
Karma: 1
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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);
}
Logged

Please don't shoot me, I am just learning...

Dorset. UK
Offline Offline
Newbie
*
Karma: 1
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think I have it now.

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

Please don't shoot me, I am just learning...

Pages: [1]   Go Up
Jump to: