der_wille_zur_macht
Team RC
I know there's a library on the Arduino Playground, at least. When the Hydra project gets to the software stage, we'll be developing something, since that's the chip we're using for our LCD.
const int bluePin = 10; //blue LEDs
const int whitePin = 9; //white LEDs
const int pumpPin = 4; //tunze 6100
void pump() // this function creates a standing wave, like a wavebox would, in my 75
{
int a = 357; // you may need a different number here depending on your tank, pumps, etc..
analogWrite(pumpPin, 20); // pump is ON
delay(a);
analogWrite(pumpPin, 255); // pump is OFF
delay((a * 3) - 10); //i know this seems weird but its working to make a nice wave in my tank right now.
}
void blue(int val) /// these functions are just a wrapper for analogWrite
{
analogWrite(bluePin, val)
}
void white(int val)
{
analogWrite(whitePin, val)
}
byte getTime()
{
//whatever we need to put here to interface with the RTC I cant remember what goes here off hand
//just know that this function grabs the time for us.
}
void setup() {}
void loop() {
hour = getTime(); //gets the time or some function to get the hour of the day
switch (hour) { //changes the state of the pumps and LED's based on the hour of the day
case 1:
pump(); // does the pump sequence 1x
blue(5); //tells the LED's how bright they should be. when hour is 1 its 1AM, so white is off and blue is dim.
white(0); //doing it this way will have
break;
case 2:
//etcetera.. there will be 24 of these .. one for each hour of the day
break;
}
/*
Arduino controller for reef aquariums
//** Current Functionality
// paramterized LED lighting control for reef aquariums
// use a DS1307 RTC to kick off lighting schedules
// trigger a master pin "on" when the preset start time is reached
// then, fade up on a given slope
// delay a set amount
// fade back down
// such that the photoperiod lasts the correct amount of time
//** Circuit
//
// PWM pins described below connected to dimming circuits on drivers
// ledMaster pin below connected to a 120V AC relay to turn the LED drivers on and off
// grounds from drivers connected to arduino ground
// DS1307 RTC connected via I2C
//
//
//
*/
// Pins to control LEDs
int firstLed = 9; // LED PWM channel for east end
int secondLed = 10; // LED PWM channel for center
// Set up RTC
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
// RTC variables
byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year;
// Other variables. These control the behavior of lighting.
int minCounter = 0; // counter that resets at midnight
int ledStartMins = 480; // minute to start lights
int photoPeriod = 510; // photoperiod in minutes
int photoStagger = 60; // minutes to stagger photoperiods for each bank
void setup() {
// init I2C and One Wire
Wire.begin();
}
/****** LED Functions ******/
/***************************/
//function to set LED brightness according to time of day
//function has three equal phases - ramp up, hold, and ramp down
void setLed(int mins, int ledPin, int start, int period) {
if (mins > start && mins <= start + (period / 3) ) {
analogWrite(ledPin, map(mins - start, 0, period/3, 0, 255));
}
if (mins > start + (period / 3) && mins <= start + 2*(period / 3)) {
analogWrite(ledPin, 255);
}
if (mins > start + 2*(period / 3) && mins <= start + period) {
analogWrite(ledPin, map(mins - (start + 2*(period/3)), 0, (period/3), 255, 0));
}
}
/***** RTC Functions *******/
/***************************/
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour)); // If you want 12 hour am/pm you need to set
// bit 6 (also need to change readDateDs1307)
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.endTransmission();
}
// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
/***** Main Loop ***********/
/***************************/
void loop() {
// get time from RTC and put in hrs and mins variables
getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);
minCounter = rtcHrs * 60 + rtcMins;
// determine if it is day or night, and act accordingly
if (minCounter > ledStartMins && minCounter < ledStartMins + photoPeriod + 2*photoStagger) { //day
// set LED states
//digitalWrite(ledMaster, HIGH);
setLed(minCounter, firstLed, ledStartMins, photoPeriod);
setLed(minCounter, secondLed, ledStartMins + photoStagger, photoPeriod);
}
else { //night
analogWrite(firstLed, 0);
analogWrite(secondLed, 0);
}
// Get ready for next iteration of loop
oldMins = rtcMins;
oldHrs = rtcHrs;
delay(1000);
}
So I spent the last 4 hours trying to just be able to display time on my LCD with no luck. I have followed thread after thread and I say uncle. Can anybody point me in the right direction or post some code that will allow this to work? Maybe an arduino for dummies book? :lmao:....... Jeff
thing doesn't want to post the include statements correctly, so here they are without the greaterthan/lessthan sign thingies:
#include Time.h
#include Wire.h
#include DS1307RTC.h // a basic DS1307 library that returns time as a time_t
#include LiquidCrystal.h
[code]
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
byte res;
byte msb;
byte lsb;
int val;
int switchPin = 2;// switch is connected to pin 2
int ledPin = 13;
int val1;
int val2; // variable for reading the pin status
int lightMode;
int buttonState;
void setup() {
pinMode(switchPin, INPUT);
buttonState = digitalRead(switchPin);
lcd.begin(20, 4);
Serial.begin(9600);
setSyncProvider(RTC.get); // the function to get the time from the RTC
Wire.begin();
}
void loop()
{
displayTime();
getTemp();
//watchButton();
//delay(1000);
val = digitalRead(switchPin); // read input value and store it in val
lcd.setCursor(0,3);
if (val != buttonState) { // the button state has changed!
if (val == LOW) { // check if the button is pressed
if (lightMode == 0){
lightMode = 1;
digitalWrite(ledPin, HIGH);
lcd.print(".");
}
else {
lightMode = 0;
digitalWrite(ledPin, LOW);
lcd.print(" ");
}
} else { // the button is -not- pressed...
//Serial.println("Button just released");
}
}
buttonState = val; // save the new state in our variable
}
void displayTime(){
lcd.setCursor(15, 0);
lcd.print(hour());
printDigits(minute());
//printDigits(second());
lcd.print(" ");
}
void displayDate(){
//lcd.print(month());
//lcd.print("/");
//lcd.print(day());
//lcd.print("/");
//lcd.print(year());
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits);
}
void getTemp(){
res = Wire.requestFrom(72,2);
if (res == 2) {
msb = Wire.receive(); /* Whole degrees */
lsb = Wire.receive(); /* Fractional degrees */
val = ((msb) << 4); /* MSB */
val |= (lsb >> 4); /* LSB */
//Serial.println(val*0.0625);
lcd.setCursor(0, 0);
lcd.print((((val*0.0625)*9)/5)+32);
//delay(500);
}
}
Thanks for the code funkmuffin....
OK, so I just found out that I had to download the time library :hmm3: and put it into my Arduino hardware folder. I must have done it right because it no longer gives me a error when I try to upload. However, now I have two rows of blocks on my LCD. Tomorrows a new day i guess... Jeff
Post your sketch or go to the Arduino forums over at Arduino.com.
There are plenty of posts on the Arduino forum involving the RTC. Search for RTC chip you are using.
Can you get anything to display on the LCD?
Make sure your telling the pin you assigned the clock to look for input from the RTC and send that input to the LCD. Some times it is as simple as that.
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h> // written by mattt on the Arduino forum and modified by D. Sjunnesson
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(20, 4); //20x4 LCD Display
lcd.setCursor(3, 0); //Starts on column 3 row 0
lcd.print("LED Controller"); //Line above centers statement
Serial.begin(9600);
RTC.stop();
RTC.set(DS1307_SEC,1); //set the seconds
RTC.set(DS1307_MIN,33); //set the minutes
RTC.set(DS1307_HR,11); //set the hours
RTC.set(DS1307_DOW,1); //set the day of the week
RTC.set(DS1307_DATE,13); //set the date
RTC.set(DS1307_MTH,6); //set the month
RTC.set(DS1307_YR,10); //set the year
RTC.start();
}
void loop()
{
lcd.setCursor(0, 2); //Starts on column 0 row 2
lcd.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
lcd.print(":");
lcd.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
lcd.print(":");
lcd.print(RTC.get(DS1307_SEC,false));//read seconds
lcd.setCursor(10, 2);
lcd.print(RTC.get(DS1307_MTH,false));//read month
lcd.print("/");
lcd.print(RTC.get(DS1307_DATE,false));//read date
lcd.print("/");
lcd.print(RTC.get(DS1307_YR,false)); //read year
delay(1000);
}
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(20, 4); //20x4 LCD Display
lcd.setCursor(0, 0); //Starts on column 0 row 0
Serial.begin(9600);
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus()!= timeSet)
lcd.print("Somethings wrong!");
else
lcd.setCursor(3, 0); //Starts on column 3 row 0
lcd.print("LED Controller");
}
void loop()
{
digitalClockDisplay();
delay(1000);
}
void digitalClockDisplay()
{
lcd.setCursor(0, 2); //Starts on column 0 row 2
lcd.print(hour());
printDigits(minute());
printDigits(second());
lcd.setCursor(10, 2); //Starts on column 0 row 2
lcd.print(month());
lcd.print("/");
lcd.print(day());
lcd.print("/");
lcd.print(year());
//lcd.print();
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits);
}