|
需要共阴显像管
显像管的左上led接2,上led接3,右上4,中5,左下6,下7,右下8,点9
代码:
[mw_shl_code=c,true]int max_z = 9;
int min_z = 2;
int show(int num = 8,boolean point = false) {
// Serial.println(num);
if(num == 0){
int pin[] = {2,3,4,6,7,8};
out (pin,sizeof(pin)/sizeof(int));
}
if(num == 1){
int pin[] = {4,8};
out (pin,sizeof(pin)/sizeof(int));
}
if(num == 2){
int pin[] = {3,4,5,6,7};
out (pin,sizeof(pin)/sizeof(int));
}
if(num == 3){
int pin[] = {3,4,5,7,8};
out (pin,sizeof(pin)/sizeof(int));
}
if(num == 4){
int pin[] = {2,4,5,8};
out (pin,sizeof(pin)/sizeof(int));
}
if(num == 5){
int pin[] = {2,3,5,7,8};
out (pin,sizeof(pin)/sizeof(int));
}
if(num == 6){
int pin[] = {2,3,5,6,7,8};
out (pin,sizeof(pin)/sizeof(int));
}
if(num == 7){
int pin[] = {3,4,8};
out (pin,sizeof(pin)/sizeof(int));
}
if(num == 8){
int pin[] = {2,3,4,5,6,7,8};
out (pin,sizeof(pin)/sizeof(int));
}
if(num == 9){
int pin[] = {2,3,4,5,7,8};
out (pin,sizeof(pin)/sizeof(int));
}
if(num == -1 && point){
int pin[] = {9};
out (pin,sizeof(pin)/sizeof(int));
}
if((num > 9 || num < 0) && !point){
return 1;
}else if(point){
digitalWrite(9,HIGH);
}
return 0;
}
void out(int op[],int len){
for(int i=min_z;i<=max_z;i++){
digitalWrite(i,LOW);
}
for(int i=0;i<len;i++){
digitalWrite(op,HIGH);
// Serial.println(op);
//Serial.println(len);
}
}
void setup() {
//Serial.begin(9600);
//while (!Serial) ;
for(int i=min_z;i<=max_z;i++){
pinMode(i, OUTPUT);
}
show(0);
delay(1000);
show(1);
delay(1000);
show(2);
delay(1000);
show(3);
delay(1000);
show(4);
delay(1000);
show(5);
delay(1000);
show(6);
delay(1000);
show(7);
delay(1000);
show(8);
delay(1000);
show(9);
delay(1000);
show(-1,true);
delay(1000);
}
void loop() {
}
[/mw_shl_code]
|
|