#include <SevSeg.h>
#include <timeObj.h>
#include <mechButton.h>
// Click the button to start a timing sequence. This'll give you 3 seconds
// to get ready. Then, the LED comes on, and you have to click the button
// again as fast as possible to stop the timing.
//
// You will need to, using library manager in the IDE, install LC_baseTools
// to compile this.
#define LED_PIN 11
SevSeg sevseg;
timeObj startTimer(3000,false);
timeObj timer(50,false);
mechButton startStopBtn(10);
int dispNumber = 0;
bool timing;
bool dec;
void setup() {
byte digitPins[] = {};
byte segmentPins[] = {6, 5, 2, 3, 4, 7, 8, 9};
bool resistorsOnSegments = true;
byte hardwareConfig = COMMON_CATHODE;
sevseg.begin(hardwareConfig, 1, digitPins, segmentPins, true);
sevseg.setBrightness(100);
pinMode(LED_PIN, OUTPUT);
startStopBtn.setCallback(btnClk); // Hook the button to it's callback function.
timing = false; // And no, we are not timing now.
}
// Called whenever one wants to start timing someone.
void startTiming(void) {
dispNumber = 0; // clear out the display number.
dec = false; // Not showing a decimal point to begin with.
timing = true; // We are timing.
timer.start(); // Start the timer for the count up.
digitalWrite(LED_PIN,HIGH); // Turn on the LED to tell the user she's being timed.
}
// Called when the user pushes the button when being timed.
void stopTiming(void) {
timing = false; // Stop the timing calls.
digitalWrite(LED_PIN,LOW); // Shut off the LED.
}
// Button has changed state, lets check it out!
void btnClk(void) {
if (!startStopBtn.getState()) { // If it's been grounded..
if (timing) { // If we are currently timing someone.
stopTiming(); // Stop timing them.
} else { // Else we are NOT timimng anyone?
startTimer.start(); // Start up the starting timer.
}
}
}
void loop() {
idle(); // Runs the magic behind the scenes.
if (timing) { // If we're timing the user..
if (timer.ding()) { // If our digit timer has expired..
dispNumber++; // Bump up the display number.
if (dispNumber == 20) { // If we reach 20..
dispNumber = 0; // We'll reset to zero.
} //
if (dec) { // If we're showing the decimal.
sevseg.setNumber(dispNumber/2); // We write the new value without.
} else { // else..
sevseg.setNumber(dispNumber/2,0); // We write it with the decimal.
} //
dec = !dec; // Flip the decimal.
sevseg.refreshDisplay(); // Show the result.
timer.stepTime(); // Reset timer with no accumulated error.
} //
} else { // Else we are NOT timing someone..
if (startTimer.ding()) { // If the starting timer has expired. (Means it's been activated!)
startTimer.reset(); // Shut down the starting timer.
startTiming(); // Start timing the user.
}
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
sevseg1:COM.1
sevseg1:COM.2
sevseg1:A
sevseg1:B
sevseg1:C
sevseg1:D
sevseg1:E
sevseg1:F
sevseg1:G
sevseg1:DP
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
led1:A
led1:C