|
本帖最后由 Daedalus 于 2014-5-26 11:09 编辑
有谁无聊的帮我看下程序呗
#include "LedControl.h"
LedControl lc=LedControl(12,11,10,1);
//第一个参数:pin 12 连接 DIN
//第二个参数:pin 11 连接 CLK
//第三个参数:pin 10 连接 CS
//第四个参数:有一个MX7219
int num = 0;
int val = 0;
int old_val = 0;
int stat = 0;
void setup() {
lc.shutdown(0,false);
lc.setIntensity(0,8); //设置LED 亮度
lc.clearDisplay(0); //清除屏幕显示
pinMode(9,INPUT);
}
void xianshia() {
lc.setRow(0,1,B00111100); //显示数字0
lc.setRow(0,2,B00100100);
lc.setRow(0,3,B00100100);
lc.setRow(0,4,B00100100);
lc.setRow(0,5,B00100100);
lc.setRow(0,6,B00100100);
lc.setRow(0,7,B00111100);
}
void xianshib(){ //显示数字1
lc.setRow(0,1,B00000100);
lc.setRow(0,2,B00000100);
lc.setRow(0,3,B00000100);
lc.setRow(0,4,B00000100);
lc.setRow(0,5,B00000100);
lc.setRow(0,6,B00000100);
lc.setRow(0,7,B00000100);
}
void xianshic(){//显示数字2
lc.setRow(0,1,B00111100);
lc.setRow(0,2,B00000100);
lc.setRow(0,3,B00000100);
lc.setRow(0,4,B00111100);
lc.setRow(0,5,B00100000);
lc.setRow(0,6,B00100000);
lc.setRow(0,7,B00111100);
}
void xianshid(){
//显示数字3
lc.setRow(0,1,B00111100);
lc.setRow(0,2,B00000100);
lc.setRow(0,3,B00000100);
lc.setRow(0,4,B00111100);
lc.setRow(0,5,B00000100);
lc.setRow(0,6,B00000100);
lc.setRow(0,7,B00111100);
}
void xianshie(){ //显示数字4
lc.setRow(0,1,B00100100);
lc.setRow(0,2,B00100100);
lc.setRow(0,3,B00100100);
lc.setRow(0,4,B00111100);
lc.setRow(0,5,B00000100);
lc.setRow(0,6,B00000100);
lc.setRow(0,7,B00000100);
}
void xianshif(){ //显示数字5
lc.setRow(0,1,B00111100);
lc.setRow(0,2,B00100000);
lc.setRow(0,3,B00100000);
lc.setRow(0,4,B00111100);
lc.setRow(0,5,B00000100);
lc.setRow(0,6,B00000100);
lc.setRow(0,7,B00111100);
}
void xianshig(){ //显示数字6
lc.setRow(0,1,B00111100);
lc.setRow(0,2,B00100000);
lc.setRow(0,3,B00100000);
lc.setRow(0,4,B00111100);
lc.setRow(0,5,B00100100);
lc.setRow(0,6,B00100100);
lc.setRow(0,7,B00111100);
}
void xianshih(){ //显示数字7
lc.setRow(0,1,B00111100);
lc.setRow(0,2,B00000100);
lc.setRow(0,3,B00000100);
lc.setRow(0,4,B00000100);
lc.setRow(0,5,B00000100);
lc.setRow(0,6,B00000100);
lc.setRow(0,7,B00000100);
}
void xianshii(){
lc.setRow(0,1,B00111100);//显示数字8
lc.setRow(0,2,B00100100);
lc.setRow(0,3,B00100100);
lc.setRow(0,4,B00111100);
lc.setRow(0,5,B00100100);
lc.setRow(0,6,B00100100);
lc.setRow(0,7,B00111100);
}
void xianshij(){
lc.setRow(0,1,B00111100);//显示数字9
lc.setRow(0,2,B00100100);
lc.setRow(0,3,B00100100);
lc.setRow(0,4,B00111100);
lc.setRow(0,5,B00000100);
lc.setRow(0,6,B00000100);
lc.setRow(0,7,B00111100);
}
void loop() {
val = digitalRead(9);
if (val == HIGH && old_val == LOW){ //判断按钮由抬起到按下则说明按钮是按下了
stat = 1 - stat;
delay(20);
}
old_val = val; //把当前值赋给old_val,以备下一个循环使用
if (stat == 1) { //判断按钮按已经按下
stat = 1 - stat;
num = num + 1;
}
if (num==10){
num = 0; }
if (num == 0){
xianshia();}
if (num == 1){
xianshib();}
if (num == 2){
xianshic();}
if (num == 3){
xianshid();}
if (num == 4){
xianshie(); }
if (num == 5){
xianshif();}
if (num == 6){
xianshig();}
if (num == 7){
xianshih();}
if (num == 8){
xianshii(); }
if (num == 9){
xianshij(); }
}
本来想做的事按下一下按钮,数字变一下,结果怎么成了数字自己一直跳,按下按钮不放就停下来了啊。 谁帮我看下这是怎么回事?
|
|