/* SevSegShift Counter Example
Copyright 2017 Dean Reading,
Copyright 2020 Jens Breidenstein
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This example demonstrates a very simple use of the SevSeg library with a 4
digit display. It displays a counter that counts up, showing deci-seconds.
*/
#include "SevSegShift.h"
#define SHIFT_PIN_SHCP 6
#define SHIFT_PIN_STCP 7
#define SHIFT_PIN_DS 8
/* Instantiate a seven segment controller object with:
- segment pins controlled via 1 shift register and
- digit pins connected to the Arduino directly
*/
SevSegShift sevseg(
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)
*/
);
byte digitPins[] = {2, 3, 4, 5}; // These are the PINS of the ** Arduino **
byte segmentPins[] = {0, 1, 2, 3, 4, 5, 6, 7}; // these are the PINs of the ** Shift register **
float input_voltage = 0.0;
float temp=0.0;
float r1=90900.0;
float r2=10000.0;
void setup() {
Serial.begin(9600);
byte numDigits = 4;
bool resistorsOnSegments = true; // '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
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
updateWithDelays, leadingZeros, disableDecPoint);
sevseg.setBrightness(90);
}
void loop() {
int analog_value = analogRead(A0);
temp = (analog_value * 5.0) / 1024.0;
input_voltage = temp / (r2/(r1+r2));
if (input_voltage < 0.1)
{
input_voltage=0.0;
}
sevseg.setNumberF(input_voltage,1);
Serial.println(A0);
sevseg.refreshDisplay(); // Must run repeatedly
}
/// END ///