数码管SevSeg库使用
接线图:
代码-1:
//串口输入四位数码管显示
- #include "SevSeg.h"
- SevSeg sevseg;
- String inString = "";
- int val=0;
- void setup() {
- Serial.begin(9600);
- while (!Serial) {
- }
- Serial.println("串口显示四位数码管");
- Serial.println();
- sevseg.Begin(0,10,11,12,13,2,3,4,5,6,7,8,9);
- //sevseg.Begin参数(0-共阴1-共阳,共极引脚,a-g,dp引脚);
- }
- void loop() {
- while (Serial.available() > 0) {
- int inChar = Serial.read();
- if (isDigit(inChar)) {
- inString += (char)inChar;
- }
- if (inChar == '\n') {
- if(inString.length()>4){
- Serial.print("输入的字符串数不能大于四!");
- inString = "";
- }else{
- //Serial.print("Value:");
- //Serial.println(inString.toInt());
- Serial.print("String: ");
- Serial.println(inString);
- val=inString.toInt();
- inString = "";
- }
- }
- }
- sevseg.PrintOutput();
- sevseg.NewNum(val, 4);
- }
复制代码
代码-2:
//数组四位数码管显示
- #include "SevSeg.h"
- SevSeg sevseg;
- int val[10]={0000,1111,2222,3333,4444,5555,6666,7777,8888,9999};
- void setup() {
- Serial.begin(9600);
- sevseg.Begin(0,10,11,12,13,2,3,4,5,6,7,8,9);
- }
- void loop() {
- for(int i=0;i<10;i++){
- for(int j=0;j<1000;j++){
- sevseg.PrintOutput();
- sevseg.NewNum(val[i], 4);
- }
- delay(500);
- }
- }
复制代码
全部资料51hei下载地址:
SevSeg.rar
(2.88 KB, 下载次数: 64)
|