Program Utama
=================================Source Code================================
#include "Wire.h"
#include "Time.h"
#include "DS1307RTC.h"
const char *monthName[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
tmElements_t tm;
void setup() {
bool parse=false;
bool config=false;
// get the date and time the compiler was run
if (getDate(__DATE__) && getTime(__TIME__)) {
parse = true;
// and configure the RTC with this info
if (RTC.write(tm)) {
config = true;
}
}
Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
delay(200);
if (parse && config) {
Serial.print("DS1307 configured Time=");
Serial.print(__TIME__);
Serial.print(", Date=");
Serial.println(__DATE__);
} else if (parse) {
Serial.println("DS1307 Communication Error :-{");
Serial.println("Please check your circuitry");
} else {
Serial.print("Could not parse info from the compiler, Time=\"");
Serial.print(__TIME__);
Serial.print("\", Date=\"");
Serial.print(__DATE__);
Serial.println("\"");
}
}
void loop() {
}
bool getTime(const char *str)
{
int Hour, Min, Sec;
if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
tm.Hour = Hour;
tm.Minute = Min;
tm.Second = Sec;
return true;
}
bool getDate(const char *str)
{
char Month[12];
int Day, Year;
uint8_t monthIndex;
if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false;
for (monthIndex = 0; monthIndex < 12; monthIndex++) {
if (strcmp(Month, monthName[monthIndex]) == 0) break;
}
if (monthIndex >= 12) return false;
tm.Day = Day;
tm.Month = monthIndex + 1;
tm.Year = CalendarYrToTm(Year);
return true;
}
13>
Program Utama.
Program Utama
=================================Source Code================================
#include "Time.h" //Time Library
#include "DS1307RTC.h" //Real Time Clock Library
#include "Wire.h" //Auxiliary Library for DS1307RTC (Real-Time Clock) - Pins to Arduino UNO: A4 (SDA), A5 (SCL)
#include "dht11.h" //Temperature and Humidity Library
dht11 DHT; //Define the name DHT for the sensor of Temperature and Humidity
#define DHT11_PIN 12 //Sensor DHT11 conected to the pin 11 on Arduino
int clockPin = 11; // Pin 8 of Arduino connected in the pin 11 of 74HC595 (Clock)
int latchPin = 10; // Pin 9 of Arduino connected in the pin 12 of 74HC595 (Latch)
int dataPin = 9; // Pin 10 of Arduino connected in the pin 14 of 74HC595 (Data)
int Jam, Menit, temp, umid;
int unitJam, unitMenit, perJam, perMenit;
int unitTemp, perTemp, unitUmid, perUmid;
unsigned long ti;
int chk; //Variable to read the sensor DHT11
//Digits Matrix - 0 a 9
byte num[] = {
B01111110, // Zero
B00110000, // One
B01101101, // Two
B01111001, // Three
B00110011, // Four
B01011011, // Five
B01011111, // Six
B01110000, // Seven
B01111111, // Eight
B01111011, // Nine
};
void setup() {
pinMode(latchPin, OUTPUT); // Define the 3 digital pins as output
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
setSyncProvider(RTC.get); // Update the time with data of RTC (Real Time Clock)
//setTime(15, 05, 00, 13, 02, 2016);
}
void loop() {
ti = millis(); // Initial time for the Timer of Hour/Time
while ((millis() - ti) < 3000) { //Timer of 3 seconds to show the Hour
Jam = hour();
Menit = minute();
unitJam = Jam % 10;
perJam = Jam / 10;
unitMenit = Menit % 10;
perMenit = Menit / 10;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 8); //Set DISPLAY 1 (top view from left to right)
shiftOut(dataPin, clockPin, LSBFIRST, ~num[perJam]); //Set the Hour (ten)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 4); //Set DISPLAY 2
shiftOut(dataPin, clockPin, LSBFIRST, ~num[unitJam]); //Set the Hour (unit)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 2); //Set DISPLAY 3
shiftOut(dataPin, clockPin, LSBFIRST, ~num[perMenit]); //Set the Minute (ten)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
shiftOut(dataPin, clockPin, LSBFIRST, ~num[unitMenit]); //Set the Minute (unit)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 4); //Set LED of dots
shiftOut(dataPin, clockPin, LSBFIRST, ~B10000000); //Set LEDs of double dots
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
shiftOut(dataPin, clockPin, LSBFIRST, 255); //Reset the DISPLAY 4 (to avoid some flicking)
digitalWrite(latchPin, HIGH);
}
delay(500); //Wait for half second before go ahead to show the next feature
chk = DHT.read(DHT11_PIN); //Read data of sensor DHT11
ti = millis(); //Initial time for the Timer of Temperature
temp = DHT.temperature; //Reading the Temperature in Celsius degree (ºC)
//Optional calculation of Temperature in Fahrenheit degrees (ºF). Remove the comments ("//") of following statement to use it.
//temp = (temp*18+5)/10+32;
while ((millis() - ti) < 3000) { //Timer of 3 seconds for the Temperature
unitTemp = temp % 10;
perTemp = temp / 10;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 8); //Set DISPLAY 1 (top view from left to right)
shiftOut(dataPin, clockPin, LSBFIRST, ~num[perTemp]); //Set the Temperature (ten)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 4); //Set DISPLAY 2
shiftOut(dataPin, clockPin, LSBFIRST, ~num[unitTemp]); //Set the Temperature (unit)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 2); //Set DISPLAY 3
shiftOut(dataPin, clockPin, LSBFIRST, ~B01100011); //Set the degree symbol [º]
digitalWrite(latchPin, HIGH);
//Show the Temperature in Celsius degrees (ºC)
//Set the following statements as comments with "//" to show the Temperature in Fahrenheit (ºF)
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
shiftOut(dataPin, clockPin, LSBFIRST, ~B01001110); //Set the symbol of Celsius [C]
digitalWrite(latchPin, HIGH);
//Show the Temperature in Fahrenheit degrees (ºF)
//Remove the indication of comments "//" on following statements to show the Temperature in Fahrenheit (ºF)
//digitalWrite(latchPin, LOW);
//shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
//shiftOut(dataPin, clockPin, LSBFIRST, ~B01000111); //Set the symbol of Fahrenheit [F]
//digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
shiftOut(dataPin, clockPin, LSBFIRST, 255); //Reset the DISPLAY 4 (to avoid some flicking)
digitalWrite(latchPin, HIGH);
}
delay(500); //Wait for half second before go ahead to show the next feature
ti = millis(); //Initial time for the Timer of Humidity
umid = DHT.humidity; //Reading the Humidity
while ((millis() - ti) < 3000) { //Timer of 3 seconds for the Humidity
unitUmid = umid % 10;
perUmid = umid / 10;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 8); //Set DISPLAY 1
shiftOut(dataPin, clockPin, LSBFIRST, ~num[perUmid]); //Set the Humidity (ten)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 4); //Set DISPLAY 2
shiftOut(dataPin, clockPin, LSBFIRST, ~num[unitUmid]); //Set the Humidity (unit)
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 2); //Set DISPLAY 3
shiftOut(dataPin, clockPin, LSBFIRST, ~B01100011); //Set the upper symbol of percentage [%] of Humidity
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set DISPLAY 4
shiftOut(dataPin, clockPin, LSBFIRST, ~B00011101); //Set the lower symbol of percentage [%] of Humidity
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, 1); //Set Display 4
shiftOut(dataPin, clockPin, LSBFIRST, 255); //Reset the DISPLAY 4 (to avoid some flicking)
digitalWrite(latchPin, HIGH);
}
delay(500); //Wait for half second before to restart
}
13>
Jangan Lupa Memasukkan Library Yang dibutuhkan
Disini
Cara Setting Jam Yaitu menggunakan Example dari Libray
"DS1307RTC.h" Upluad terlebih dahulu sebelum program utama dimasukkan ke Board Arduino yang digunakan.
VIDEO
No comments
Post a Comment