Difference between revisions of "Lesson 17--Microduino Button Control Digital Tube"

From Microduino Wiki
Jump to: navigation, search
(Created page with "{{Language | 第十七课--Microduino 独立按键让数码管加减}} {| style="width: 800px;" |- | ==Objective== This tutorial will teach you how to use the buttons to add ...")
 
 
(One intermediate revision by one other user not shown)
Line 14: Line 14:
 
**Breadboard                one piece   
 
**Breadboard                one piece   
 
**Digital tube                one
 
**Digital tube                one
**Buttos                       two
+
**Buttons                       two
 
**220Ω (100Ω~1kΩ)              one  
 
**220Ω (100Ω~1kΩ)              one  
 
**USB Data cable              one
 
**USB Data cable              one
Line 48: Line 48:
  
 
==Program==
 
==Program==
 +
Download program:
 +
https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Advanced/MicroduinoDigitalSubtraction
 +
 
<source lang="cpp">
 
<source lang="cpp">
  
Line 86: Line 89:
  
 
==Debug==
 
==Debug==
Fristly download the library, uncompress it and put to libraries folder of Arduino IDE, then restart Arduino IDE to load library.
+
Firstly download the library, unzip 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
+
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.
 
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 1: Copy the code to IDE and compile it
  
Step 2:Set up circuit, as follows:
+
Step 2: Set up circuit, as follows:
  
 
[[File:第十七课-Microduino独立按键让数码管加减连接图.jpg|600px|center|thumb]]
 
[[File:第十七课-Microduino独立按键让数码管加减连接图.jpg|600px|center|thumb]]
 
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.
 
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 3: Run program
  
Step 4:Digital displays initial value 5, then press that two buttons respectively, what will happen!!
+
Step 4: Digital displays initial value 5, then press that two buttons respectively, what will happen!!
  
 
==Result==
 
==Result==

Latest revision as of 08:19, 12 September 2016

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
    • Buttons 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

Firstly download the library, unzip 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