Hi Guys,
I’m new to Arduino and trying to write my second little program from scratch. I’ve run into all the expected newbie problems and have enjoyed finding the problems so far.
I’ve now been stuck for a while so seeking help please.
Im getting errors saying “ expected primary-expression before '>=' token
int GreenOnVal = >=920 && <=950; “.
I’m wondering if it’s ok to have calculations in a variable I’ve declared above void setup ?
Or is there another reason anyone can see please ?
My circuit should be measuring a voltage on analog pin A0 then lighting leds when the result falls within the value window I declared before void setup.
Many thanks
George.
Code..
int analogPin =A0; // using to measure voltage range 0-5vdc
int val =0; // result from analog read from analog pin
int GreenLED =2;
int YellowLED =3;
int RedLED =4;
int BuzzerNc =5;
int BuzzerNo =6;
int GreenOnVal = >=920 && <=950; // value window for green led to light on
int GreenOffVal = <=920 && >=950; // value window for green led to light off
int YellOnVal = <=920 && >=1020;
int YellOffVal = >=920 && <=1020;
int RedOnVal = >=1000 && <=1015;
int RedOffVal = >=1015 && <=1020;
void loop() {
val = analogRead(analogPin); // read voltage from the analog input pin
Serial.println(val); // debug value
if (val =GreenOnVal){digitalWrite (GreenLED,HIGH);}
if (val =GreenOffVal){digitalWrite (GreenLED,LOW);}
if (val =YellOnVal){digitalWrite (YellLED,HIGH);}
if (val =YellOffVal){digitalWrite (YellLED,LOW);}
if (val =RedOnVal){digitalWrite (RedLED,HIGH);}
if (val =RedOffVal){digitalWrite (RedLED,LOW);}
I’m trying to create a variable that’s a range or window of values returned by the Analog read.
Each led has its own window. I will need to change these values so thought it best to declare it before void setup.
The art of getting away with less than you know relies on pattern matching and reading code that does things like you want to do.
Your expression quoted above is very creative, and its meaning almost clear, but it is not anything you ever saw in any functioning C/C++ program… you can’t just make stuff up!
Hmmm, I think I understand what you’re saying.
I’m not just new to Arduino, I’m new to programming and venturing into it with Arduino so not familiar with he rights and wrongs yet. This is what I’m trying to learn. From what I have learnt so far, I thought I could indeed make up a name of my choice and add value after the = symbol. This is the first time I’ve tried adding a calculation here and I expected it to be incorrect. However I learn by errors and it’s not like it costs anything to hit compile or reach out to the brains on this forum.
Yes. If I didn’t learn from mistakes, I would know nothing.
That said, there is a time for experiments, there are occasions where reaching out to the heavies on these fora makes sense, but
there is never going to be a substitute for finding and following an organized course of material presenting the basics and not-so-basics of programming.
Google around, try any of the 100s of beginners tutorials on the Arduino. Maybe you want to watch a video series. Maybe you prefer reading. Maybe the young woman is easier to follow than the old man…
You should be able to tell after 5 or 10 minutes with any of them whether you like the teacher, or can at least tolerate him or her, and whether s/he is presenting things at your current ability to understand and incorporate new knowledge.
No one was born knowing any of this, and we all had to do some work along the way. As I like to say, this stuff is hard until it is easy.
And yes certainly there are always ppl here eager to help.
Thanks. I have been looking watching tutorials and reading what I can relating to Arduino. I have indeed found my favourite teacher on YouTube and that’s Paul McWhorter. As you say it’s finding someone that teaches the way you learn. I have watched most of his tutorials, some a few times. I’ve completed some very simple example programs but that’s not what I’m in it for. I need to be able to convert the messy ideas in my head to this very structured language that I’m unfamiliar with.
Apologies if I’m asking newbie questions in a big boys forum, but this is the first place a newbie like me would reach out.
Thanks. I think I can see what you have done here. It’s a lot easier to understand the (()) etc when it’s shown to you rather than trying to work out the format it wants you to write in. I will have a play, cheers.