first commit

This commit is contained in:
2016-12-19 23:50:21 +01:00
commit 77e70471c6
2 changed files with 306 additions and 0 deletions
+306
View File
@@ -0,0 +1,306 @@
/*************************************
* Klok
* Author: Michel Bats
* Website: www.batssoft.nl
* Revision: 20140926
*
* Used libraries:
* LiquidCrystal_I2C
* F Malpartida's NewLiquidCrystal library
*************************************/
#include <Wire.h>
#include <LCD.h>
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // adres van het LCD
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
// Creat a set of new characters
const uint8_t charBitmap[][8] = {
{
0, 0, 0x1, 0x3, 0x3, 0x1, 0, 0 }
,
{
0, 0, 0x10, 0x18, 0x18, 0x10, 0, 0 }
,
{
0x1F, 0x1F, 0x1F, 0, 0, 0, 0, 0 }
,
{
0, 0, 0, 0, 0, 0x1F, 0x1F, 0x1F }
,
{
0x1F, 0x1F, 0, 0, 0, 0, 0x1F, 0x1F }
,
{
0xE, 0, 0, 0, 0, 0, 0, 0 }
,
{
0, 0, 0, 0, 0, 0, 0, 0xE }
,
{
0, 0, 0, 0, 0, 0, 0, 0 }
};
void setup() {
int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
Wire.begin();
rtc.begin();
lcd.begin (20,4); // Initialiseer het LCD
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
if (! rtc.isrunning()) {
//Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
//rtc.adjust(DateTime(2014, 1, 1, 1, 0, 0));
}
for ( int i = 0; i < charBitmapSize; i++ )
{
lcd.createChar ( i, (uint8_t *)charBitmap[i] );
}
lcd.clear();
}
void loop(){
DateTime now = rtc.now();
// Datum
lcd.setCursor ( 0, 0 );
//lcd.print (now.day());
//lcd.print ("-");
//lcd.print (now.month());
//lcd.print ("-");
//lcd.print (now.year());
// Dagen
char valDay = now.day();
int valDay1;
int valDay2;
if (valDay < 10) {
valDay1 = 10;
valDay2 = now.hour();
}
else {
char array[2];
sprintf(array, "%i", valDay);
valDay1 = array[0] - '0';
valDay2 = array[1] - '0';
}
printClock(0,0,valDay1);
printClock(4,0,valDay2);
// Streep
printClock(7,0,'-');
// Maanden
char valMonth = now.month();
int valMonth1;
int valMonth2;
if (valMonth < 10) {
valMonth1 = 10;
valMonth2 = now.hour();
}
else {
char array[2];
sprintf(array, "%i", valMonth);
valMonth1 = array[0] - '0';
valMonth2 = array[1] - '0';
}
printClock(8,0,valMonth1);
printClock(12,0,valMonth2);
// Uren
char valHour = now.hour();
int valHour1;
int valHour2;
if (valHour < 10) {
valHour1 = 10;
valHour2 = now.hour();
}
else {
char array[2];
sprintf(array, "%i", valHour);
valHour1 = array[0] - '0';
valHour2 = array[1] - '0';
}
printClock(4,2,valHour1);
printClock(8,2,valHour2);
//Dubbele punt
printClock(11,2,':');
// Minuten
char valMinute = now.minute();
int valMinute1;
int valMinute2;
if (valMinute < 10) {
valMinute1 = 0;
valMinute2 = now.minute();
}
else {
char array[2];
sprintf(array, "%i", valMinute);
valMinute1 = array[0] - '0';
valMinute2 = array[1] - '0';
}
printClock(13,2,valMinute1);
printClock(17,2,valMinute2);
delay (1000);
}
void printClock(int posX, int posY, char ch){
if (ch == 1){
lcd.setCursor ( posX, posY );
lcd.print (char(2));
lcd.print (char(511));
lcd.print (char(510));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(3));
lcd.print (char(511));
lcd.print (char(3));
}
else if (ch == 2){
lcd.setCursor ( posX, posY );
lcd.print (char(2));
lcd.print (char(4));
lcd.print (char(511));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(511));
lcd.print (char(3));
lcd.print (char(3));
}
else if (ch == 3){
lcd.setCursor ( posX, posY );
lcd.print (char(2));
lcd.print (char(4));
lcd.print (char(511));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(3));
lcd.print (char(3));
lcd.print (char(511));
}
else if (ch == 4){
lcd.setCursor ( posX, posY );
lcd.print (char(511));
lcd.print (char(3));
lcd.print (char(511));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(510));
lcd.print (char(510));
lcd.print (char(511));
}
else if (ch == 5){
lcd.setCursor ( posX, posY );
lcd.print (char(511));
lcd.print (char(4));
lcd.print (char(2));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(3));
lcd.print (char(3));
lcd.print (char(511));
}
else if (ch == 6){
lcd.setCursor ( posX, posY );
lcd.print (char(511));
lcd.print (char(4));
lcd.print (char(2));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(511));
lcd.print (char(3));
lcd.print (char(511));
}
else if (ch == 7){
lcd.setCursor ( posX, posY );
lcd.print (char(2));
lcd.print (char(2));
lcd.print (char(511));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(510));
lcd.print (char(510));
lcd.print (char(511));
}
else if (ch == 8){
lcd.setCursor ( posX, posY );
lcd.print (char(511));
lcd.print (char(4));
lcd.print (char(511));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(511));
lcd.print (char(3));
lcd.print (char(511));
}
else if (ch == 9){
lcd.setCursor ( posX, posY );
lcd.print (char(511));
lcd.print (char(4));
lcd.print (char(511));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(3));
lcd.print (char(3));
lcd.print (char(511));
}
else if (ch == 0){
lcd.setCursor ( posX, posY );
lcd.print (char(511));
lcd.print (char(2));
lcd.print (char(511));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(511));
lcd.print (char(3));
lcd.print (char(511));
}
else if (ch == ':'){
lcd.setCursor ( posX, posY );
lcd.print (char(0));
lcd.print (char(1));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(0));
lcd.print (char(1));
}
else if (ch == '-'){
lcd.setCursor ( posX, posY );
lcd.print (char(6));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(5));
}
else if (ch == ': :'){
lcd.setCursor ( posX, posY );
lcd.print (char(510));
lcd.print (char(510));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(510));
lcd.print (char(510));
}
else {
lcd.setCursor ( posX, posY );
lcd.print (char(510));
lcd.print (char(510));
lcd.print (char(510));
lcd.setCursor ( posX, posY+1 );
lcd.print (char(510));
lcd.print (char(510));
lcd.print (char(510));
}
}
BIN
View File
Binary file not shown.