Lesson 18--Microduino 4-way Responder

来自Microduino Wikipedia
跳转至: 导航搜索
Language English

Objective

This tutorial will teach you to do a four-way responder using 5 buttons based on Microduino. Four buttons are marked with the number 1 ~ 4 respectively, press the four buttons at the same time, digital tube will display the button number of the first press. The fifth button uses to reset.

Equipment

  • Microduino-Core
  • Microduino-FT232R
  • Other hardware equipment
    • Breadboard Jumper one box
    • Breadboard one piece
    • Button one
    • Digital tube one
    • 10kΩ resistor five
    • 220Ω resistor one
    • USB Data cable one

Schematic

第十八课-Microduino4路抢答器原理图.jpg


Pin Table

Microduino Pin Digitl Pin
D10 1
D9 2
D5 3
D8 4
D13 5
D7 6
D6 7
Not used 8
D11 9
D12 10

Program

Download program: https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Advanced/Microduino4Responder

#include "SevSeg.h"
SevSeg sevseg;

void setup() {
  //Define used pins
  sevseg.Begin(1,2,3,4,5,6,7,8,9,10,11,12,13);
  pinMode(1, INPUT);    //Pin 1 for button 1
  pinMode(2, INPUT);    //Pin 2 for button 2
  pinMode(3, INPUT);    //Pin 3 for button 3
  pinMode(4, INPUT);    //Pin 4 for button 4

  sevseg.PrintOutput();
  sevseg.NewNum(0, 4); // initial value is 0

}

void loop() {
  //Enable output function
  sevseg.PrintOutput();

  //Reads the four button pin in cycle
  for(int i=1; i<=4; i++) {
    if(digitalRead(i)==HIGH) {//Press a button
      while(1) {//Display the button number
        sevseg.PrintOutput();
        sevseg.NewNum(i, 4);
      }
    }
  }
}

Debug

Fristly download the library, uncompress it and put to libraries folder of Arduino IDE, then restart Arduino IDE to load library.

Library link:https://docs.google.com/file/d/0Bwrp4uluZCpNN1Q4dmFZX1MzWVE/edit

This library can drive 4bits digital tube and support number, decimal point and easy to use.

Step 1:Copy the code to IDE and compile it

Step 2:Set up circuit, as follows:

第十八课-Microduino4路抢答器连接图.jpg

There are two buttons and use the same connection. One end connects to power and on the other end, a signal line and GND in parallel.

Step 3:Run program

Step 4: At beginning, the digital will display 0, press four buttons at the same time, the digital will display the button number of the fisrt pressed.

Result

Digital will display the button number of the first pressed. The most right side is the reset button.

Video

http://v.youku.com/v_show/id_XNjgwMzY0MzU2.html