-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d72df2
commit a4572fb
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* 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 | ||
|
||
void setup() { | ||
byte numDigits = 4; | ||
byte digitPins[] = {2, 3, 4, 5}; | ||
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13}; | ||
bool resistorsOnSegments = false; // '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); | ||
} | ||
|
||
void loop() { | ||
static unsigned long timer = millis(); | ||
static int deciSeconds = 0; | ||
|
||
if (millis() - timer >= 100) { | ||
timer += 100; | ||
deciSeconds++; // 100 milliSeconds is equal to 1 deciSecond | ||
|
||
if (deciSeconds == 10000) { // Reset to 0 after counting for 1000 seconds. | ||
deciSeconds=0; | ||
} | ||
sevseg.setNumber(deciSeconds, 1); | ||
} | ||
|
||
sevseg.refreshDisplay(); // Must run repeatedly | ||
} | ||
|
||
/// END /// |