11:45 pm

January 2, 2019

Hi guys,
my first post here. I am kinda new to the arduino world. I am playing around with leds and buttons.
I have setup my circuit with 4 leds and 3 buttons.
4 leds are placed in a square pattern, one per corner.
1 button is to make the left ones blink
1 button is to make the right ones blink
1 button is to make the rear ones light up still.
In the event one side is blinking and the rear ones are triggered still I specified that the blinking side keeps blinking and the other side stays lit.
Here's part of the code (to simplify):
[code]
int blinkleftPin = 7;
int blinkrightPin = 8;
int stillPin = 9;
int rrPin = 10;
int rlPin = 11;
int frPin = 12;
int flPin = 13;
int blinkleftState = 0;
int blinkrightState = 0;
int stillState = 0;
void setup() {
pinMode(flPin, OUTPUT);
pinMode(frPin, OUTPUT);
pinMode(rlPin, OUTPUT);
pinMode(rrPin, OUTPUT);
pinMode(blinkleftPin, INPUT);
pinMode(blinkrightPin, INPUT);
pinMode(stillPin, INPUT);
}
void loop() {
blinkleftState = digitalRead(blinkleftPin);
blinkrightState = digitalRead(blinkrightPin);
stillState = digitalRead(stillPin);
if ((blinkleftState == LOW) && (blinkrightState == LOW) && (stillState == LOW)) {
digitalWrite(flPin, LOW);
digitalWrite(frPin, LOW);
digitalWrite(rlPin, LOW);
digitalWrite(rrPin, LOW);
}
if ((blinkleftState == LOW) && (blinkrightState == LOW) && (stillState == HIGH)) {
digitalWrite(flPin, LOW);
digitalWrite(frPin, LOW);
digitalWrite(rlPin, HIGH);
digitalWrite(rrPin, HIGH);
}
if ((blinkleftState == HIGH) && (blinkrightState == LOW) && (stillState == LOW)) {
digitalWrite(flPin, HIGH);
digitalWrite(frPin, LOW);
digitalWrite(rlPin, HIGH);
digitalWrite(rrPin, LOW);
delay(1000);
digitalWrite(flPin, LOW);
digitalWrite(frPin, LOW);
digitalWrite(rlPin, LOW);
digitalWrite(rrPin, LOW);
delay(1000);
}
if ((blinkleftState == HIGH) && (blinkrightState == LOW) && (stillState == HIGH)) {
digitalWrite(flPin, HIGH);
digitalWrite(frPin, LOW);
digitalWrite(rlPin, HIGH);
digitalWrite(rrPin, HIGH);
delay(1000);
digitalWrite(flPin, LOW);
digitalWrite(frPin, LOW);
digitalWrite(rlPin, LOW);
digitalWrite(rrPin, HIGH);
delay(1000);
}
}
[/code]
My problem is that when the leds are blinking i have a whole 2000ms cycle during which it i push the STILL button nothing changes.
I can't have a direct fast response, the program of course waits for the end of the cycle.
How can i get around this problem and have an immediate button?
I read about using millis but i'm not familiar with it.
Can anybody try to put me on the right path?
Thanks
9:00 am


Moderators
March 7, 2017

You might have more luck getting help about LEDs and digital I/O on the Arduino forum. https://forum.arduino.cc/
4:04 am


Top
January 29, 2014

In fact the "Doing several things at once" post at https://forum.arduino.cc/index.php?topic=223286.0 contains all you need to know.
Most Users Ever Online: 166
Currently Online:
35 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
rw950431: 272
Vinod: 240
piajola: 95
turgo: 70
vespapierre: 63
Adarsh_Murthy: 62
Member Stats:
Guest Posters: 1
Members: 8665
Moderators: 1
Admins: 2
Forum Stats:
Groups: 3
Forums: 14
Topics: 1600
Posts: 5760
Newest Members:
Advantagetreeexperts, laundrydaddyuk, techhhelp5, ken, tran, huldacormierModerators: cstapels: 460
Administrators: Hans: 405, lee: 457