- int a = 12;// LED1接digital_12
- int b = 10;// LED2接digital_10
- int c = 8;// LED3接digital_8
- int d = 6;// LED4接digital_6
- int e = 4;// LED5接digital_4
- int f = 2;// LED6接digital_2
- int g = 0;// LED7接digital_0
- int h = 1;// LED8接digital_1
- int j = 13;// LED9接digital_13
- int k = 19;// LED10接analog_A5 (模拟口A0-A5相当于数据口digital14-digial19)
- int m = 18;// LED11接analog_A4
- int n = 17;// LED12接analog_A3
- int p = 16;// LED13接analog_A2
- int q = 15;// LED14接analog_A1
- int r = 14;// LED15接analog_A0
- //震动开关触发后,延迟时间的调整,采用触发后300+50=350毫秒以保持同步
- int delayTime1=300;
- //采用矩阵输出字符图形,每个字符高15个点
- byte bars[15] = {a,b,c,d,e,f,g,h,j,k,m,n,p,q,r};
- /***************************字模数组******************************/
- byte youth_digits[28][15] = { //---显示‘少年’的数组
- {0,0,0,0,0,0,0,1,1,0,0,0,0,0,1 },//少
- {0,0,0,0,0,0,1,1,0,0,0,0,0,0,1 },
- {0,0,0,0,1,1,1,0,0,0,0,0,0,0,1 },
- {0,0,0,0,1,0,0,0,0,0,0,0,0,1,1 },
- {0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
- {0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
- {1,1,1,1,1,1,1,1,1,1,0,0,1,1,0 },
- {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 },
- {0,0,0,1,0,0,0,0,0,0,0,1,0,0,0 },
- {0,0,0,0,1,0,0,0,0,0,1,1,0,0,0 },
- {0,0,0,0,1,1,0,0,0,1,1,0,0,0,0 },
- {0,0,0,0,0,1,1,0,0,1,0,0,0,0,0 },
- {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0 },
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
- {0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 },//年
- {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0 },
- {0,0,1,1,1,0,1,1,1,1,1,0,0,0,0 },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- {1,0,0,1,0,0,1,0,0,0,0,0,0,0,0 },
- {1,0,1,0,0,0,1,0,0,0,0,0,0,0,0 },
- {1,1,1,0,0,0,1,0,0,0,0,0,0,0,0 },
- {1,1,0,0,0,0,1,0,0,0,0,0,0,0,0 },
- {1,1,0,0,0,0,1,0,0,0,0,0,0,0,0 },
- {1,0,0,0,0,0,1,0,0,0,0,0,0,0,0 },
- {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0 }, };
- byte gao_digits[15][15] = { //--- 显示‘高’的数组
- {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0 },
- {0,1,0,0,0,0,0,0,0,1,1,1,1,1,1 },
- {0,1,0,0,0,0,0,0,1,0,0,0,0,0,0 },
- {0,1,0,1,1,1,1,0,1,0,0,0,0,0,0 },
- {0,1,0,1,0,0,1,0,1,0,1,1,1,0,0 },
- {0,1,0,1,0,0,1,0,1,0,1,0,1,0,0 },
- {0,1,0,1,0,0,1,0,1,0,1,0,1,0,0 },
- {1,1,0,1,0,0,1,0,1,0,1,0,1,0,0 },
- {0,1,0,1,0,0,1,0,1,0,1,0,1,0,0 },
- {0,1,0,1,0,0,1,0,1,0,1,0,1,0,0 },
- {0,1,0,1,0,0,1,0,1,0,1,1,1,0,0 },
- {0,1,0,1,1,1,1,0,1,0,0,0,0,0,0 },
- {0,1,0,0,0,0,0,0,1,0,0,0,0,0,1 },
- {0,1,0,0,0,0,0,0,0,1,1,1,1,1,1 },
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },};
- byte shou_digits[14][15] = { //--- 显示‘手’的数组
- {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0 },
- {0,1,0,0,0,0,0,0,1,0,0,0,0,0,0 },
- {0,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
- {0,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
- {0,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
- {0,1,0,0,0,1,0,0,1,0,0,0,0,0,1 },
- {0,1,0,0,0,1,0,0,1,0,0,0,0,0,1 },
- {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
- {0,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
- {0,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
- {1,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
- {1,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
- {1,0,0,0,0,1,0,0,1,0,0,0,0,0,0 },
- {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0 },};
- /***************************初始化函数******************************/
- void setup()//设置输出口
- {
- for (int i = 0; i < 3; i++)
- {
- pinMode(i, OUTPUT); //设置D0到D2引脚为输出状态
- digitalWrite(i,LOW);//初始设置,所有的LED灭
- }
- pinMode(3, INPUT); //设置D3引脚为输入状态,为震动开关的数字输入
- digitalWrite(3,HIGH);//初始设置内置上拉电阻:20-50k
- for (int i = 4; i < 20; i++)
- {
- pinMode(i, OUTPUT); //设置D4到D19引脚为输出状态
- digitalWrite(i,LOW);//初始设置,所有的LED灭
- }
- }
- /***************子函数(显示“少年电子高手”)字样函数******************/
- void youth() //---------------- 点亮‘少年’字样
- {
- for (int j=0;j<28;j++)
- {
- //第一重循环,横扫‘少年’两个字的列,每个字14列
- for (int i = 0; i < 15; i++)
- {
- //第二重循环,竖扫15次,逐个给一列当中的每一个点赋值
- //对应数组依次点亮每个灯来显示少年字样
- digitalWrite(bars[i],youth_digits[j][i] );
- }
- delay(3);//这个延迟时间很重要,关系到摇动的快慢以及字的宽度
- }
- for (int kk = 0; kk <20; kk++)
- {
- digitalWrite(kk,LOW);//所有灯熄灭
- }
- }
- void electronic()//------------ 点亮‘电子’字样
- {
- for (int j=0;j<26;j++){
- //第一重循环,横扫‘电子’两个字的列,共26列
- for (int i = 0; i < 15; i++)
- {
- //第二重循环,竖扫15次,逐个给一列当中的每一个点赋值
- //对应数组依次点亮每个灯来显示电子字样
- digitalWrite(bars[i],dianzi_digits[j][i] );
- }
- delay(3); //这个延迟时间很重要,关系到摇动的快慢以及字的宽度
- }
- for (int kk = 0; kk <20; kk++)
- {
- digitalWrite(kk,LOW); //所有灯熄灭
- }
- }
- void gaoshou()//--------------- 点亮‘高手’字样
- {
- for (int j=0;j<15;j++)
- { // 点亮‘高’
- for (int i = 0; i < 15; i++)
- {
- digitalWrite(bars[i],gao_digits[j][i] );
- }
- delay(3);
- }
- for (int kk = 0; kk <20; kk++)
- {
- digitalWrite(kk,LOW);
- }
- for (int j=0;j<14;j++)// 点亮‘手’,与上面的高组成词:高手
- {
- for (int i = 0; i < 15; i++)
- {
- digitalWrite(bars[i],shou_digits[j][i] );
- }
- delay(3);
- }
- for (int kk = 0; kk <20; kk++)
- {
- digitalWrite(kk,LOW);
- }
- }
- /***************************主函数******************************/
- void loop()
- {
- while(1)//采用震动开关触发,等待手摇棒触发
- {
- if (digitalRead(3)==0)
- {
- delay(50); //延时,防抖动
- //当手摇使得震动开关闭合,在D3口读震动开关数据,低电平则跳出死循环
- if (digitalRead(3)==0)
- break;
- }
- }
- delay(delayTime1); //触发后延时,基本上做到了同步
- youth(); //显示‘少年’字样
- digitalWrite(3,HIGH);//把D3口写高,等待下一次手摇触发
- //*******************************************************************
- while(1) //采用震动开关触发,等待手摇棒触发
- {
- if (digitalRead(3)==0)
- {
- delay(50);
- //当手摇使得震动开关闭合,在D3口读震动开关数据,低电平则跳出死循环
- if (digitalRead(3)==0)
- break;
- }
- }
- delay(delayTime1); //触发后延时,基本上做到了同步
- electronic(); //显示‘电子’字样
- digitalWrite(3,HIGH); //把D3口写高,等待下一次手摇触发
- //*******************************************************************
- while(1) //采用震动开关触发,等待手摇棒触发
- {
- if (digitalRead(3)==0)
- {
- delay(50);
- //当手摇使得震动开关闭合,在D3口读震动开关数据,低电平则跳出死循环
- if (digitalRead(3)==0)
- break;
- }
- }
- delay(delayTime1); //触发后延时,基本上做到了同步
- gaoshou(); //显示‘高手’字样
- digitalWrite(3,HIGH); //把D3口写高,等待下一次手摇触发
- }
复制代码