Ciao 访客, welcome back to old school! :p
#include <SevenSegmentDisplay.h>/* Sample codes for 7 segments display by Jack Zhong(jzopen@yeah.net) Please refer to the library header file for usage instructions in Chinese. If you ran into trouble to read those Chinese words, please open the .h files with Notepad or any other word processing application you like. Please bear in mind, DO NOT try to modify the codes unless there is a must to do so. */// Declare a variable led of cathode common type,// if it were a anode one, please imply the type// when declared in this way:// SevenSegmentDisplay led(COMMONANODE);SevenSegmentDisplay led;// Define an array to host digit pins// In this example, the display has// 4 digits, in another word, it could// display 4 digits at a timeunsigned int digitsPins[4] ={ 2, 3, 4, 5 };// Define an array to host segment pins// pins start from segmemt a to segment dp.unsigned int segPins[8] ={ 6, 7, 8, 9, 10, 11, 12, 13 };char c='1';int i=0;void setup(){ // enable Serial object if you need trace the project Serial.begin(9600); // You can pass the pins in either of two ways //led.setSegmentPins(&segPins[0]); led.setSegmentPins(&segPins[0]); led.setDigitPins(&digitsPins[0]); // call diagnoze() to check if the display work properly led.diagnoze();}void loop(){ i++; c= i/1000; if (c>6) i=0; //because my serial in mega board was out of work, //so I disable the following code. //#define GOODSERIAL#ifdef GOODSERIAL if (Serial.available()>0) c= Serial.read();#else c=c+'0';#endif Serial.println(c); switch (c) { case '0': case 'l': case 'L': // Display string, it supports left alignment, // center alignment and right alignment // the default value for display string is left one. led.display("Err"); break; case '1': case 'c': case 'C': led.display("Err", taCENTER); break; case '2': case 'r': case 'R': led.display("Err", taRIGHT); break; case '3': case 'i': case 'I': // Display integer number led.display(i/5); break; case '4': // you can decide whether add the leading zero or not led.display(i/5,true); break; case '5': case 'f': case 'F': // display float number led.display( i/10.0); break; default: //led.diagnoze(); break; }}