Blinking leds and delay problem | Arduino | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Blinking leds and delay problem
No permission to create posts
January 2, 2019
11:45 pm
Avatar
threepwood
New Member
Members
Forum Posts: 1
Member Since:
January 2, 2019
sp_UserOfflineSmall Offline

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

January 3, 2019
9:00 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 861
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

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

January 4, 2019
4:04 am
Avatar
rw950431

Top
Members
Forum Posts: 279
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

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.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
13 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:

khanhNguyen_CT, susyburr, quijano__, meosuckhoe, briskpanda, Dejw0089

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457