-
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
Troels L Strand
committed
Jul 18, 2019
0 parents
commit 85c064d
Showing
3 changed files
with
118 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,5 @@ | ||
{ | ||
"sketch": "FallingTarget.ino", | ||
"board": "arduino:avr:leonardo", | ||
"port": "/dev/ttyACM0" | ||
} |
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,20 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Linux", | ||
"includePath": [ | ||
"/home/troels/Arduino/libraries/TM1637-1.2.0", | ||
"/opt/arduino-1.8.9/tools/**", | ||
"/opt/arduino-1.8.9/hardware/arduino/avr/**" | ||
], | ||
"forcedInclude": [ | ||
"/opt/arduino-1.8.9/hardware/arduino/avr/cores/arduino/Arduino.h" | ||
], | ||
"intelliSenseMode": "gcc-x64", | ||
"compilerPath": "/usr/bin/gcc", | ||
"cStandard": "c11", | ||
"cppStandard": "c++17" | ||
} | ||
], | ||
"version": 4 | ||
} |
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,93 @@ | ||
#include <TM1637Display.h> | ||
|
||
int button[] = {4, 5}; | ||
// int button[] = {5 ,6, 7, 8}; | ||
|
||
int buttonSize = sizeof(button) / sizeof(int); | ||
|
||
unsigned long startTime; | ||
unsigned long stopTime; | ||
unsigned long currentTime; | ||
|
||
#define CLK 2 | ||
#define DIO 3 | ||
|
||
void displayTime(long time, TM1637Display display, bool show100 = false, bool alwaysColon = false) | ||
{ | ||
uint8_t digit1 = time / 100000 ? display.encodeDigit((time / 100000) % 10) : 0x0; | ||
uint8_t digit2 = time / 10000 ? display.encodeDigit((time / 10000) % 10) : 0x0; | ||
uint8_t digit3 = time / 1000 ? display.encodeDigit((time / 1000) % 10) : 0x0; | ||
uint8_t digit4 = time / 100 ? display.encodeDigit(time / 100 % 10) : 0x0; | ||
|
||
if (time < 9999) | ||
{ | ||
digit1 = time / 1000 ? display.encodeDigit((time / 1000) % 10) : digit1; | ||
if ((time / 100)) | ||
{ | ||
digit2 = display.encodeDigit((time / 100) % 10); | ||
// Colon every half because it looks better. | ||
digit2 = (((time / 10) % 10) >= 5 || alwaysColon) ? 0x80 | digit2 : digit2; | ||
} | ||
|
||
digit3 = display.encodeDigit((time / 10) % 10); | ||
digit4 = show100 ? display.encodeDigit(time % 10) : 0x0; | ||
} | ||
// We won't show number of more than 9999 seconds. | ||
if (time > 999999) | ||
{ | ||
digit1 = digit2 = digit3 = digit4 = 0b01000000; | ||
} | ||
|
||
int8_t data[] = {digit1, digit2, digit3, digit4}; | ||
display.setSegments(data); | ||
} | ||
|
||
TM1637Display display(CLK, DIO); | ||
|
||
void setup() | ||
{ | ||
Serial.begin(9600); | ||
startTime = millis(); | ||
display.setBrightness(3); | ||
|
||
// Set the trigger pins. | ||
for (int i = 0; i < buttonSize; i++) | ||
{ | ||
pinMode(button[i], INPUT_PULLUP); | ||
} | ||
} | ||
|
||
int programmerPin = 8; | ||
int programmerPinPresses = 0; | ||
|
||
void loop() | ||
{ | ||
currentTime = millis(); | ||
int pressed = 0; | ||
for (int i = 0; i < buttonSize; i++) | ||
{ | ||
pressed += digitalRead(button[i]) == LOW; | ||
} | ||
if (!stopTime && pressed == buttonSize) | ||
{ | ||
stopTime = millis(); | ||
} | ||
if (stopTime) | ||
{ | ||
displayTime((stopTime - startTime) / 10, display, true, true); | ||
} | ||
else if (startTime) | ||
{ | ||
displayTime((millis() - startTime) / 10, display); | ||
} | ||
if (!startTime && pressed > 0) | ||
{ | ||
startTime = millis(); | ||
} | ||
// Reset the number when all buttons are released. | ||
if (pressed == 0) | ||
{ | ||
startTime = stopTime = NULL; | ||
displayTime(0, display); | ||
} | ||
} |