Code: Select all
void setup () {
// omitted
// set up the LCD
lcd.begin(COLUMNS_LCD, ROWS_LCD);
lcd.print("Hello world!");
// init. the RTC
rtc.begin();
todayDate = now.unixtime();
// omitted
}
Moderators: adafruit_support_bill, adafruit
Code: Select all
void setup () {
// omitted
// set up the LCD
lcd.begin(COLUMNS_LCD, ROWS_LCD);
lcd.print("Hello world!");
// init. the RTC
rtc.begin();
todayDate = now.unixtime();
// omitted
}
Code: Select all
/*
Demonstration sketch for Adafruit i2c/SPI LCD backpack
using MCP23008 I2C expander
( http://www.ladyada.net/products/i2cspilcdbackpack/index.html )
This sketch prints "Hello World!" to the LCD
and shows the time.
The circuit:
* 5V to Arduino 5V pin
* GND to Arduino GND pin
* CLK to Analog #5
* DAT to Analog #4
*/
// include the library code:
#include "Wire.h"
#include "LiquidCrystal.h"
const byte red = 22;
const byte blue = 24;
const byte green = 26;
// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidCrystal lcd(0);
void setup() {
// set up the LCD's number of rows and columns:
Serial.println("Initializing backlight pins");
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
Serial.println("Initializing LCD");
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
Serial.begin(9600);
Serial.println("Setup complete");
}
void loop() {
static byte color = 1;
int mySeconds=0;
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
mySeconds=millis()/1000;
lcd.print(mySeconds);
Serial.println(mySeconds);
switch (color) {
case 1: {
color = 2;
backlit(red);
break;
}
case 2: {
color = 3;
backlit(green);
break;
}
case 3: {
color = 1;
backlit(blue);
break;
}
}
}
void backlit(byte myPin) {
digitalWrite(red, LOW);
digitalWrite(blue, LOW);
digitalWrite(green, LOW);
digitalWrite(myPin, HIGH);
delay(1000);
return;
}
Yes, it does.adafruit_support_mike wrote:If you disconnect the LCD and load a sketch that only uses the RTC, does the RTC work?
Code: Select all
LiquidCrystal lcd(0);
RTC_DS1307 rtc;
Code: Select all
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("LCD initialized!");
Serial.println("LCD initialized");
Code: Select all
// Initialize RTC
Serial.println("Initializing RTC");
rtc.begin();
Serial.println("RTC initialized");
Code: Select all
void loop() {
long mySeconds = 0;
DateTime now = rtc.now();
Code: Select all
// Test the RTC with the LCD functioning
// include the library code:
#include "Wire.h"
#include "LiquidCrystal.h"
#include "RTClib.h" // DS1307 Real Time Clock library
const byte red = 24;
const byte blue = 26;
const byte green = 28;
const byte RTC_GND = 18;
const byte RTC_VCC = 19;
volatile byte color = 1;
// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidCrystal lcd(0);
RTC_DS1307 rtc;
//**************************************************
void setup() {
Serial.begin(57600);
// set up the LCD's number of rows and columns:
Serial.println("Initializing LCD backlight");
pinMode(red, OUTPUT); // initializing backlight pins
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
switchColor();
Serial.println("Backlight initialized");
Serial.println("Initializing LCD");
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("LCD initialized!");
Serial.println("LCD initialized");
// Initialize RTC
/*
Serial.println("Initializing RTC power");
pinMode(RTC_GND, OUTPUT); // set pins to power RTC
digitalWrite(RTC_GND, LOW);
pinMode(RTC_VCC, OUTPUT);
digitalWrite(RTC_VCC, HIGH);
Serial.println("RTC power initialized");
*/
Serial.println("Initializing RTC");
rtc.begin();
Serial.println("RTC initialized");
Serial.println("Setup complete");
}
//**************************************************
void loop() {
long mySeconds = 0;
DateTime now = rtc.now();
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
// mySeconds = millis() / 1000;
mySeconds=now.second();
lcd.print(mySeconds);
Serial.print("Seconds ");
Serial.println(mySeconds);
switchColor();
}
//--------------------------------------------------
void backlit(byte myPin) {
digitalWrite(red, LOW);
digitalWrite(blue, LOW);
digitalWrite(green, LOW);
digitalWrite(myPin, HIGH);
delay(1000);
return;
}
//--------------------------------------------------
void switchColor() {
Serial.println(color);
switch (color) {
case 1: {
color = 2;
backlit(red);
break;
}
case 2: {
color = 3;
backlit(green);
break;
}
case 3: {
color = 1;
backlit(blue);
break;
}
}
}