Translate

Timer Counter Down Panel P10 RGB HUB75

Timer Counter Down Panel P10 RGB HUB75



        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat menampilkan nilai countdown untuk tujuan tertentu. alat ini menggunakan panel P10 RGB dengan HUB75. pada tampilan di panel P10 terdapat simbol merah dan hijau serta terdapat pula nilai yang countdown. untuk lebih jelasnya berikut adalah program dan komponennya.  


a. Arduino Uno




b. Panel P10 RGB





c. Modul RTC DS3231





d. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DS3231.h>
#include <Adafruit_GFX.h>   
#include <RGBmatrixPanel.h> 
LiquidCrystal_I2C lcd(0x27, 16, 2);

DS3231  rtc(SDA, SCL);
Time  t;

#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr

#define CLK 8  // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);

String sjam,smenit,sdetik;
int jam,menit,detik;

int btset = 10;
int btup = 11;
int btdown = 12;
int btok = 13;
int btsetx;
int btupx;
int btdownx;
int btokx;
int countdown;
int detikku;


void setup()
{
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(btset,INPUT_PULLUP);
  pinMode(btup,INPUT_PULLUP);
  pinMode(btdown,INPUT_PULLUP);
  pinMode(btok,INPUT_PULLUP);
  matrix.begin();
  matrix.setTextWrap(false); // Allow text to run off right edge
  matrix.setTextSize(2);
  matrix.fillScreen(0);
  rtc.begin();
  //rtc.setDOW(THURSDAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(15, 53, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(13, 5, 2022);   // Set the date to January 1st, 2014
}

void loop()
{
  
t = rtc.getTime();

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

if(btsetx == 0){
delay(200);
lcd.clear();  
setjam();
setmenit();
setdetik();  
}

  lcd.setCursor(0,0);
  lcd.print(t.hour);
  lcd.print(":");
  lcd.print(t.min);
  lcd.print(":");
  lcd.print(t.sec);
  lcd.print("   ");

detikku = 59 - t.sec;

if(t.sec == 30){

  matrix.drawLine(4, 3, 5, 3 , matrix.Color333(1, 0, 0));
  matrix.drawLine(3, 4, 6, 4 , matrix.Color333(1, 0, 0));
  matrix.drawLine(2, 5, 7, 5 , matrix.Color333(1, 0, 0));
  matrix.drawLine(1, 6, 8, 6 , matrix.Color333(1, 0, 0));
  matrix.drawLine(0, 7, 9, 7 , matrix.Color333(1, 0, 0));
  matrix.drawLine(0, 8, 9, 8 , matrix.Color333(1, 0, 0));
  matrix.drawLine(1, 9, 8, 9 , matrix.Color333(1, 0, 0));
  matrix.drawLine(2, 10, 7, 10 , matrix.Color333(1, 0, 0));
  matrix.drawLine(3, 11, 6, 11 , matrix.Color333(1, 0, 0));
  matrix.drawLine(4, 12, 5, 12 , matrix.Color333(1, 0, 0));

countdown = 30;
matrix.setTextColor(matrix.Color444(1, 1, 1));
matrix.setCursor(10, 1); //x,y
matrix.print(countdown); 
delay(2000);
matrix.fillScreen(0);
}

if(detikku == 10){
  
  matrix.drawLine(4, 3, 5, 3 , matrix.Color333(1, 0, 0));
  matrix.drawLine(3, 4, 6, 4 , matrix.Color333(1, 0, 0));
  matrix.drawLine(2, 5, 7, 5 , matrix.Color333(1, 0, 0));
  matrix.drawLine(1, 6, 8, 6 , matrix.Color333(1, 0, 0));
  matrix.drawLine(0, 7, 9, 7 , matrix.Color333(1, 0, 0));
  matrix.drawLine(0, 8, 9, 8 , matrix.Color333(1, 0, 0));
  matrix.drawLine(1, 9, 8, 9 , matrix.Color333(1, 0, 0));
  matrix.drawLine(2, 10, 7, 10 , matrix.Color333(1, 0, 0));
  matrix.drawLine(3, 11, 6, 11 , matrix.Color333(1, 0, 0));
  matrix.drawLine(4, 12, 5, 12 , matrix.Color333(1, 0, 0));

countdown = 10;
  
matrix.setTextColor(matrix.Color444(1, 1, 1));
matrix.setCursor(10, 1); //x,y
matrix.print(countdown);   
delay(1000);
matrix.fillScreen(0);
}

if((detikku > 0 )&&(detikku <= 5)){
matrix.setTextColor(matrix.Color444(1, 1, 1));
matrix.setCursor(15, 1); //x,y
matrix.print(detikku);   
}

if(detikku > 0){
  matrix.drawLine(4, 3, 5, 3 , matrix.Color333(1, 0, 0));
  matrix.drawLine(3, 4, 6, 4 , matrix.Color333(1, 0, 0));
  matrix.drawLine(2, 5, 7, 5 , matrix.Color333(1, 0, 0));
  matrix.drawLine(1, 6, 8, 6 , matrix.Color333(1, 0, 0));
  matrix.drawLine(0, 7, 9, 7 , matrix.Color333(1, 0, 0));
  matrix.drawLine(0, 8, 9, 8 , matrix.Color333(1, 0, 0));
  matrix.drawLine(1, 9, 8, 9 , matrix.Color333(1, 0, 0));
  matrix.drawLine(2, 10, 7, 10 , matrix.Color333(1, 0, 0));
  matrix.drawLine(3, 11, 6, 11 , matrix.Color333(1, 0, 0));
  matrix.drawLine(4, 12, 5, 12 , matrix.Color333(1, 0, 0));
}

if(detikku == 0){
  matrix.drawLine(4, 3, 5, 3 , matrix.Color333(0, 1, 0));
  matrix.drawLine(3, 4, 6, 4 , matrix.Color333(0, 1, 0));
  matrix.drawLine(2, 5, 7, 5 , matrix.Color333(0, 1, 0));
  matrix.drawLine(1, 6, 8, 6 , matrix.Color333(0, 1, 0));
  matrix.drawLine(0, 7, 9, 7 , matrix.Color333(0, 1, 0));
  matrix.drawLine(0, 8, 9, 8 , matrix.Color333(0, 1, 0));
  matrix.drawLine(1, 9, 8, 9 , matrix.Color333(0, 1, 0));
  matrix.drawLine(2, 10, 7, 10 , matrix.Color333(0, 1, 0));
  matrix.drawLine(3, 11, 6, 11 , matrix.Color333(0, 1, 0));
  matrix.drawLine(4, 12, 5, 12 , matrix.Color333(0, 1, 0));
  matrix.setTextColor(matrix.Color444(0, 1, 0));
  matrix.setCursor(10, 1); //x,y
  matrix.print("GO");   
  delay(3000);
  matrix.fillScreen(0);
}
  delay(1000);
  matrix.fillScreen(0);
}

