hi there i'm trying to make an LED blink on and off but the daley i want variable from 5min to 25min
this code seems to turn the LED on and stays on but if i reduce the numbers down from 300000 to 30000 it seems to turn the LED off after 20seconds
any ideas what going on?
int sensorPin = A0; // 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() {
// read the value from the sensor:
int sensorValue = analogRead(sensorPin);
int sensor = map(sensorValue, 0, 1023, 300000UL, 1500000UL);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensor);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensor);
}
am i on the right line?
i did noticed the LED starts LOW not HIGH?
const int ledPin = 13; // the number of the LED pin
long sensorPin = A0; // select the input pin for the potentiometer
long sensorValue = 0; // variable to store the value coming from the sensor
// Variables will change:
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
long sensorValue = analogRead(sensorPin);
long sensor = map(sensorValue, 0, 1023, 30000UL, 1500000UL);
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > sensor) {
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}