4 digit 7 segment Counter - In depth and Easy Tutorial

  Рет қаралды 1,167

Waiduino

Waiduino

Күн бұрын

Пікірлер: 5
@Waiduino
@Waiduino 6 ай бұрын
#include "SevSeg.h" SevSeg sevseg; // Initiate a seven-segment controller object int score = 0; int buttonState = 0; int lastButtonState = 1; // Initial state when the button is not pressed const int button = A0; // Button pin unsigned long lastDebounceTime = 0; // the last time the output pin was toggled unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers void setup() { Serial.begin(9600); byte numDigits = 4; byte digitPins[] = {2, 3, 4, 5}; byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13}; bool resistorsOnSegments = false; // If resistors are on segment pins, set this to true sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins, resistorsOnSegments); sevseg.setBrightness(90); pinMode(button, INPUT_PULLUP); // Configure the button pin as input with internal pull-up resistor } void loop() { int reading = digitalRead(button); // Read the state of the button // Check if the button state has changed if (reading != lastButtonState) { lastDebounceTime = millis(); // Reset the debounce timer } if ((millis() - lastDebounceTime) > debounceDelay) { // If the button state has been stable for longer than the debounce delay if (reading == LOW && buttonState == HIGH) { // Button is pressed score += 1; } buttonState = reading; // Update the button state } lastButtonState = reading; // Update the last button state sevseg.setNumber(score); // Display the updated score sevseg.refreshDisplay(); // Must run repeatedly }
@yzhmoeh
@yzhmoeh 3 ай бұрын
i think the first initialization is incorrect. It should be: int score = 0;
@Waiduino
@Waiduino 3 ай бұрын
@@yzhmoeh Thank you so much for catching that! I just changed it on the comment
@quangmi3402
@quangmi3402 2 ай бұрын
Can you guide and write code on how to move forward and backward, with a button that returns to 0?
@Waiduino
@Waiduino 2 ай бұрын
@@quangmi3402 Does it need to be with a 4 digit seven segment or can you use a 1 digit?
Stop Wasting Money on New Batteries! Restore Old AA Batteries Today!
18:17
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
The Only Git Tutorial You'll Ever Need (Complete Beginner's Guide)
16:20
Professor Patterns
Рет қаралды 1,1 М.
4 digit 7 segment display with Arduino
5:19
VinVout-io
Рет қаралды 479