I started to make a clock with seven segment displays and real time ds1307, my problem is with the displaying, I want to see the clock for 4 seconds and then 4 seconds the date and so in the circle
#include <SevenSeg.h>
#include "Wire.h"
#define DS1307_ADDRESS 0x68
SevenSeg disp1(2,3,4,5,6,9,8);
SevenSeg disp2(2,3,4,5,6,9,8);
const int numOfDigits1 = 2;
const int numOfDigits2 = 2;
int digitPins1 [ numOfDigits1 ]={10,11};
int digitPins2 [ numOfDigits2 ]={12,13};
byte zero = 0x00; //workaround for issue #527
void setup () {
Wire.begin();
Serial.begin(9600);
setDateTime();
disp1 . setDigitPins ( numOfDigits1 , digitPins1 );
disp1 . setDigitDelay (3000) ;
disp2 . setDigitPins ( numOfDigits2 , digitPins2 );
disp2 . setDigitDelay (3000) ;
}
void setDateTime(){
byte second = 59; //0-59
byte minute = 20; //0-59
byte hour = 22; //0-23
byte weekDay = 2; //1-7
byte monthDay = 17; //1-31
byte month = 10; //1-12
byte year = 11; //0-99
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekDay));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(zero); //start
Wire.endTransmission();
}
byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void printDate(){
}
void loop () {
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
//print the date EG 3/1/11 23:59:59
Serial.print(month);
Serial.print("/");
Serial.print(monthDay);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);
if (second == 0 & second == 1 & second == 2 & second == 3 ){
disp1 . write (hour) ;
disp1 . clearDisp () ;
disp2 . write (minute);
disp2.clearDisp ();
}
if (second == 4 && 5 && 6 && 7 ){
disp1 . write (monthDay) ;
disp1 . clearDisp () ;
disp2 . write (month);
disp2.clearDisp ();
}
AND means that all of the conditions must be true, OR means that any of the conditions must be true, so you want OR, not AND.
I assume that second could be any integer 0, 1, 2, ... 58, 59, so there are 30 conditions to check (actually twice as many, see below). Doable but painful. second%4 will be 0, 1, 2, or 3. I suggest using the modulo operator like this:
if ((second%4)<2) {
or this:
if ((second%4)>1) {
The problem is, you cannot determine an eight second cycle (four seconds of time, and four seconds of date) by just using seconds. 60 divided by 8 is not an integer. You would need to know whether the minutes are odd or even as well. I did not want to complicate things this way, so I changed the definition to a four second cycle (two seconds of time, and two seconds of date).
Certainly, this is not going to work:
if (second == 0 & second == 1 & second == 2 & second == 3 ){
and neither will this:
if (second == 4 && 5 && 6 && 7 ){
(These will not work for reasons beyond the simple AND versus OR but I do not want to go into them here.)
Post on this forum if you really really want an eight second cycle and want the more complicated suggestion.
.
Aah, so do you really need a 12 second cycle? Four seconds of time, four seconds of date, and four seconds of temperature? That would be nice because 60 seconds divided by 12 is an integer (5). If this is the case, use
if ((second%12)<4) {
or, where appropriate
if ((second%12)>7) {
or even
if (((second%12)>3) && ((second%12)<8)) {
(That last one could be changed to avoid calculating second%12 twice but that is left as an exercise for the reader or for the compiler.)
This is much easier than having to deal with 60 and 8.
can somebody write to me the last part of the code, how these three things should be displayed on the display in the easiest way,to be turned on for 4 seconds each .
For seven days I can not manage to solve this
can somebody write to me the last part of the code, how these three things should be displayed on the display in the easiest way,to be turned on for 4 seconds each .
time - clock
data
temp
For seven days I can not manage to solve this
thanks in advance
#include <SevenSeg.h>
#include <Wire.h>
#define DEV_ID 0x90 >> 1
#include "Wire.h"
#define DS1307_ADDRESS 0x68
SevenSeg disp1(2,3,4,5,6,9,8);
SevenSeg disp2(2,3,4,5,6,9,8);
const int numOfDigits1 = 2;
const int numOfDigits2 = 2;
int digitPins1 [ numOfDigits1 ]={10,11};
int digitPins2 [ numOfDigits2 ]={12,13};
byte zero = 0x00; //workaround for issue #527
void setup () {
Wire.begin();
Wire.beginTransmission(DEV_ID); // connect to DS1621 (#0)
Wire.write(0xAC); // Access Config
Wire.write(0x02); // set for continuous conversion
Wire.beginTransmission(DEV_ID); // restart
Wire.write(0xEE); // start conversions
Wire.endTransmission();
Wire.begin();
Serial.begin(9600);
setDateTime();
disp1 . setDigitPins ( numOfDigits1 , digitPins1 );
disp1 . setDigitDelay (3000) ;
disp2 . setDigitPins ( numOfDigits2 , digitPins2 );
disp2 . setDigitDelay (3000) ;
}
void setDateTime(){
byte second = 0; //0-59
byte minute = 50; //0-59
byte hour = 17; //0-23
byte weekDay = 2; //1-7
byte monthDay = 31; //1-31
byte month = 10; //1-12
byte year = 17; //0-99
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekDay));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(zero); //start
Wire.endTransmission();
}
byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void printDate(){
}
void loop () {
int tempC = 0;
// give time for measurement
Wire.beginTransmission(DEV_ID);
Wire.write(0xAA); // read temperature
Wire.endTransmission();
Wire.requestFrom(DEV_ID, 1); // request one byte from DS1621
tempC = Wire.read(); // get whole degrees readin
Serial.println(tempC);
Serial.println();
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
//print the date EG 3/1/11 23:59:59
Serial.print(month);
Serial.print("/");
Serial.print(monthDay);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);
if (((second%12)>3) && ((second%12)<8)) {
disp1 . write (hour) ;
disp1 . clearDisp () ;
disp2 . write (minute);
disp2.clearDisp ();
} if ((second%10)<5) {
disp1 . write (monthDay) ;
disp1 . clearDisp () ;
disp2 . write (month);
disp2.clearDisp ();
}
if ((second%10)<5) {
disp1 . write (tempC);
disp1 . clearDisp ();
}
}
This is the circuit diagram for a DS1307 based RTC Clock System. It may be helpful for you. The clock is running at a set time. The control program is attached.
You have to: 1. Multiplex the Date. How? Please figure it out. 2. Multiplex Temp from TWI device BMP180. How? Please figure it out.