Paso 4: codificación.
1. Descargue el proyecto de demostración de arduino (clockWithCalendar.rar) a su ordenador.
2. Abra el proyecto del IDE de Arduino y luego subir el programa a la placa.
¿Para obtener más información? por favor consulte la Página de la WIKI.
Características más emocionantes, consulte el Manual de usuario.
El código principal se muestra a continuación.
#include <Wire.h>#include <I2C_LCD.h>#include "DS1307.h"//For detials of the function useage, please refer to "I2C_LCD User Manual". //You can download the "I2C_LCD User Manual" from I2C_LCD WIKI page: // http://www.seeedstudio.com/wiki/I2C_LCDI2C_LCD LCD; //define a object of I2C_LCD class uint8_t I2C_LCD_ADDRESS = 0x51; //Device address configuration, the default value is 0x51.extern GUI_Bitmap_t bmClock; //Declare bitmap data packet.char monthTab[13][6] = {"Null","Jan.,","Feb.,", "Mar.,", "Apr.,", "May,", "Jun.,", "Jul.,", "Aug.,", "Sep.,", "Oct.,", "Nov.,", "Dec.,"}; char weekTab[8][10] = {"Null","Mon.,","Tues.,", "Wed.,", "Thur.,", "Fri.,", "Sat.,", "Sun.,"}; char dayTab[32][6] = {"Null","1st,","2nd,", "3rd,", "4th,", "5th,", "6th,", "7th,", "8th,", "9th,", "10th,", "11th,", "12th,", "13th,", "14th,", "15th,", "16th,", "17th,", "18th,", "19th,", "20th,", "21th,", "22nd,", "23rd,", "24th,", "25th,", "26th,", "27th,", "28th,", "29th,", "30th,", "31st,"};char timeTab[10] = {"00:00:00"};DS1307 clock; //define a object of DS1307 classvoid setup() { Wire.begin(); //I2C controller initialization. clock.begin(); //RTC initialization. clock.fillByYMD(2015,07,31); //Jul 31,2015 clock.fillByHMS(21,20,30); //21:20:30" clock.fillDayOfWeek(FRI); //Friday clock.setTime(); //Write time to the RTC chip. }void loop() { LCD.CleanAll(WHITE); //Clean the screen with black or white. //Booting logo ON, backlight ON, bitmap work mode. //If you want to display characters please switch to WM_CharMode. LCD.WorkingModeConf(ON, ON, WM_BitmapMode); //Display bitmap at the specified location. //Prototype: void DrawScreenAreaAt(GUI_Bitmap_t *bitmap, uint8_t x, uint8_t y) LCD.DrawScreenAreaAt(&bmClock, 4, 3); //Draw a rectangle, and filled with black; //Prototype: void DrawRectangleAt(x, y, width, height, mode); LCD.DrawRectangleAt(0, 0, 128, 5, BLACK_FILL); LCD.DrawRectangleAt(0, 59, 128, 5, BLACK_FILL); //Booting logo ON, backlight ON, character work mode. LCD.WorkingModeConf(ON, ON, WM_CharMode); while(1) { //Update the date and time. clock.getTime(); //Set font size. LCD.FontModeConf(Font_6x8, FM_ANL_AAA, BLACK_BAC); //Set the start coordinate. LCD.CharGotoXY(5,10); //Date format: Fri.,24st,Jul.,2015 LCD.print(weekTab[clock.dayOfWeek]); LCD.print(dayTab[clock.dayOfMonth]); LCD.print(monthTab[clock.month]); LCD.print(clock.year+2000); //Set font size. LCD.FontModeConf(Font_10x20, FM_ANL_AAA, BLACK_BAC); //Set the start coordinate. LCD.CharGotoXY(40,32); //Time format: 00:00:00 snprintf(timeTab, 9, "%02d:%02d:%02d", clock.hour, clock.minute, clock.second); LCD.print(timeTab); delay(1000); } }