Arduino - SevSeg 转换库问题

Arduino - SevSeg Shift Library issues

我要创建的项目是电压断路器电路;它本质上是通过使用传感器测量电路的电压,如果电压超过用户使用电位计选择的量,它将通过继电器切断电路其余部分的电源:全部由 Arduino 供电和处理。

我已经让电路与 LCD 一起工作,但是它有点笨重并且没有必要用液晶显示器来表示两位数字,所以我寻找了一个替代方案。

目的是用一个四位八段显示器和一个移位寄存器来代替它(我在 Arduino Nano 上的 GPIO 引脚中有 运行 个)但是我似乎做不到。

代码如下:

#include <SevSegShift.h>

const int SHIFT_PIN_DS  = 8; /* Data input PIN */
const int SHIFT_PIN_STCP = 7; /* Shift Register Storage PIN */
const int SHIFT_PIN_SHCP = 6; /* Shift Register Shift PIN */

//Instantiate a seven segment controller object (with Shift Register functionality)
SevSegShift sevsegshift(
                  SHIFT_PIN_DS, 
                  SHIFT_PIN_SHCP, 
                  SHIFT_PIN_STCP, 
                  1, /* number of shift registers there is only 1 Shiftregister 
                        used for all Segments (digits are on Controller)
                        default value = 2 (see SevSegShift example)
                        */
                  true /* Digits are connected to Arduino directly 
                          default value = false (see SevSegShift example)
                        */
                );

void setup() {
  byte numDigits = 4;
  byte digitPins[] = {5, 4, 3, 2}; // These are the PINS of the ** Arduino **
  byte segmentPins[] = {0, 2, 4, 6, 7, 1, 3, 5}; // these are the PINs of the ** Shift register **
  bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
  byte hardwareConfig = COMMON_CATHODE; // See README.md for options
  bool updateWithDelays = false; // Default 'false' is Recommended
  bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
  bool disableDecPoint = false; // Use 'true' if your decimal point doesn't exist or isn't connected. Then, you only need to specify 7 segmentPins[]

  SevSeg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
  
}

我不断收到的错误是:

退出状态 1 '.' 之前的预期不合格 ID代币

突出显示的行是:

SevSeg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);

有人知道这是什么意思吗?

感谢您的帮助!

这是因为你输入的变量不正确,而不是 SevSeg(来自库的class的名称),您需要输入sevsegshift,您创建的class实例的名称。

#include <SevSegShift.h>

const int SHIFT_PIN_DS  = 8; /* Data input PIN */
const int SHIFT_PIN_STCP = 7; /* Shift Register Storage PIN */
const int SHIFT_PIN_SHCP = 6; /* Shift Register Shift PIN */

//Instantiate a seven segment controller object (with Shift Register functionality)
SevSegShift sevsegshift(
                  SHIFT_PIN_DS, 
                  SHIFT_PIN_SHCP, 
                  SHIFT_PIN_STCP, 
                  1, /* number of shift registers there is only 1 Shiftregister 
                        used for all Segments (digits are on Controller)
                        default value = 2 (see SevSegShift example)
                        */
                  true /* Digits are connected to Arduino directly 
                          default value = false (see SevSegShift example)
                        */
                );

void setup() {
  byte numDigits = 4;
  byte digitPins[] = {5, 4, 3, 2}; // These are the PINS of the ** Arduino **
  byte segmentPins[] = {0, 2, 4, 6, 7, 1, 3, 5}; // these are the PINs of the ** Shift register **
  bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
  byte hardwareConfig = COMMON_CATHODE; // See README.md for options
  bool updateWithDelays = false; // Default 'false' is Recommended
  bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
  bool disableDecPoint = false; // Use 'true' if your decimal point doesn't exist or isn't connected. Then, you only need to specify 7 segmentPins[]

  sevsegshift.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
  
}

希望这能回答您的问题!