Pembuatan Jam Digital Sederhana
Вставка
- Опубліковано 6 жов 2024
- Ini adalah program dari jam digital sederhana ini
// Copy mulai dari sini
#include "LedControl.h"
/*
Now we need a LedControl to work with.
**** These pin numbers will probably not work with your hardware ****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);
/* we always wait a bit between updates of the display */
unsigned long delaytime=1000;
int detiksatuan = 0;
int detikpuluhan = 0;
int menitsatuan = 0;
int menitpuluhan = 0;
int jamsatuan = 0;
int jampuluhan = 0;
void setup() {
// put your setup code here, to run once:
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), UbahJam, RISING);
pinMode(3, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(3), UbahMenit, RISING);
}
void loop() {
// put your main code here, to run repeatedly:
if ( detiksatuan == 9)
{
detikpuluhan = detikpuluhan +1;
detiksatuan = 0;
}
else
{ detiksatuan = detiksatuan +1;
}
if ( detikpuluhan == 6)
{
menitsatuan = menitsatuan +1;
detikpuluhan = 0;
}
if ( menitsatuan == 10)
{
menitpuluhan = menitpuluhan +1;
menitsatuan = 0;
}
if ( menitpuluhan == 6)
{
jamsatuan = jamsatuan +1;
menitpuluhan =0;
}
if ( jamsatuan == 10)
{
jampuluhan = jampuluhan +1;
jamsatuan = jamsatuan =0;
}
if ( jampuluhan == 2)
{
if ( jamsatuan ==4)
{
jampuluhan = 0;
jamsatuan =0;
}
}
// Menampilkan ke display 7 segment
lc.setDigit(0,0,detiksatuan,false); //detik satuan
lc.setDigit(0,1,detikpuluhan,false); // detik puluhan
lc.setChar(0,2,'-',false); // karakter -
lc.setDigit(0,3,menitsatuan,false); // menit satuan
lc.setDigit(0,4,menitpuluhan,false); // menit puluhan
lc.setChar(0,5,'-',false); // karakter -
lc.setDigit(0,6,jamsatuan,false); // jam satuan
lc.setDigit(0,7,jampuluhan,false); // jam puluhan
delay(delaytime);
}
void UbahJam(){
jamsatuan = jamsatuan +1;
}
void UbahMenit(){
menitsatuan = menitsatuan+1;
}
// Sampai sini
Terima Kasih Semoga bermanfaat
#arduino #digitalclock #7segmentdisplay #interrupts #arduinoproject #library #setChar #setDigit #jamdigital