I'm new with arduino
I've made a button which controls two leds.
I want one led to stay on for three seconds and the other one for 10 seconds.
I want to avoid delay because I don't want my entire program to stop
dijkie350:
I looked at the example with the blinking led and at the millis() in te reference.
so far I didn't manage to get this in my sketch.
Well as I said before....
JimboZA:
What have you tried so far: what worked, what didn't?
.... what code have you tried? Post it here, and explain what it's (not) doing. Also post a schematic of your circuit: we need to see how the button is connected.
I just used this simple button sketch, only with a led added.
everything is working fine so far.
now I have to keep te leds on.
one for three seconds and the other for fifteen for example
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;
const int belPin = 12;
const int rgbPin = 11;
int buttonState = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(belPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(rgbPin, OUTPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(belPin, HIGH);
digitalWrite(rgbPin, HIGH);
}
else {
// turn LED off:
digitalWrite(belPin, LOW);
digitalWrite(rgbPin, LOW);
}
}