和朋友们一起打球会不会经常遇到忘记分数的情况,能够专心打球而不用分心是一件多么惬意的事情,有一块属于自己场地的记分牌在吸引眼球的同时也能让朋友们更专心认真的打球。那就让我们来发扬极客精神,自己动手做一个吧!
这台“基于arduino的红外遥控比赛记分器”采用arduino UNO 、四块8*8红色点阵模块和红外遥控接收模块组成,可以通过红外线遥控器更新比赛分数和设置发球方,遥控有效距离不小于10米,可由一个随身电源供电。
硬件使用MAX7219点阵模块作为显示输出,采用级联接法,使用Max72xxPanel和Adafruit_GFX库驱动,轻松实现多种组合输出。具体接线方法在附件的代码中有描述,或请参考论坛内其它相关帖子。
此记分器经过羽毛球场地测试,性能稳定,霸气实用,获得一致好评,希望爱折腾的你能将它应用于其它运动,谢谢。 全部制作资料及源码下载:
score.rar
(83.43 KB, 下载次数: 11)
部分源码预览:
- int RECV_PIN = A0;
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- int pinCS = 10; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf [url]http://arduino.cc/en/Reference/SPI[/url] )
- int numberOfHorizontalDisplays = 4;
- int numberOfVerticalDisplays = 1;
- int pinRightPlus = 4;
- int pinRightReduce = 5;
- int pinLeftPlus = 6;
- int pinLeftReduce = 7;
- unsigned long leftPlusCode = 0xFD807F;
- unsigned long LeftReduceCode = 0xFDA05F;
- unsigned long rightPlusCode = 0xFD40BF;
- unsigned long rightReduceCode = 0xFD609F;
- unsigned long resetCode = 0xFD00FF;
- unsigned long fireChg = 0xFD20DF;
- Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
- int leftScore=0;
- int rightScore=0;
- uint8_t whoFire = 0; //0:none,1:left,2:right
- void setup() {
- pinMode(pinRightPlus, INPUT);
- pinMode(pinRightReduce, INPUT);
- pinMode(pinLeftPlus, INPUT);
- pinMode(pinLeftReduce, INPUT);
- matrix.setIntensity(1); // Use a value between 0 and 15 for brightness
- //Serial.begin(9600);
- irrecv.enableIRIn(); // Start the receiver
- }
- void checkIR()
- {
- if (irrecv.decode(&results)) {
- //Serial.println(results.value, HEX);
-
- if (results.value==leftPlusCode)
- {
- leftScore++;
- if(leftScore>99)
- {
- leftScore=99;
- }
- whoFire=1;
- }
- else if(results.value==fireChg)
- {
- //0:none,1:left,2:right
- if(whoFire==0)
- {
- whoFire=1;
- }
- else if(whoFire==1)
- {
- whoFire=2;
- }
- else if(whoFire==2)
- {
- whoFire=1;
- }
- }
- else if(results.value==LeftReduceCode )
- {
- leftScore--;
- if(leftScore<0)
- {
- leftScore=0;
- }
- }
- else if(results.value==rightPlusCode )
- {
- rightScore++;
- if(rightScore>99)
- {
- rightScore=99;
- }
- whoFire=2;
- }
- else if(results.value==rightReduceCode )
- {
- rightScore--;
- if(rightScore<0)
- {
- rightScore=0;
- }
- }
- else if(results.value==resetCode )
- {
- leftScore=0;
- rightScore=0;
- whoFire=0;
- }
- irrecv.resume(); // Receive the next value
- }
- }
- void loop() {
- checkIR();
- drawScreen();
- delay(400);
- }
- void drawScreen()
- {
- matrix.fillScreen(LOW);
- drawLeftScore();
- drawRightScore();
- drawArr();
- matrix.write(); // Send bitmap to display
- }
- void drawArr()
- {
- //0:none,1:left,2:right
- if(whoFire == 1)
- {
- matrix.drawPixel(0, 3, HIGH);
- matrix.drawLine(1, 2, 1, 4, HIGH);
- matrix.drawLine(2, 1, 2, 5, HIGH);
- }
- else if(whoFire == 2)
- {
- matrix.drawPixel(31, 3, HIGH);
- matrix.drawLine(30, 2, 30, 4, HIGH);
- matrix.drawLine(29, 1, 29, 5, HIGH);
- }
- }
- void drawLeftScore()
- {
- uint8_t score10 = leftScore/10;
- uint8_t score1 = leftScore%10;
- matrix.drawChar(4, 0,score10+48, HIGH, LOW, 1);
- matrix.drawChar(10, 0,score1+48, HIGH, LOW, 1);
- }
- void drawRightScore()
- {
- uint8_t score10 = rightScore/10;
- uint8_t score1 = rightScore%10;
- matrix.drawChar(17, 0,score10+48, HIGH, LOW, 1);
- matrix.drawChar(23, 0,score1+48, HIGH, LOW, 1);
- }
复制代码
|