I got it to work like it should, and then I started tweaking things. What I'm trying to accomplish is a 4-position software switch for my LED with OFF, LOW, MEDIUM, and HIGH.
int sensorPin = 0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
int thresholdone = 250;
int thresholdtwo = 500;
int thresholdthree = 750;
{ if(analogRead(sensorPin) < thresholdone);
{analogWrite(ledPin, 0);}}
{ if(analogRead(sensorPin) >= thresholdone; analogRead(sensorPin) < thresholdtwo);
{analogWrite(ledPin, 25);}}
{ if(analogRead(sensorPin) >= thresholdtwo; analogRead(sensorPin) < thresholdthree);
{analogWrite(ledPin, 100);}}
{ if(analogRead(sensorPin) >= thresholdthree);
{analogWrite(ledPin, 256);}}
}
Several changes later, I got the following error messages upon compile:
Twist_A_Potentiometer.cpp: In function 'void loop()':
Twist_A_Potentiometer:46: error: expected )' before ';' token Twist_A_Potentiometer:46: error: expected ;' before ')' token
Twist_A_Potentiometer:49: error: expected )' before ';' token Twist_A_Potentiometer:49: error: expected ;' before ')' token
FWIW, the extra spaces don't seem to make any difference in the other projects, so I use them for neatness. Without the curly braces around each whole "if" phrase I get more errors relating to them. What's my syntax problem?
The function call analogRead returns a value between 0 and 1023. Suppose for a moment that the sensor being read was relatively stable. Both calls to analogRead would return the same value. Suppose that the value was 450. Your statement would resolve to:
Now, look closely at the conditional part of the if statement. What is 450 >= thresholdone; 450 < thresholdtwo supposed to mean? If you want to have two (or more) conditionals, you need an operator between them, such as && (and) or || (or).
When you decide what the statement is supposed to do, and use the appropriate operator between the conditionals (not and implement TeslaFans ideas, too. you code should compile.
This is what I love about user forums. People that know what they're doing! Thanks for the help. And yes, I'm a screaming newbie, but I've got a big family and a full time job, so this is what I do for me-time.
So, I replaced some of the errant semicolons with &&, and changed 256 to 255, and moved the LED from pin 13 to pin 9, and it compiled, yay! It's doing something now, just not quite what I expected. I hooked up the piezo from the kit to the LED to give me a little more feedback on what it was doing. I'm getting different levels of light/noise, but something's funny. It's like the 0-1-2-3 settings are out of order. Flaky pot, perhaps? I'll check it with my meter shortly.
So far, I've got my LED "lamp" working with Lo, Med, and Hi. What I can't seem to get it to do is turn OFF! I've played with all the variables. All that does is change where in the pot sweep it transitions. I'm puzzled. :~ http://www.oomlout.com/a/products/ardx/circ-08/