Digital Tube Control

来自Microduino Wikipedia
Pkj讨论 | 贡献2014年6月13日 (五) 03:51的版本 (Created page with "{| style="width: 800px;" |- | ==Objective== The course will show you how to use Processing to control a common cathode digital tube. ==Equipment== *'''Microduino-Core''...")
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索

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

https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/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