Hey everybody! I'm new to programming and fairly new to electronics, but I'm learning quick!
I took a trip to local Barnes and Noble today and picked up a book called, Arduino Cookbook, by Michael Margolis. It's a thick book and is full of excellent information for setting up and programming your Arduino.
While reading I came across this code:
// blink an LED the number of times givein in the count parameter
void blink2(int count)
{
while(count > 0) //repeat until count is no longer greather than zero
{
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);
count = count -1; //decrement count}
}
That gives me a compiler error (no surprise to me)
core.a(main.cpp.o): In function main': C:\Users\Steve\Desktop\arduino-0022\arduino-0022\hardware\arduino\cores\arduino/main.cpp:7: undefined reference to setup'
C:\Users\Steve\Desktop\arduino-0022\arduino-0022\hardware\arduino\cores\arduino/main.cpp:10: undefined reference to `loop'
So I started to tinker with the code, and I got to work... But then I wanted to do a "count up" and "count down",
So I changed the code so that when the count is going in one direction the LED blinks faster and then slower when going in the other direction. This bit of code does that...
int zero = 0;
int five = 5;void setup(){
pinMode(13, OUTPUT);
}void loop(){
while(zero < five)
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(300);
zero = zero +1;
}
while(five = five)
{
digitalWrite(13, HIGH);
delay(1500);
digitalWrite(13, LOW);
delay(150);
five = five -1;
}
}
However, I want the count to go from it's minimum of zero to five, then back down to zero at a different LED flashing speed, then back up to five at it's faster speed, then back to zero, just a continual loop of zero to five at one flashing speed, five to zero at a slower flashing speed, then back up, then back down, etc.
Since I am new to all of this I am not even sure if my above code is efficient or even correct. It gives me the result of going up, then back down, but then it stops all together, as in it won't keep looping as I would want/expect. I tried all different sorts of control structures but no luck.
What is the proper way to do this? I am just doing this to test and learn, I have no end use for it. My actual goal is to setup an environmental control system using the Arduino to act as a thermostat, control timing for 5 devices, and a CO2 controller through use of a CO2meter.com sensor. It's for my Uncles greenhouse, since he is often away he wants to be able to do data logging and web-interface and so I am working on the basic control system first and then later I can figure out the web-interface and data logging.
Any help is very much appreciated it. I'm not sure why, but when I tried to do a forum copy on that second bit of code, it just came up with a ton of java errors in the IDE and wouldn't let me copy it that way.
P.S. I'm also not looking for "answers", rather I want to learn how be proficient in programming so that I can build and expand on my design(s) as I learn.