|
| 1 | +/* |
| 2 | + Second Counter |
| 3 | +
|
| 4 | + This sketch will count seconds since the last reset on a seven segment display. |
| 5 | +
|
| 6 | + The circuit: |
| 7 | + - Display pin A -> Arduino digital pin 5 |
| 8 | + - Display pin B -> Arduino digital pin 6 |
| 9 | + - Display pin C -> Arduino digital pin 7 |
| 10 | + - Display pin D -> Arduino digital pin 8 |
| 11 | + - Display pin E -> Arduino digital pin 9 |
| 12 | + - Display pin F -> Arduino digital pin 10 |
| 13 | + - Display pin G -> Arduino digital pin 11 |
| 14 | + - Display pin DP -> Arduino digital pin 12 |
| 15 | + - Display Digit pin 1 -> Arduino pin 1 |
| 16 | + - Display Digit pin 2 -> Arduino pin 2 (if you don't have two digits, just leave pin 2 unused) |
| 17 | + - Display Digit pin 3 -> Arduino pin 3 (if you don't have three digits, just leave pin 3 unused) |
| 18 | + - Display Digit pin 4 -> Arduino pin 4 (if you don't have four digits, just leave pin 4 unused) |
| 19 | +
|
| 20 | + created 10/12/2025 |
| 21 | + by Nyjah |
| 22 | +
|
| 23 | + This example sketch is in the public domain. |
| 24 | +*/ |
| 25 | + |
| 26 | +#include <AutoPlex7.h> |
| 27 | + |
| 28 | +// Set up display |
| 29 | +int displayType = COMMON_ANODE; // Change to "COMMON_CATHODE" if using a common cathode display |
| 30 | +int D1 = 1; |
| 31 | +int D2 = 2; |
| 32 | +int D3 = 3; |
| 33 | +int D4 = 4; |
| 34 | +int A = 5; |
| 35 | +int B = 6; |
| 36 | +int C = 7; |
| 37 | +int D = 8; |
| 38 | +int E = 9; |
| 39 | +int F = 10; |
| 40 | +int G = 11; |
| 41 | +int DP = 12; |
| 42 | + |
| 43 | +// Create counter variables |
| 44 | +unsigned long previousMillis = 0; |
| 45 | +const long interval = 1000; |
| 46 | +long seconds = 0; |
| 47 | + |
| 48 | +void setup() { |
| 49 | +display.begin(); // Initialize the display |
| 50 | +display.testDisplay(); // Run test to ensure functionality |
| 51 | +delay(1000); // Wait one second |
| 52 | +display.clearDisplay(); // Clears the display |
| 53 | +} |
| 54 | + |
| 55 | +void loop() { |
| 56 | +unsigned long currentMillis = millis(); // Get the current time |
| 57 | + |
| 58 | + if (currentMillis - previousMillis >= interval) { |
| 59 | + // Save the last time you updated the counter |
| 60 | + previousMillis = currentMillis; |
| 61 | + |
| 62 | + seconds++; // Increment the seconds counter |
| 63 | + |
| 64 | + display.showNumber(seconds); // Show the number of seconds on the screen |
| 65 | + } |
| 66 | +} |
0 commit comments