void setjam(){

  lcd.setCursor(0,0);
  lcd.print("Jam: ");
  lcd.print(jam);
  lcd.print("   ");

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

if(btupx == 0){
delay(200);
jam++;  
}

if(btdownx == 0){
delay(200);
jam--;  
}

if(btokx == 0){
lcd.clear();
delay(2000);
return; 
}

if(jam > 23){
jam = 0;
}

if(jam < 0){
jam = 23;
}  

setjam();
}


void setmenit(){

  lcd.setCursor(0,0);
  lcd.print("Min: ");
  lcd.print(menit);
  lcd.print("   ");

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

if(btupx == 0){
delay(200);
menit++;  
}

if(btdownx == 0){
delay(200);
menit--;  
}

if(btokx == 0){
lcd.clear();
delay(2000);
return; 
}

if(menit > 59){
menit = 0;
}

if(menit < 0){
menit = 59;
}  

setmenit();
}


void setdetik(){

  lcd.setCursor(0,0);
  lcd.print("Detik: ");
  lcd.print(detik);
  lcd.print("   ");

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

if(btupx == 0){
delay(200);
detik++;  
}

if(btdownx == 0){
delay(200);
detik--;  
}

if(btokx == 0){
lcd.clear();
delay(2000);
t.hour = jam;
t.min = menit;
t.sec = detik;
rtc.setTime(jam,menit,detik);     // Set the time to 12:00:00 (24hr format)
return; 
}

if(detik > 59){
detik = 0;
}

if(detik < 0){
detik = 59;
}  

setdetik();




e. VIDEO HASILNYA




No comments:

Post a Comment