Kali ini akan saya bahas mengenai bagaimana cara membuat alat untuk kendali lampu lalu lintas yang disimulasikan dengan led, disini dilengkapi dengan jam dan juga hari yang tampil di layar LCD, alat ini dilengkapi 3 buah tombol yang mana tiap tombol mewakili satu buah instruksi yang mengandung rule jam ON dan OFF led, jadi misal tombol 1 ditekan, led akan hidup hari senin sampai kamis jam 8.00 sampai jam 13.00, tombol 2 untuk hari jumat-sabtu jam 8.00 - 13.00 begitu pula dengan tombol 3. untuk lebih jelasnya berikut program dan skemanya.
a. Arduino Mega
b. LCD 16x2
c. RTC DS1307
d. LED + PUSH BUTTON
e. Program Arduino IDE
#include <LiquidCrystal.h>
#include "Wire.h"
#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
LiquidCrystal lcd(8, 7, 6, 3, 4, 5);
byte decToBcd(byte val)
{
return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return( (val/16*10) + (val%16) );
}
int led1 = A0;
int led2 = A1;
int led3 = A2;
int led4 = A3;
int led5 = A4;
int led6 = A5;
int led7 = A6;
int led8 = A7;
int led9 = A8;
int led10 = A9;
int led11 = A10;
int led12 = A11;
int mark = 0;
const int buttonPin1 = 14;
const int buttonPin2 = 15;
const int buttonPin3 = 16;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
void setup() {
// DS3231 seconds, minutes, hours, day, date, month, year
//setDS3231time(0,4,9,2,23,5,16);
Wire.begin();
lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led10, OUTPUT);
pinMode(led11, OUTPUT);
pinMode(led12, OUTPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year)
{
// sets time and date data to DS3231
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set next input to start at the seconds register
Wire.write(decToBcd(second)); // set seconds
Wire.write(decToBcd(minute)); // set minutes
Wire.write(decToBcd(hour)); // set hours
Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
Wire.write(decToBcd(month)); // set month
Wire.write(decToBcd(year)); // set year (0 to 99)
Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void displayTime1()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// retrieve data from DS3231
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
// send it to the serial monitor
lcd.setCursor(0, 0);
lcd.print(hour, DEC);
// convert the byte variable to a decimal number when displayed
lcd.print(":");
if (minute<10)
{
lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if (second<10)
{
lcd.print("0");
}
lcd.print(second, DEC);
lcd.setCursor(0, 1);
lcd.print(dayOfMonth, DEC);
lcd.print("/");
lcd.print(month, DEC);
lcd.print("/");
lcd.print(year, DEC);
switch(dayOfWeek){
lcd.setCursor(13, 1);
case 1:
lcd.print(" MInggu");
break;
case 2:
lcd.print(" Senin");
break;
case 3:
lcd.print(" Selasa");
break;
case 4:
lcd.print(" Rabu");
break;
case 5:
lcd.print(" Kamis");
break;
case 6:
lcd.print(" Jum'at");
break;
case 7:
lcd.print(" Sabtu");
break;
}
if ((hour >= 5) && (hour <= 8) && (dayOfWeek >= 2) && (dayOfWeek <= 5)){
digitalWrite(led1, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led10, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
//=========================================================
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
delay(1000);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
//========================================================
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
delay(1000);
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
//========================================================
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
delay(1000);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
if ((hour >= 11) && (hour <= 13) && (dayOfWeek >= 2) && (dayOfWeek <= 5)){
digitalWrite(led1, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led10, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
//=========================================================
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
delay(1000);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
//========================================================
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
delay(1000);
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
//========================================================
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
delay(1000);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
if ((hour >= 17) && (hour <= 18) && (dayOfWeek >= 2) && (dayOfWeek <= 5)){
digitalWrite(led1, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led10, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
//=========================================================
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
delay(1000);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
//========================================================
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
delay(1000);
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
//========================================================
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
delay(1000);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
else {
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
}
void displayTime2()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// retrieve data from DS3231
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
// send it to the serial monitor
lcd.setCursor(0, 0);
lcd.print(hour, DEC);
// convert the byte variable to a decimal number when displayed
lcd.print(":");
if (minute<10)
{
lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if (second<10)
{
lcd.print("0");
}
lcd.print(second, DEC);
lcd.setCursor(0, 1);
lcd.print(dayOfMonth, DEC);
lcd.print("/");
lcd.print(month, DEC);
lcd.print("/");
lcd.print(year, DEC);
switch(dayOfWeek){
lcd.setCursor(13, 1);
case 1:
lcd.print(" MInggu");
break;
case 2:
lcd.print(" Senin");
break;
case 3:
lcd.print(" Selasa");
break;
case 4:
lcd.print(" Rabu");
break;
case 5:
lcd.print(" Kamis");
break;
case 6:
lcd.print(" Jum'at");
break;
case 7:
lcd.print(" Sabtu");
break;
}
if ((hour >= 5) && (hour <= 8) && (dayOfWeek >= 6) && (dayOfWeek <= 7)){
digitalWrite(led1, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led10, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
//=========================================================
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
delay(1000);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
//========================================================
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
delay(1000);
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
//========================================================
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
delay(1000);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
if ((hour >= 11) && (hour <= 13) && (dayOfWeek >= 6) && (dayOfWeek <= 7)){
digitalWrite(led1, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led10, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
//=========================================================
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
delay(1000);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
//========================================================
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
delay(1000);
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
//========================================================
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
delay(1000);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
if ((hour >= 17) && (hour <= 18) && (dayOfWeek >= 6) && (dayOfWeek <= 7)){
digitalWrite(led1, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led10, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
//=========================================================
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
delay(1000);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
//========================================================
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
delay(1000);
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
//========================================================
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
delay(1000);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
else {
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
}
void displayTime3()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// retrieve data from DS3231
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
// send it to the serial monitor
lcd.setCursor(0, 0);
lcd.print(hour, DEC);
// convert the byte variable to a decimal number when displayed
lcd.print(":");
if (minute<10)
{
lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if (second<10)
{
lcd.print("0");
}
lcd.print(second, DEC);
lcd.setCursor(0, 1);
lcd.print(dayOfMonth, DEC);
lcd.print("/");
lcd.print(month, DEC);
lcd.print("/");
lcd.print(year, DEC);
switch(dayOfWeek){
lcd.setCursor(13, 1);
case 1:
lcd.print(" MInggu");
break;
case 2:
lcd.print(" Senin");
break;
case 3:
lcd.print(" Selasa");
break;
case 4:
lcd.print(" Rabu");
break;
case 5:
lcd.print(" Kamis");
break;
case 6:
lcd.print(" Jum'at");
break;
case 7:
lcd.print(" Sabtu");
break;
}
if ((hour >= 5) && (hour <= 8) && (dayOfWeek ==1) ){
digitalWrite(led1, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led10, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
//=========================================================
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
delay(1000);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
//========================================================
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
delay(1000);
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
//========================================================
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
delay(1000);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
if ((hour >= 12) && (hour <= 2) && (dayOfWeek ==1) ){
digitalWrite(led1, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led10, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
//=========================================================
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
delay(1000);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
//========================================================
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
delay(1000);
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
//========================================================
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
delay(1000);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
if ((hour >= 17) && (hour <= 19) && (dayOfWeek ==1) ){
digitalWrite(led1, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led10, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
//=========================================================
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
delay(1000);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
//========================================================
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
delay(1000);
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
//========================================================
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
delay(1000);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
if ((hour >= 21) && (dayOfWeek ==1) ){
digitalWrite(led1, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led10, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
//=========================================================
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
delay(1000);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
//========================================================
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
delay(1000);
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
//========================================================
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
delay(1000);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
if ((hour >= 0) && (hour <= 2) && (dayOfWeek ==1) ){
digitalWrite(led1, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led10, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
//=========================================================
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
delay(1000);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
delay(1000);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
//========================================================
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
delay(1000);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
delay(1000);
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
//========================================================
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
delay(1000);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
delay(1000);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
else {
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
}
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("PILIH MENU");
lcd.setCursor(0, 1);
lcd.print("1 2 3");
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
while (buttonState1 == LOW) {
lcd.setCursor(8, 0);
lcd.print(" MENU 1");
displayTime1();
}
while (buttonState2 == LOW) {
lcd.setCursor(8, 0);
lcd.print(" MENU 2");
displayTime2();
}
while (buttonState3 == LOW) {
lcd.setCursor(8, 0);
lcd.print(" MENU 3");
displayTime3();
}
}
f. VIDEO HASILNYA
No comments:
Post a Comment