#include<stdlib.h>
int a=2;
int b=3;
int c=4;
int d=5;
int e=6;
int f=7;
int g=8;
int p=9;
int d4=13;
int d3=12;
int d2=11;
int d1=10;
long n=0;
int x=100;
int del=2000;
const int buttonPin1 = 1;
const int buttonPin2 = 0;
int buttonState1 = 0;
int buttonState2 = 0;
void setup()
{
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(p,OUTPUT);
pinMode(d4,OUTPUT);
pinMode(d3,OUTPUT);
pinMode(d2,OUTPUT);
pinMode(d1,OUTPUT);
pinMode(buttonPin1,INPUT);
pinMode(buttonPin2,INPUT);
}
void loop()
{
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if(buttonState1 == 0){ //复位键此处程序开始
clearLEDs();
pickDigit(1);
pickNumber((n/x/600)%10); //(n/x/600)%10
delayMicroseconds(del);
clearLEDs();
pickDigit(2);
pickNumber((n/x/60)%10); //(n/x/60)%10
delayMicroseconds(del);
clearLEDs();
pickDigit(3);
dispDec(3);
pickNumber(n/x/10%6); //n/x/10%6
delayMicroseconds(del);
clearLEDs();
pickDigit(4);
pickNumber(n/x%10); //n/x%10
delayMicroseconds(del);
n++;
}
else {
n=0;
}
if(buttonState2 == 1){ //buttonState2作暂停功能
这里应该怎么写???
}
}
void pickDigit(int x)
{
digitalWrite(d1,LOW);
digitalWrite(d2,LOW);
digitalWrite(d3,LOW);
digitalWrite(d4,LOW);
switch(x)
{
case 1:
digitalWrite(d1,HIGH);
break;
case 2:
digitalWrite(d2,HIGH);
break;
case 3:
digitalWrite(d3,HIGH);
break;
default:
digitalWrite(d4,HIGH);
break;
}
}
void pickNumber(int x)
{
switch(x)
{
default:
zero();
break;
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
case 7:
seven();
break;
case 8:
eight();
break;
case 9:
nine();
break;
}
}
void dispDec(int x)
{
digitalWrite(p,LOW);
}
void clearLEDs()
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(p,HIGH);
}
void zero()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
}
void one()
{
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
}
void two()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
}
void three()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
}
void four()
{
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
void five()
{
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
void six()
{
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
void seven()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
}
void eight()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
void nine()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
|