I am trying to implement mills() into my program in place of delay so that I can add in part of my program which is a traffic light. This is the counter which will be counting down to the light changing. I understand what the millis() function is, however i've been having difficulties trying to figure out how to properly use it in a program. Any help would be appreciated bellow is my code. Also i'm trying to figure out how to get both displays working together where the one will act as the ten's changing every 10 seconds and the other will function as the ones counting every second. This is my first project and it has been a difficult learning experience but a learning experience none the less
// ---A---
// | |
// F B
// | |
// ---G---
// | |
// E C
// | |
// ---D---
//
// A = pin 22 & 47
// B = pin 23 & 48
// C = pin 24 & 49
// D = pin 25 & 50
// E = pin 26 & 51
// F = pin 27 & 52
// G = pin 28 & 53
byte seven_seg_digits[10][7] = { { 1,1,1,1,1,1,0 }, // = 0
{ 0,1,1,0,0,0,0 }, // = 1
{ 1,1,0,1,1,0,1 }, // = 2
{ 1,1,1,1,0,0,1 }, // = 3
{ 0,1,1,0,0,1,1 }, // = 4
{ 1,0,1,1,0,1,1 }, // = 5
{ 1,0,1,1,1,1,1 }, // = 6
{ 1,1,1,0,0,1,0 }, // = 7
{ 1,1,1,1,1,1,1 }, // = 8
{ 1,1,1,1,0,1,1 } // = 9
};
unsigned long previousMillis = 0; // sets previousMillis to 0
const long interval = 1000; // sets interval to 1000 or 1 second
void setup() {
// Tens Seven Segment Display
pinMode(22, OUTPUT); // A
pinMode(23, OUTPUT); // B
pinMode(24, OUTPUT); // C
pinMode(25, OUTPUT); // D
pinMode(26, OUTPUT); // E
pinMode(27, OUTPUT); // F
pinMode(28, OUTPUT); // G
// Ones Seven Segment Display
pinMode(47, OUTPUT); // A
pinMode(48, OUTPUT); // B
pinMode(49, OUTPUT); // C
pinMode(50, OUTPUT); // D
pinMode(51, OUTPUT); // E
pinMode(52, OUTPUT); // F
pinMode(53, OUTPUT); // G
}
void sevenSegWrite1(byte digit) { // creates 7-segment variable
byte pin = 47; // start from pin 47 for the ones 7-segment
for (byte segCount = 0; segCount < 7; ++segCount) { // set count to 0, count <7, +count
digitalWrite(pin, seven_seg_digits[digit][segCount]); // display on defined pin, the digit in the array based on position of count then move to next pin
++pin;
}
}
void pause(long interval) { // attempt at defining variable millis instead of having to use delay
previousMillis = millis(); // previousMillis is millis
if(millis() - previousMillis < 1000){ // if millis - previousMillis is less than 1000
}
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) { // if currentMillis - previousMillis is greater than or equal to interval of 1000
previousMillis = currentMillis; // previousMillis = currentMillis increasing currentMillis to keep up with millis
for(byte count = 10; count > 0; --count) { // Counts down from 9 to 0
delay(1000); // Pauses every second to count down
sevenSegWrite1(count - 1); // Displays the current number in the sequence on the 7-segment display
}
}
}