Translate

TIMER COUNTDOWN INTERFACE P10 ALARM ARDUINO

Timer Countdown Interface P10 Alarm Arduino
 
     
           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk timer count down / pewaktu pencacah mundur dengan nilai yang sudah disetting pada koding, jika sudah mencapai waktunya atau waktunya sudah 0 maka akan membunyikan buzzer. untuk lebih jelasnya berikut adalah komponen dan programnya.

 
 
a. Komponen Penyusun


b. Wiring Diagram Arduino ke Panel P10


c. Program Arduino IDE

#include <Wire.h>
#include <SPI.h>        //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h>        //Library DMD yang menyediakan fungsi penampilan teks, gambar dsb
#include <TimerOne.h>   //Library peripheral Timer1 untuk menjalankan prosedur pindai panel DMD
#include <Time.h>     //Library waktu yang menyediakan tipe data, struktur, dan obyek waktu
#include "Arial_black_16.h"
#include "Arial_Black_16_ISO_8859_1.h"
#include "Arial14.h"
#include "DejaVuSans9.h"
#include "Droid_Sans_12.h"
#include "Droid_Sans_16.h"
#include "DejaVuSansItalic9.h"
#include "Mono5x7.h"
#include "SystemFont5x7.h"
#include <DS3231.h>

#define WAKTU_TAMPIL_JAM      10    //detik
#define WAKTU_TAMPIL_KALENDAR 5     //detik

#define DISPLAY_COLUMN_COUNT  2
#define DISPLAY_ROW_COUNT     1

#define PIXELS_PER_COLUMN  32
#define PIXELS_PER_ROW    16

#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

DMD dmd(DISPLAY_COLUMN_COUNT, DISPLAY_ROW_COUNT);
unsigned char show = 0;

unsigned int suhu;
unsigned int suhux;
unsigned int dataadc;

char lineBuff[20];
char lineBuffx[20];

int jam = 0;
int menit = 1;
int detik = 60;

int jamx;
int menitx;
int detikx;
int buzzer = 5;
int tombol = 3;
int tombolx;
int tanda = 0;

DS3231  rtc(SDA, SCL);
Time  t;
 
void ScanDMD()
{
  dmd.scanDisplayBySPI();
}


void setup(void)
{
  mlx.begin();
  dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)
  Serial.begin(9600);
   //initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
  Timer1.initialize( 1000 );           //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
  Timer1.attachInterrupt( ScanDMD );   //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
 
  //clear/init the DMD pixels held in RAM
  dmd.clearScreen( true );
  rtc.begin();
  //rtc.setDOW(FRIDAY);     // Set Day-of-Week to SUNDAY
  rtc.setTime(0, 0, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(13, 5, 2022);   // Set the date to January 1st, 2014
  pinMode(buzzer,OUTPUT);
  digitalWrite(buzzer,LOW); //buzzer off
  pinMode(tombol,INPUT_PULLUP);
}


void loop(void)
{
t = rtc.getTime();
t.sec = 0;
 
tombolx = digitalRead(tombol);

if(tombolx == 0){
rtc.setTime(0, 0, 0);  
t.sec = 0;  
mulai();  
}

sprintf(lineBuff, "%d:%d", jam, menit);
sprintf(lineBuffx, "%d ", t.sec);

dmd.selectFont(DejaVuSans9);
dmd.selectFont(Mono5x7);
dmd.drawString( 38,  0, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  
dmd.drawString( 42,  8, lineBuffx, strlen(lineBuffx), GRAPHICS_NORMAL);  

}

void mulai(){
t = rtc.getTime();
detikx = detik - t.sec;

 sprintf(lineBuff, "%d:%d   ", jam, menit);
 sprintf(lineBuffx, "%d ", detikx);

 dmd.selectFont(DejaVuSans9);
 dmd.selectFont(Mono5x7);
 dmd.drawString( 38,  0, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  
 dmd.drawString( 42,  8, lineBuffx, strlen(lineBuffx), GRAPHICS_NORMAL);  

 
if((jam <= 0)&&(menit <= 0)&&(detikx <= 30)){
   digitalWrite(buzzer,HIGH); //buzzer on
   delay(20);
   digitalWrite(buzzer,LOW); //buzzer off
}

if(detikx == 1){
     
   if((jam == 0)&&(menit == 0)&&(detikx == 1)){
     jam = 0;
     menit = 0;
     detikx = 0;
     detik = 0;
     t.sec = 0;
     
     sprintf(lineBuff, "%d:%d", jam, menit);
     sprintf(lineBuffx, "%d ", detikx);

     dmd.selectFont(DejaVuSans9);
     dmd.selectFont(Mono5x7);
     dmd.drawString( 38,  0, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  
     dmd.drawString( 42,  8, lineBuffx, strlen(lineBuffx), GRAPHICS_NORMAL);  
   
    digitalWrite(buzzer,HIGH);
    delay(5000);
    digitalWrite(buzzer,LOW);
    tanda = 0;
    jam = 1;
    menit = 59;
    detik = 60;
    return;
    }
    
    menit--;
    detikx = 59;
    detik = 59;

 if(menit < 0){
 if(jam > 0){
   menit = 59;
  }
    
    jam--;
    
if(jam < 0){
      jam = 0;
    }    
    }
    
 }

delay(1000);  
mulai();  
}



 
d. VIDEO HASILNYA
 





No comments:

Post a Comment