Lesson 17--Microduino Button Control Digital Tube

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

Objective

This tutorial will teach you how to use the buttons to add and subtract the digital tube displayed value. There are two buttons, one is used to increase the value, another is used to decrease value.

Equipment

Microduino-Core Microduino-FT232R

  • Other hardware equipment
    • Breadboard Jumper one box
    • Breadboard one piece
    • Digital tube one
    • Buttos two
    • 220Ω (100Ω~1kΩ) one
    • USB Data cable one

Schematic

第十七课-Microduino独立按键让数码管加减原理图.jpg

Pin Table

Microduino Pin Digital Tube 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/MicroduinoDigitalSubtraction

    #include "SevSeg.h"
    SevSeg sevseg;
    int i=5;
    
    void setup() {
    //Define used pins
      sevseg.Begin(1,2,3,4,5,6,7,8,9,10,11,12,13);
      pinMode(2, INPUT);    //D2 use to add
      pinMode(3, INPUT);    //D3 use to subtract
      
      sevseg.PrintOutput();
      sevseg.NewNum(i, 4); 
      
    }
     
    void loop() {
      //Enable the output function
      sevseg.PrintOutput();

      if(digitalRead(2)==HIGH) {//If press button 2
        i++;
        sevseg.NewNum(i, 4);
        delay(200);        //Delay 50ms
      }
      else if(digitalRead(3)==HIGH) {//If press button 3
        i--;
        sevseg.NewNum(i, 4);
        delay(200);        //Delay 50ms
      }

  }

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:

第十七课-Microduino独立按键让数码管加减连接图.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:Digital displays initial value 5, then press that two buttons respectively, what will happen!!

Result

Press two buttons respectively, the value will increase one or decrease one.

Video

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