For my second attempt with Arduino (Blink being the first), I tried combining the AnalogInput and BlinkWithoutDelay examples to make the blink speed controlled by a potentiometer. I got it working, and I had a Serial.println(interval); in there for debugging. Once I took it out, the blinking would start at the correct interval, then would quickly speed up and go constant-on (or a very small interval). With the attached code, can anybody help me? Thanks!
#define potPin 2
#define ledPin 13
float val = 0;
float interval = 0;
long previousMillis = 0;
int value = LOW;void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}void loop() {
//280-630 : Approxamate range of my pot
val = analogRead(potPin);
interval = long((((val)-270)/360)*1000); //Change the val to an interval, approx 0-1000
Serial.println(interval); //The debug line that, when removed, causes error
if (millis() - previousMillis > interval) {
previousMillis = millis();if (value == LOW)
value = HIGH;
else
value = LOW;digitalWrite(ledPin, value);
}
}