Lesson 20--Microduino Two Digital Tube Countdown Display
From Microduino Wiki
Language: | English • 中文 |
---|
ObjectiveWe have learned display the number statically, this lesson will teach you how to dispaly number dynamically. Only need change the code, no hardware change. Equipment
SchematicPin Table
Programbyte digit0 = 10; //Ten digits Microduino pin
byte digit1 = 11; //Single digit Microduino pin
byte dotPin = 2; //Decimal point pin
byte sevenSegmentPins[] = {2,3,4,5,6,7,8}; //A,B,C,D,E,F,G Microduino pin
byte sevenSegment[10][7] =
{
//a b c d e f g
{ 0,0,0,0,0,0,1 }, // = 0
{ 1,0,0,1,1,1,1 }, // = 1
{ 0,0,1,0,0,1,0 }, // = 2
{ 0,0,0,0,1,1,0 }, // = 3
{ 1,0,0,1,1,0,0 }, // = 4
{ 0,1,0,0,1,0,0 }, // = 5
{ 0,1,0,0,0,0,0 }, // = 6
{ 0,0,0,1,1,1,1 }, // = 7
{ 0,0,0,0,0,0,0 }, // = 8
{ 0,0,0,1,1,0,0 } // = 9
};
void setup()
{
//Initialize all lights up
pinMode(dotPin, OUTPUT); //pin 9
pinMode(digit0, OUTPUT); //pin 10
pinMode(digit1, OUTPUT); //pin 11
for(int i=0; i<7; i++)
{
pinMode(sevenSegmentPins[i], OUTPUT);
}
digitalWrite(dotPin, HIGH);
digitalWrite(digit0, HIGH);
digitalWrite(digit1, HIGH);
}
//Display number
void segmentWrite(byte digit)
{
byte pin = 2;
for (byte i=0; i<7; ++i)
{
digitalWrite(pin, sevenSegment[digit][i]);
++pin;
}
}
void loop()
{
for(int i=9;i>=0;i--) {// Countdown ten digits
for(int j=9;j>=0;j--) {//Countdown to single digit
unsigned long startTime = millis();
for (unsigned long elapsed=0; elapsed < 600; elapsed = millis() - startTime) {//Display 600ms
digitalWrite(digit0, LOW); //Trun on ten digits tube
segmentWrite(j); //Display single tube
delay(10); //Delay 10ms
digitalWrite(digit0, HIGH); //Turn on ten digits tube
digitalWrite(digit1, LOW); //Turn off single tube
segmentWrite(i); //Display ten digits
delay(10); //Delay 10ms
digitalWrite(digit1, HIGH); //Turn on single digit
}
}
}
} DebugStep 1:Identify the digitsl tube's Pin Step 2: Copy code to IDE and compile it Step 3: Set up circuit, as follows: Step 4: Run program Setp 5: Observe the digital tube
ResultThe number will countdown from 99 to 0, and then in circle. Video |