Created
January 9, 2022 02:28
-
-
Save slashinfty/5c1d78d0fd8be34548a958477e66f1ba to your computer and use it in GitHub Desktop.
Simple dual counter
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
#include <TM1637.h> | |
// pins | |
int leftPin = 2; | |
int rightPin = 5; | |
int resetPin = 8; | |
// display | |
int clk = 11; | |
int dio = 12; | |
TM1637 TM(clk, dio); | |
// vars | |
int leftCount = 0; | |
int rightCount = 0; | |
int resetCount = 0; | |
void setup() { | |
TM.init(); | |
TM.set(2); | |
TM.clearDisplay(); | |
TM.point(1); | |
for(int i = 0; i < 4; i++) { | |
TM.display(i, 0); | |
} | |
pinMode(leftPin, INPUT); | |
pinMode(rightPin, INPUT); | |
pinMode(resetPin, INPUT); | |
} | |
void loop() { | |
int first = 0; | |
int second = 0; | |
if (digitalRead(leftPin) == HIGH && leftCount < 99) { | |
resetCount = 0; | |
leftCount = leftCount + 1; | |
first = leftCount / 10; | |
second = leftCount % 10; | |
TM.display(0, first); | |
TM.display(1, second); | |
delay(400); | |
} else if (digitalRead(rightPin) == HIGH && rightCount < 99) { | |
resetCount = 0; | |
rightCount = rightCount + 1; | |
first = rightCount / 10; | |
second = rightCount % 10; | |
TM.display(2, first); | |
TM.display(3, second); | |
delay(400); | |
} else if (digitalRead(resetPin) == HIGH) { | |
resetCount = resetCount + 1; | |
if (resetCount == 3) { | |
leftCount = 0; | |
rightCount = 0; | |
resetCount = 0; | |
for(int i = 0; i < 4; i++) { | |
TM.display(i, 0); | |
} | |
} | |
delay(400); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment