I am using an arduino mega 2560 and 2 seven segment displays, i'm trying to get the displays to count down in 3 chunks from 20-0 seconds then 5-0 seconds and 30-0 seconds then repeat to go along with a traffic light controller. I have gotten it to count from 9-0 so far however both 7-segment displays count together 9-0 instead of being able to get the 10's place counter to count only every 10 seconds. Any help or suggestions would be welcomed.
// ---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
unsigned long currentMillis = 0;
const long interval = 1000;
int count = 9;
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 sevenSegWrite0(byte digit) { // creates 7-segment variable
byte pin = 22;
// start from pin 22 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 loop() {
currentMillis = millis();
if(currentMillis - previousMillis >= interval) { /
/ if currentMillis - previousMillis is greater than or equal to interval of 1000
previousMillis = currentMillis;
sevenSegWrite1(count);
sevenSegWrite0(count);
count--;
if(count<0) count = 9;
}
}
seven_segement_for_traffic_light.ino (3.22 KB)