Hi I am brand new to coding and using micontrollers. I have a nano and am trying to make a hit counter that displays to a 4 digit 7 segment display.
Im using the SevSeg library to control the display and im trying to get it to display the counter number.
My problem is it is only showing a single digit either the first digit or the last digit but never the full one. It will sometimes show the full digit but only for a brief second then it disappears and only shows the one or none at all.
Here is my attempted code so far.
* SevSeg Counter Example
Copyright 2020 Dean Reading
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 "SevSeg.h"
SevSeg sevseg; //Instantiate a seven segment controller object
const int knockSensor = A7;
const int threshold = 1000;
int sensorReading = 0;
int counter = 0;
void setup() {
byte numDigits = 4;
byte digitPins[] = {10,11,12,13};
byte segmentPins[] = {9,2,3,5,6,8,7,4};
bool resistorsOnSegments = true; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_ANODE; // 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);
Serial.begin(9600);
}
void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(knockSensor);
if (sensorReading>=threshold){
counter== counter++;
Serial.println(counter);
if (counter==100)
counter=0;
sevseg.setNumber(counter);
sevseg.refreshDisplay();
}
}
/// END ///
I am completely new to all of this so any help would be greatly appreciated. However don't be rude please, the world is crappy enough don't add to it cause you want to stroke your ego.