Beranda > Arduino, DS1307, I2C LCD > Membuat Jam dengan Karakter Besar (Big Font) pada LCD Arduino

Membuat Jam dengan Karakter Besar (Big Font) pada LCD Arduino

19 Juni 2017

Tutorial ini menggunakan materi yang sama dengan tutorial sebelumnya yaitu Membuat Jam sederhana Menggunakan I2C LCD dan RTC DS1307.

Yang berbeda adalah sketchnya :

//source : https://www.youtube.com/watch?v=8ZsUcUAsL3I
//modified : yopi ardinal


#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>

#define I2C_ADDR 0x3F //0x3F for 16 x 2 units

// Tell the LCD what type we have (eg 16 x 2 or 20 x 4)
LiquidCrystal_I2C lcd(I2C_ADDR, 16, 2);

uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
RTC_DS1307 RTC;


// Define the bit patters for each of our custom chars. These
// are 5 bits wide and 8 dots deep
uint8_t custChar[8][8] = {
  {31, 31, 31, 0, 0, 0, 0, 0},      // Small top line - 0
  {0, 0, 0, 0, 0, 31, 31, 31},      // Small bottom line - 1
  { B11111,
    B00000,
    B00000,
    B00000,                         // This shows an alternative
    B00000,                         // way of defining a custome character,
    B00000,                         // a bit more 'visually' perhaps?
    B00000,
    B11111,
  },
  //{31, 0, 0, 0, 0, 0, 0, 31},     // Small lines top and bottom -2
  {0, 0, 0, 0, 0, 0,  0, 31},       // Thin bottom line - 3
  {31, 31, 31, 31, 31, 31, 15, 7},  // Left bottom chamfer full - 4
  {28, 30, 31, 31, 31, 31, 31, 31}, // Right top chamfer full -5
  {31, 31, 31, 31, 31, 31, 30, 28}, // Right bottom chamfer full -6
  {7, 15, 31, 31, 31, 31, 31, 31},  // Left top chamfer full -7
};

// Define our numbers 0 thru 9
// 254 is blank and 255 is the "Full Block"
uint8_t bigNums[10][6] = {
  {7, 0, 5, 4, 1, 6},         //0
  {0, 5, 254, 1, 255, 1},     //1
  {0, 2, 5, 7, 3, 1},         //2
  {0, 2, 5, 1, 3, 6},         //3
  {7, 3, 255, 254, 254, 255}, //4
  {7, 2, 0, 1, 3, 6},         //5
  {7, 2, 0, 4, 3, 6},         //6
  {0, 0, 5, 254, 7, 254},   //7
  {7, 2, 5, 4, 3, 6},         //8
  {7, 2, 5, 1, 3, 6},         //9
};

int jam, menit, detik;
int satuanjam, satuanmenit, puluhanjam, puluhanmenit, puluhandetik, satuandetik;


void setup()
{
  Wire.begin();
  RTC.begin();
  Serial.begin(9600);


  if (! RTC.begin()) {
    Serial.println("RTC tidak ditemukan");
    while (1);
  }

  if (! RTC.isrunning()) {
    Serial.println("RTC tidak jalan!");
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }


  // Initialise the LCD: turn on backlight and ensure cursor top left
  lcd.begin();
  lcd.backlight();
 
  lcd.clear();
  
}


void printBigNum(int number, int startCol, int startRow) {

  // Position cursor to requested position (each char takes 3 cols plus a space col)
  lcd.setCursor(startCol, startRow);

  // Each number split over two lines, 3 chars per line. Retrieve character
  // from the main array to make working with it here a bit easier.
  uint8_t thisNumber[6];
  for (int cnt = 0; cnt < 6; cnt++) {
    thisNumber[cnt] = bigNums[number][cnt];
  }

  // First line (top half) of digit
  for (int cnt = 0; cnt < 3; cnt++) {
    lcd.print((char)thisNumber[cnt]);
  }

  // Now position cursor to next line at same start column for digit
  lcd.setCursor(startCol, startRow + 1);

  // 2nd line (bottom half)
  for (int cnt = 3; cnt < 6; cnt++) {
    lcd.print((char)thisNumber[cnt]);
  }
}


void loop() {
  // Nothing to do here (compiler will probably remove this method)
  DateTime now = RTC.now();

  jam = now.hour();
  menit = now.minute();
  detik = now.second();

  satuanjam = jam % 10;
  puluhanjam = jam / 10;
    
  satuanmenit = menit % 10;
  puluhanmenit = menit / 10;
    
  satuandetik = detik % 10;
  puluhandetik = detik / 10;
  
   for (int cnt = 0; cnt < sizeof(custChar) / 8; cnt++) {
    lcd.createChar(cnt, custChar[cnt]);
  }


  printBigNum(puluhanjam, 0, 0);
  printBigNum(satuanjam, 4, 0);
  printBigNum(puluhanmenit, 8, 0);
  printBigNum(satuanmenit, 12, 0);
  lcd.setCursor(7,0);
  lcd.print(" ");
  lcd.setCursor(7,1);
  lcd.print(" ");
  delay(1000);
  printBigNum(puluhanjam, 0, 0);
  printBigNum(satuanjam, 4, 0);
  printBigNum(puluhanmenit, 8, 0);
  printBigNum(satuanmenit, 12, 0);
  lcd.setCursor(7,0);
  lcd.print("o");
  lcd.setCursor(7,1);
  lcd.print("o");
  delay(1000);
  
}


%d blogger menyukai ini: