“数码管控制”的版本间的差异

来自Microduino Wikipedia
跳转至: 导航搜索
调试
Program
 
(未显示2个用户的4个中间版本)
第1行: 第1行:
 +
{{Language |Digital_Tube_Control}}
 
{| style="width: 800px;"
 
{| style="width: 800px;"
 
|-
 
|-
 
|
 
|
==目的==
+
==Objective==
  
本教程将教大家如何用processing来控制一个共阴极数码管。
+
The course will show you how to use Processing to control a common cathode digital tube.
  
==设备==
+
==Equipment==
*'''[[Microduino-Core]]'''
+
*'''[[Microduino-Core/zh]]'''
*'''[[Microduino-FT232R]]'''
+
*'''[[Microduino-USBTTL/zh]]'''
  
  
*其他硬件设备
+
*Other Hardware Equipment
**USB数据连接线  一根
+
**A USB cable
**共阴极数码管    一个
+
**A common cathode digital tube 
**面包板跳线      一盒
+
**A box of jumpers 
**10K欧电阻      一个
+
**A resistor of 10K Ω
  
==原理图==
+
==Schematic==
  
 
[[File:processing7SegmentSchematics.jpg|600px|center|thumb]]
 
[[File:processing7SegmentSchematics.jpg|600px|center|thumb]]
  
==程序==
+
==Program==
  
https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/ProcessingSegment
+
[https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/ProcessingSegment ProcessingSegment]
  
==调试==
+
==Debugging==
  
步骤一:按着原理图搭建硬件环境,像这样:
+
Step 1:Build the hardware environment according to the schematic, just like this:
 
[[File:processing7SegmentConnectionDiagram.jpg|600px|center|thumb]]
 
[[File:processing7SegmentConnectionDiagram.jpg|600px|center|thumb]]
  
  
步骤二:解释一下代码:
+
Step 2: Here is the code needed:
  
本例需要两端的代码,Processing端和Microduino端
+
The code the two ends(Processing and Microduino)
  
 
Microduino:
 
Microduino:
  
使用firmata的StandardFirmata程序。
+
Using Firmata's StandardFirmata program.
  
 
Processing:
 
Processing:
  
//定义8个LED用来表示一个数码管。
+
//Define eight led lights to indicate a digital tube.
 
   LED[] leds = new LED[8]; // An array of 8 led objects!
 
   LED[] leds = new LED[8]; // An array of 8 led objects!
  
//定义对应数码管引脚1,2,.......10的Microduino引脚。
+
//Define Microduino pins of the corresponding digital tube pins (1,2...10).
 
   int microduinoPins[] = {//Correspondence microduino pin for 7 segment  
 
   int microduinoPins[] = {//Correspondence microduino pin for 7 segment  
 
     11,2,4,5,6,7,9,10};
 
     11,2,4,5,6,7,9,10};
  
//定义数码管LED标签
+
//Define the name of each segment LED digital tube 
 
   String segmentLables[]={"1-e","2-d","3-c","4-dp","5-b","6-a","7-f","8-g"};
 
   String segmentLables[]={"1-e","2-d","3-c","4-dp","5-b","6-a","7-f","8-g"};
  
  
//在setup()中初始化绘制数码管的8个led
+
//Initialize and draw each led in setup().
 
   for (int i = 0; i < leds.length; i ++ ) { // Initialize each led and output pin using a for loop.
 
   for (int i = 0; i < leds.length; i ++ ) { // Initialize each led and output pin using a for loop.
 
     arduino.pinMode(microduinoPins[i], Arduino.OUTPUT);  
 
     arduino.pinMode(microduinoPins[i], Arduino.OUTPUT);  
第66行: 第67行:
 
   leds[7] = new LED(100, 300, 200,50,8);
 
   leds[7] = new LED(100, 300, 200,50,8);
  
//在draw()中绘制数码管并判断led的亮灭并把状态发送到Microduino
+
//Draw the digital tube in draw(), judge the status of the led lights, and send the current status to Microduino 
 
   for (int i = 0; i < leds.length; i ++ ) { // Run each Car using a for loop.
 
   for (int i = 0; i < leds.length; i ++ ) { // Run each Car using a for loop.
 
     leds[i].display();
 
     leds[i].display();
第81行: 第82行:
 
   }
 
   }
  
步骤三:下载代码并编译通过。
+
Step 3:Download the code and get it compiled successfully.
  
步骤四:运行后,在processing中会出现8个LED,鼠标点击每个led看数码管会有什么反应。
+
Step 4:There will appear eight led lights in Processing after the system goes smoothly. Please click each led and see the response of the digital tube.
  
==结果==
+
==Result==
  
鼠标点击后对应的数码管LED会亮起或熄灭,像这样
+
Click the mouse and the corresponding digital tube led will turn on or off, as follows:
[[File:processing7SegmentResult.jpg|600px|center|thumb]]
+
[[File:processing7SegmentResult1.jpg|600px|center|thumb]]
  
 
+
==Video==
==视频==
 
  
  
 
|}
 
|}

2014年10月29日 (三) 07:25的最新版本

Language English

Objective

The course will show you how to use Processing to control a common cathode digital tube.

Equipment


  • Other Hardware Equipment
    • A USB cable
    • A common cathode digital tube
    • A box of jumpers
    • A resistor of 10K Ω

Schematic

Processing7SegmentSchematics.jpg

Program

ProcessingSegment

Debugging

Step 1:Build the hardware environment according to the schematic, just like this:

Processing7SegmentConnectionDiagram.jpg


Step 2: Here is the code needed:

The code the two ends(Processing and Microduino)

Microduino:

Using Firmata's StandardFirmata program.

Processing:

//Define eight led lights to indicate a digital tube.

 LED[] leds = new LED[8]; // An array of 8 led objects!

//Define Microduino pins of the corresponding digital tube pins (1,2...10).

 int microduinoPins[] = {//Correspondence microduino pin for 7 segment 
   11,2,4,5,6,7,9,10};

//Define the name of each segment LED digital tube

 String segmentLables[]={"1-e","2-d","3-c","4-dp","5-b","6-a","7-f","8-g"};


//Initialize and draw each led in setup().

 for (int i = 0; i < leds.length; i ++ ) { // Initialize each led and output pin using a for loop.
   arduino.pinMode(microduinoPins[i], Arduino.OUTPUT); 
 }
 
 leds[0] = new LED(50, 350, 50,200,1);
 leds[1] = new LED(100, 550, 200,50,2);
 leds[2] = new LED(300, 350, 50,200,3);
 leds[3] = new LED(350, 550, 50,50,4);
 leds[4] = new LED(300, 100, 50,200,5);
 leds[5] = new LED(100, 50, 200,50,6);
 leds[6] = new LED(50, 100, 50,200,7);
 leds[7] = new LED(100, 300, 200,50,8);

//Draw the digital tube in draw(), judge the status of the led lights, and send the current status to Microduino

 for (int i = 0; i < leds.length; i ++ ) { // Run each Car using a for loop.
   leds[i].display();
   
   //draw segemnt lables
   text (segmentLables[i], leds[i].xpos, leds[i].ypos); 
   
   if (leds[i].button) {//switch led on/off
     arduino.digitalWrite(microduinoPins[i], Arduino.HIGH);
   }
   else {
     arduino.digitalWrite(microduinoPins[i], Arduino.LOW);
   }
 }

Step 3:Download the code and get it compiled successfully.

Step 4:There will appear eight led lights in Processing after the system goes smoothly. Please click each led and see the response of the digital tube.

Result

Click the mouse and the corresponding digital tube led will turn on or off, as follows:

Processing7SegmentResult1.jpg

Video