抢答器

超级无敌强大的抢答器


基于Arduino 2560

在经过好几天的修改,讨论,商议,最终版的抢答器终于完成了(软硬件都完成了)

抢答器的详细介绍

  • 器材:Arduino 2560*1,按钮*8,LED模块*3,蜂鸣器*3,舵机*3,LCD1602*1
  • 流程:三位选手抢答,抢答成功者会亮起他的LED和蜂鸣器,LCD显示屏会显示5s的倒计时,然后裁判选择给分/惩罚,完成后在LCD显示该选手的分值以及三位选手的分数之比.以此为一个循环.

  • 代码如下(具体引脚代码里面应该都能看懂)

 #include "TM1637.h"
#define CLK 6   //四位数码管  //pins definitions for TM1637 and can be changed to other ports       
#define DIO 7    //四位数码管
#include <SoftwareSerial.h>
 #include <Servo.h> 
Servo myservo1;  //创建一个舵机控制对象
Servo myservo2;
Servo myservo3;


#define txPin 5

SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin
const int LCDdelay=10;  // conservative, 2 actually works

// wbp: goto with row & column
void lcdPosition(int row, int col) {
  LCD.write(0xFE);   //command flag
  LCD.write((col + row*64 + 128));    //position 
  delay(LCDdelay);
}
void clearLCD(){
  LCD.write(0xFE);   //command flag
  LCD.write(0x01);   //clear command.
  delay(LCDdelay);
}
void backlightOn() {  //s on the backlight
  LCD.write(0x7C);   //command flag for backlight stuff
  LCD.write(157);    //ght level.
  delay(LCDdelay);
}
void backlightOff(){  //s off the backlight
  LCD.write(0x7C);   //command flag for backlight stuff
  LCD.write(128);     //ght level for off.
   delay(LCDdelay);
}
void serCommand(){   //a general function to call the command flag for issuing all other commands   
  LCD.write(0xFE);
}

TM1637 tm1637(CLK,DIO);



int pinmod1=2; //led接口11 12 10
int pinmod2=3;
int pinmod3=4; 
int button1=A1;//led按钮接口 1 2 3
int button2=A2;
int button3=A3;
int b1=0;   //led按钮
int b2=0;
int kx=0;
int b3=0;
int button5=A5; //加分按钮接口5678
int b5=0;
int button6=A6;
int b6=0;
int button7=A7;
int b7=0;
int button8=A8;
int b8=0;
int a=0;  //四位数码管
int b=0;   //四位数码管
int c=0;   //四位数码管
int d=0;   //四位数码管
int k1=0;
int b4=0;
int button4=A4; //chengfa
int k2=0;
int k3=0;
void setup(){
  pinMode(txPin, OUTPUT);
  LCD.begin(9600);
  backlightOn() ;
  clearLCD();
  lcdPosition(0,0);
     Serial.begin(9600);
     pinMode(button1,INPUT);
      pinMode(button2,INPUT);
      pinMode(button3,INPUT);
       pinMode(button4,INPUT);
     pinMode(button5,INPUT);
     pinMode(button6,INPUT);
     pinMode(button7,INPUT);
     pinMode(pinmod1,OUTPUT);
     pinMode(pinmod2,OUTPUT);
     pinMode(pinmod3,OUTPUT);
     pinMode(button5,INPUT);
     pinMode(button6,INPUT);
     pinMode(button7,INPUT);
       pinMode(button8,INPUT);
     myservo1.attach(8);
     myservo2.attach(9);
     myservo3.attach(10);
     tm1637.init();
     tm1637.set(BRIGHT_DARKEST );      //BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
  myservo1.write(90);         // 指定舵机转向的角度 
    delay(0);
    myservo2.write(90);         // 指定舵机转向的角度 
    delay(0);
    myservo3.write(90);         // 指定舵机转向的角度 
    delay(0);
}

void loop(){
myservo1.write(90);         // 指定舵机转向的角度 
    delay(0);
  b1=analogRead(button1);
  if(b1>1000){
     for(int i=0;i<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值