Bonjour,
Je poste ici car j'ai besoin d'aide pour une programmation. J'ai pour projet d'afficher la date et l'heure sur un afficheur graphique SPI (LCD12864) à l'aide d'une horloge grove I2C ( basée sur le DS1307 ) et d'une carte Arduino. Je suis arrivé à afficher des caractères sur mon écran à l'aide du programme suivant :*
#include "U8glib.h" // Inclut la librairie U8G
//U8GLIB_ST7920_128X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, U8G_PIN_NONE, U8G_PIN_NONE, 17, 16); // Câblage parallèle
U8GLIB_ST7920_128X64 u8g(13, 11, 10, U8G_PIN_NONE); // Câblage SPI
/* Fonction permettant de redessiner TOUT l'écran */
void draw(void) {
u8g.setFont(u8g_font_unifont); // Utilise la police de caractère standard
u8g.drawStr( 0, 22, "Hello World"); // Affiche hello world
}
/* setup() */
void setup(void) {
u8g.setColorIndex(1); // Affichage en mode N&B (obligatoire vu que l'on a pas un écran couleur)
}
/* loop() */
void loop(void) {
u8g.firstPage(); // Sélectionne la 1er page mémoire de l'écran
do {
draw(); // Redessine tout l'écran
} while(u8g.nextPage()); // Sélectionne la page mémoire suivante
/* Delai avant de recommencer */
delay(1000);
}
Et j'arrive à faire fonctionner l'horloge via le moniteur série Arduino à l'aide du programme suviant :
/****************************************************************************/
// Function: Set time and get the time from RTC chip(DS1307) and display
// it on the serial monitor.
// Hardware: Grove - RTC
// Arduino IDE: Arduino-1.0
// Author: FrankieChu
// Date: Jan 19,2013
// Version: v1.0
// by www.seeedstudio.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
/****************************************************************************/
#include <Wire.h>
#include "DS1307.h"
DS1307 clock;//define a object of DS1307 class
void setup()
{
Serial.begin(9600);
clock.begin();
clock.fillByYMD(2013,1,19);//Jan 19,2013
clock.fillByHMS(15,28,30);//15:28 30"
clock.fillDayOfWeek(SAT);//Saturday
clock.setTime();//write time to the RTC chip
}
void loop()
{
printTime();
}
/*Function: Display time on the serial monitor*/
void printTime()
{
clock.getTime();
Serial.print(clock.hour, DEC);
Serial.print(":");
Serial.print(clock.minute, DEC);
Serial.print(":");
Serial.print(clock.second, DEC);
Serial.print(" ");
Serial.print(clock.month, DEC);
Serial.print("/");
Serial.print(clock.dayOfMonth, DEC);
Serial.print("/");
Serial.print(clock.year+2000, DEC);
Serial.print(" ");
Serial.print(clock.dayOfMonth);
Serial.print("*");
switch (clock.dayOfWeek)// Friendly printout the weekday
{
case MON:
Serial.print("MON");
break;
case TUE:
Serial.print("TUE");
break;
case WED:
Serial.print("WED");
break;
case THU:
Serial.print("THU");
break;
case FRI:
Serial.print("FRI");
break;
case SAT:
Serial.print("SAT");
break;
case SUN:
Serial.print("SUN");
break;
}
Serial.println(" ");
}
Maintenant il me faudrait afficher l'heure sur l'écran mais, étant débutant en programmation, je ne sais pas comment faire.. Merci pour votre aide.
Cordialement. G
