// Use an analog potentiometer as a selector switch
#include <SevSeg.h>
SevSeg sevseg; //Instantiate a seven segment controller object
// Number of switch positions and maximum analog voltage
const byte numberOfPositions = 5;
const uint16_t maxAnalog = 1023 + 1;
void setup() {
Serial.begin(115200);
const byte numDigits = 1;
const byte digitPins[] = {2};
const byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
const bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
const byte hardwareConfig = COMMON_ANODE; // See README.md for options
const bool updateWithDelays = false; // Default 'false' is Recommended
const bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
const bool disableDecPoint = true; // Use 'true' if your decimal point doesn't exist or isn't connected
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
updateWithDelays, leadingZeros, disableDecPoint);
sevseg.setBrightness(70);
}
void loop() {
byte swVal = map(analogRead(A5), 0, maxAnalog, 1, numberOfPositions + 1);
byte lastSwVal;
sevseg.setNumber(swVal, 1);
if (swVal != lastSwVal) { // update display only on value change
sevseg.refreshDisplay(); // Must run repeatedly
lastSwVal = swVal;
}
}