0% found this document useful (0 votes)
39 views

Arduino Timer

The code initializes a 7-segment display using a SevSeg library. It defines pins for a button and LED. When the button is pressed, it will count down from 10 to 0 on the display over 5 seconds, turning on an LED. It initializes the display in common cathode mode with 4 digits and sets the brightness. In the loop, it checks the button, sets the number to display from the start to end value, refreshes the display, then decrements the number and refreshes until it hits 0, at which point it turns off the LED.

Uploaded by

Liyyu Firdaus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Arduino Timer

The code initializes a 7-segment display using a SevSeg library. It defines pins for a button and LED. When the button is pressed, it will count down from 10 to 0 on the display over 5 seconds, turning on an LED. It initializes the display in common cathode mode with 4 digits and sets the brightness. In the loop, it checks the button, sets the number to display from the start to end value, refreshes the display, then decrements the number and refreshes until it hits 0, at which point it turns off the LED.

Uploaded by

Liyyu Firdaus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include "SevSeg.

h"
SevSeg sevseg;

int Button1 = A0;


int Ledlight = A1;
float TimeSecs = 1;
float display7segment = (TimeSecs * 5000);//10 wami
int startNumber = 10;
int endNumber = 0;

const int buzzerPin = 0;

void setup() {
pinMode(Button1,INPUT_PULLUP);
pinMode(Ledlight,OUTPUT);
byte numDigits = 4;
byte digitPins[] = {13, 10, 9, 2};
byte segmentPins[] = {12, 8, 4, 6,7, 11, 3, 5};
digitalWrite(Ledlight , HIGH);
bool resistorsOnSegments = true;
byte hardwareConfig = COMMON_CATHODE;
bool updateWithDelays = false;
bool leadingZeros = true;
bool disableDecPoint = true;

sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins,


resistorsOnSegments,
updateWithDelays, leadingZeros, disableDecPoint);
sevseg.setBrightness(50);
}

void loop() {

if(digitalRead(Button1)==LOW){
startNumber = 10;
digitalWrite(Ledlight ,HIGH);
}
if (startNumber >= endNumber) {
for (long i = 0; i <= display7segment; i++){
sevseg.setNumber(startNumber,0);
sevseg.refreshDisplay();
}
startNumber--;
}

if(startNumber < 0){


digitalWrite(Ledlight , LOW);
}
else {
digitalWrite(Ledlight ,HIGH);
}
sevseg.refreshDisplay();
sevseg.setNumber(0000,0);
}

You might also like