Obscure
Obscure

Reputation: 45

Arduino - SevSeg Shift Library issues

The project I am trying to create is a voltage breaker circuit; it essentially measures the voltage of a circuit by using a sensor and if it is over the user-selected amount using a potentiometer, via a relay it will cut the power to rest of a circuit: all powered and processed by an Arduino.

I have got the circuit working with an LCD however it is a bit clunky and unnecessary to have an lcd for representing the two digits so I looked for an alternative.

The aim is to replace it with a four digit eight segment display combined with a shift register(I have ran out of GPIO pins on the Arduino Nano)however I can't seem to do it.

Here is the code:

#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);
  
}

The error I keep getting is:

exit status 1 expected unqualified-id before '.' token

And the line highlighted is:

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

Does anyone know what this might mean?

Thanks for the help!

Upvotes: 0

Views: 445

Answers (1)

James Barnett
James Barnett

Reputation: 571

The reason that this is, is because you have typed the variable incorrectly, rather than SevSeg (the name of the class from the library), you need to type sevsegshift, the name of the instance of the class you created.

#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);
  
}

Hope this answered your question!

Upvotes: 1

Related Questions