unsigned long startMillis=0; //some global variables available anywhere in the program
unsigned long currentMillis;
unsigned long period;
byte numbers[11][7] = {
{ 1, 0, 0, 1, 1, 1, 1 }, //E
{ 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, 0, 0 }, //7
{ 1, 1, 1, 1, 1, 1, 1 }, //8
{ 1, 1, 1, 1, 0, 1, 1 }, //9
{ 1, 0, 0, 0, 1, 1, 1 } //F
};
byte segmentPin[7] = { 0, 1, 2, 3, 4, 5, 6 };
void display_number(int num) {
for (int i = 0; i < 7; i++) digitalWrite(segmentPin[i], numbers[num][i]);
}
void startup() {
for (int i = 0; i < 6; i++) {
digitalWrite(i, HIGH);
currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started)
if (currentMillis - startMillis >= 500) //test whether the period has elapsed
{
digitalWrite(i, LOW);//if so, change the state of the LED. Uses a neat trick to change the state
startMillis = currentMillis; //IMPORTANT to save the start time of the current LED state.
}
}
}
void setup() {
for (int i = 0; i < 7; i++) {
pinMode(i, OUTPUT);
}// put your setup code here, to run once:
}
void loop() {
period=6000;
for (int i = 0; i < 2; i++) {
currentMillis = millis();
if (currentMillis - startMillis >= period) //test whether the period has elapsed
{
digitalWrite(i, !digitalRead(i));//if so, change the state of the LED. Uses a neat trick to change the state
startMillis = currentMillis; //IMPORTANT to save the start time of the current LED state.
}
}
}