mirror of
https://github.com/deruiter/DCF77-Analyzer-Clock-V2.0.git
synced 2025-11-04 16:17:45 +01:00
Added credits ;)
This commit is contained in:
@@ -26,8 +26,17 @@
|
|||||||
Erik de Ruiter
|
Erik de Ruiter
|
||||||
2014
|
2014
|
||||||
|
|
||||||
|
Edit:
|
||||||
|
2014-12-01 changed code to accomodate Adafruit Audio FX Sound Board for Chime sound
|
||||||
|
|
||||||
*/
|
|
||||||
|
CREDITS:
|
||||||
|
I learned a lot from the work of Matthias Dalheimer and Thijs Elenbaas who made their own DCF77 decoders.
|
||||||
|
Without their work I would not have known where to start.
|
||||||
|
I ended up writing my own code (using bits and pieces of their ideas) so I could understand what is happening...
|
||||||
|
My code is far, very far from efficient or advanced but it does work and I know what is going on.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------------
|
||||||
// Libraries
|
// Libraries
|
||||||
@@ -46,19 +55,19 @@
|
|||||||
//STREAMING.h .................................................... http://arduiniana.org/libraries/streaming/
|
//STREAMING.h .................................................... http://arduiniana.org/libraries/streaming/
|
||||||
/*
|
/*
|
||||||
New users sometimes wonder why the “Arduino language” doesn’t provide the kind
|
New users sometimes wonder why the “Arduino language” doesn’t provide the kind
|
||||||
of concatenation or streaming operations they have become accustomed to in Java/VB/C#/C++, etc.
|
of concatenation or streaming operations they have become accustomed to in Java/VB/C#/C++, etc.
|
||||||
lcd << "GPS #" << gpsno << " date: " << day << "-" << month << "-" << year << endl;
|
lcd << "GPS #" << gpsno << " date: " << day << "-" << month << "-" << year << endl;
|
||||||
This library works for any class that derives from Print:
|
This library works for any class that derives from Print:
|
||||||
Serial << "Counter: " << counter;
|
Serial << "Counter: " << counter;
|
||||||
lcd << "Temp: " << t.get_temperature() << " degrees";
|
lcd << "Temp: " << t.get_temperature() << " degrees";
|
||||||
my_pstring << "Hi Mom!" << endl;
|
my_pstring << "Hi Mom!" << endl;
|
||||||
With the new library you can also use formatting manipulators like this:
|
With the new library you can also use formatting manipulators like this:
|
||||||
Serial << "Byte value: " << _HEX(b) << endl;
|
Serial << "Byte value: " << _HEX(b) << endl;
|
||||||
lcd << "The key pressed was " << _BYTE(c) << endl;
|
lcd << "The key pressed was " << _BYTE(c) << endl;
|
||||||
This syntax is familiar to many, is easy to read and learn, and, importantly, *** consumes no resources ***
|
This syntax is familiar to many, is easy to read and learn, and, importantly, *** consumes no resources ***
|
||||||
(Because the operator functions are essentially just inline aliases for their print() counterparts,
|
(Because the operator functions are essentially just inline aliases for their print() counterparts,
|
||||||
no sketch gets larger or consumes more RAM as a result of their inclusion.)
|
no sketch gets larger or consumes more RAM as a result of their inclusion.)
|
||||||
*/
|
*/
|
||||||
#include <Streaming.h>
|
#include <Streaming.h>
|
||||||
// OneWire lets you access 1-wire devices made by Maxim/Dallas,
|
// OneWire lets you access 1-wire devices made by Maxim/Dallas,
|
||||||
// such as DS18S20, DS18B20, DS1822 .............................. http://www.pjrc.com/teensy/td_libs_OneWire.html
|
// such as DS18S20, DS18B20, DS1822 .............................. http://www.pjrc.com/teensy/td_libs_OneWire.html
|
||||||
@@ -85,14 +94,14 @@ OneWire ds(8); // define Onewire instance DS on pin 8
|
|||||||
values between 10..15 are printed as their hexadecimal equivalent
|
values between 10..15 are printed as their hexadecimal equivalent
|
||||||
lc.setChar(int addr, int digit, char value, boolean dp) ....... will display: 0 1 2 3 4 5 6 7 8 9 A B C D E F H L P; - . , _ <SPACE> (the blank or space char)
|
lc.setChar(int addr, int digit, char value, boolean dp) ....... will display: 0 1 2 3 4 5 6 7 8 9 A B C D E F H L P; - . , _ <SPACE> (the blank or space char)
|
||||||
|
|
||||||
pin 12/7 is connected to the DataIn
|
pin 12/7 is connected to the DataIn
|
||||||
pin 11/6 is connected to the CLK
|
pin 11/6 is connected to the CLK
|
||||||
pin 10/5 is connected to CS/LOAD
|
pin 10/5 is connected to CS/LOAD
|
||||||
|
|
||||||
***** Please set the number of devices you have *****
|
***** Please set the number of devices you have *****
|
||||||
But the maximum default of 8 MAX72XX wil also work.
|
But the maximum default of 8 MAX72XX wil also work.
|
||||||
LedConrol(DATAIN, CLOCK, CS/LOAD, NUMBER OF MAXIM CHIPS)
|
LedConrol(DATAIN, CLOCK, CS/LOAD, NUMBER OF MAXIM CHIPS)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// lc is for the Maxim Common CATHODE displays
|
// lc is for the Maxim Common CATHODE displays
|
||||||
LedControl lc = LedControl(12, 11, 10, 8, false); // Define pins for Maxim 72xx and how many 72xx we use
|
LedControl lc = LedControl(12, 11, 10, 8, false); // Define pins for Maxim 72xx and how many 72xx we use
|
||||||
@@ -110,12 +119,16 @@ LedControl lc1 = LedControl(7, 6, 5, 1, true); // Define pins for Maxim 72xx and
|
|||||||
#define DCFSyncTime 1600 // defines 2000 ms pulse for end of sequence
|
#define DCFSyncTime 1600 // defines 2000 ms pulse for end of sequence
|
||||||
|
|
||||||
// define Arduino Pins
|
// define Arduino Pins
|
||||||
#define BUZZER A1 // Piezo buzzer on Analog port
|
#define BUZZER A1 // OUTPUT: Piezo buzzer on Analog port
|
||||||
|
#define CHIMESWITCHPIN A2 // INPUT: Chime on/off switch
|
||||||
|
#define CHIMEPIN A3 // OUTPUT: Chime Activate LOW=CHIME ON
|
||||||
#define DCF_INTERRUPT 0 // Interrupt number associated with pin
|
#define DCF_INTERRUPT 0 // Interrupt number associated with pin
|
||||||
#define DCF77PIN 2 // Connection pin to DCF 77 device. Must be pin 2 or 3!
|
#define SPEAKERVOLPIN 13 // After power on, set the speaker volume of the Adafruit Adio Board via this pin
|
||||||
#define CHIMEPIN 3 // switch CHIME ON/OFF
|
#define DCF77PIN 2 // INPUT: Connection pin to DCF 77 device. Must be pin 2 or 3!
|
||||||
#define DCF77SOUNDPIN 4 // switch DCF77 Sound ON/OFF
|
#define NOTUSEDPIN 3 // INPUT: not used at this moment
|
||||||
#define TEMPRESETPIN 9 // Push button to reset min/max temp memory
|
#define DCF77SOUNDPIN 4 // INPUT: Switch DCF77 Sound ON/OFF
|
||||||
|
#define TEMPRESETPIN 9 // INPUT: Push button to reset min/max temp memory
|
||||||
|
|
||||||
|
|
||||||
// define miscellaneous parameters
|
// define miscellaneous parameters
|
||||||
#define DEBUG_FLOW 0 // 1 = show info about functions calls
|
#define DEBUG_FLOW 0 // 1 = show info about functions calls
|
||||||
@@ -149,6 +162,9 @@ LedControl lc1 = LedControl(7, 6, 5, 1, true); // Define pins for Maxim 72xx and
|
|||||||
#define BrightnessMaximDcfTime 4
|
#define BrightnessMaximDcfTime 4
|
||||||
#define BrightnessMaximBufferBitError 15
|
#define BrightnessMaximBufferBitError 15
|
||||||
|
|
||||||
|
// After power on, set the speaker volume of the Adafruit Adio Board via this pin
|
||||||
|
#define SPEAKERVOLUME 12
|
||||||
|
|
||||||
// definition of Status/Error Led's. Use division and modulo to seperate Row/Col values!!
|
// definition of Status/Error Led's. Use division and modulo to seperate Row/Col values!!
|
||||||
// to lit a LED you need a ROW and COLUMN value.
|
// to lit a LED you need a ROW and COLUMN value.
|
||||||
// so, for example: BFLed/10 results in the value '1' (row)
|
// so, for example: BFLed/10 results in the value '1' (row)
|
||||||
@@ -156,27 +172,27 @@ LedControl lc1 = LedControl(7, 6, 5, 1, true); // Define pins for Maxim 72xx and
|
|||||||
|
|
||||||
/* Row/Col LED numbers of Maxim 7219 chip
|
/* Row/Col LED numbers of Maxim 7219 chip
|
||||||
Row Col
|
Row Col
|
||||||
Sunday 0 0
|
Sunday 0 0
|
||||||
Monday 0 1
|
Monday 0 1
|
||||||
Tuesday 0 2
|
Tuesday 0 2
|
||||||
Wednesday 0 3
|
Wednesday 0 3
|
||||||
Thursday 0 4
|
Thursday 0 4
|
||||||
Friday 0 5
|
Friday 0 5
|
||||||
Saturday 0 6
|
Saturday 0 6
|
||||||
Synced 0 7
|
Synced 0 7
|
||||||
RTCError 1 0
|
RTCError 1 0
|
||||||
SummerTime 1 1
|
SummerTime 1 1
|
||||||
WinterTime 1 2
|
WinterTime 1 2
|
||||||
LeapYear 1 3
|
LeapYear 1 3
|
||||||
BF 1 4
|
BF 1 4
|
||||||
EoM 1 5
|
EoM 1 5
|
||||||
EoB 1 6
|
EoB 1 6
|
||||||
rPW 1 7
|
rPW 1 7
|
||||||
rPT 2 0
|
rPT 2 0
|
||||||
DCFOk 2 1
|
DCFOk 2 1
|
||||||
Chime 2 2
|
Chime 2 2
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#define SyncedLed 07
|
#define SyncedLed 07
|
||||||
#define RTCError 10
|
#define RTCError 10
|
||||||
#define SummerTimeLed 11
|
#define SummerTimeLed 11
|
||||||
@@ -207,15 +223,16 @@ unsigned char previousSignalState;
|
|||||||
|
|
||||||
// DCF Buffers and indicators
|
// DCF Buffers and indicators
|
||||||
static int DCFbitBuffer[59]; // here, the received DCFbits are stored
|
static int DCFbitBuffer[59]; // here, the received DCFbits are stored
|
||||||
const int bitValue[] = {1, 2, 4, 8, 10, 20, 40, 80}; // these are the decimal values of the received DCFbits
|
const int bitValue[] = {
|
||||||
|
1, 2, 4, 8, 10, 20, 40, 80}; // these are the decimal values of the received DCFbits
|
||||||
|
|
||||||
/* not used at this moment
|
/* not used at this moment
|
||||||
// Inserted a 'null' value ("") because an array starts with position zero '0' and I need it to start at '1'
|
// Inserted a 'null' value ("") because an array starts with position zero '0' and I need it to start at '1'
|
||||||
const char dayNameLong[][10] = {"", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"};
|
const char dayNameLong[][10] = {"", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"};
|
||||||
const char dayNameShort[][3] = {"", "Ma", "Di", "Wo", "Do", "Vr", "Za", "Zo"};
|
const char dayNameShort[][3] = {"", "Ma", "Di", "Wo", "Do", "Vr", "Za", "Zo"};
|
||||||
const char monthNameLong [][10] = {"", "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"};
|
const char monthNameLong [][10] = {"", "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"};
|
||||||
const char monthNameShort [][4] = {"", "Jan", "Feb", "Mrt", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"};
|
const char monthNameShort [][4] = {"", "Jan", "Feb", "Mrt", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int bufferPosition = 0;
|
static int bufferPosition = 0;
|
||||||
static int endOfMinute = 0;
|
static int endOfMinute = 0;
|
||||||
@@ -245,11 +262,8 @@ int weekNumber; //Returns the number of the week in the year
|
|||||||
int errorCounter = 0;
|
int errorCounter = 0;
|
||||||
|
|
||||||
// miscelleanous variables
|
// miscelleanous variables
|
||||||
boolean Chime = 0;
|
boolean daytimeChange = 1;
|
||||||
boolean daytime = 0;
|
boolean dayTime = 0;
|
||||||
int loopTime = 0; // check Loop() timing
|
|
||||||
|
|
||||||
//buzzer related
|
|
||||||
boolean chimeSwitch = 0;
|
boolean chimeSwitch = 0;
|
||||||
boolean dcf77SoundSwitch = 0;
|
boolean dcf77SoundSwitch = 0;
|
||||||
|
|
||||||
@@ -274,12 +288,14 @@ void setup()
|
|||||||
// initialize Serial communication
|
// initialize Serial communication
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
// define DCF77PIN as input
|
pinMode(DCF77PIN, INPUT); // define DCF77PIN as input
|
||||||
pinMode(DCF77PIN, INPUT);
|
pinMode(NOTUSEDPIN, INPUT); // define pin to shut off display as input
|
||||||
// define pin to shut off display as input
|
pinMode(TEMPRESETPIN, INPUT); // define pin to reset High / Low temperature memory
|
||||||
pinMode(CHIMEPIN, INPUT);
|
pinMode(DCF77SOUNDPIN, INPUT); // define pin for switch to shut off second beep sound
|
||||||
pinMode(TEMPRESETPIN, INPUT);
|
pinMode(CHIMESWITCHPIN, OUTPUT); // output to activate hourly chime sound
|
||||||
pinMode(DCF77SOUNDPIN, INPUT);
|
pinMode(CHIMEPIN, OUTPUT); // output to activate ticking sound
|
||||||
|
pinMode(SPEAKERVOLPIN, OUTPUT); // output to set LOWER speaker volume on startup
|
||||||
|
digitalWrite(SPEAKERVOLPIN, LOW);
|
||||||
|
|
||||||
// Initialize all variables and LED displays
|
// Initialize all variables and LED displays
|
||||||
initialize();
|
initialize();
|
||||||
@@ -293,11 +309,21 @@ void setup()
|
|||||||
if (timeStatus() != timeSet)
|
if (timeStatus() != timeSet)
|
||||||
{ // Unable to sync with the RTC - activate RTCError LED
|
{ // Unable to sync with the RTC - activate RTCError LED
|
||||||
lc.setLed(MaximLeds, RTCError / 10, RTCError % 10, true);
|
lc.setLed(MaximLeds, RTCError / 10, RTCError % 10, true);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// RTC has set the system time - dim RTCError LED
|
// RTC has set the system time - dim RTCError LED
|
||||||
lc.setLed(MaximLeds, RTCError / 10, RTCError % 10, false);
|
lc.setLed(MaximLeds, RTCError / 10, RTCError % 10, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// After power on, set the speaker volume of the Adafruit Adio Board
|
||||||
|
for(int i=0; i<=SPEAKERVOLUME; i++)
|
||||||
|
{
|
||||||
|
digitalWrite(SPEAKERVOLPIN, HIGH);
|
||||||
|
delay(100);
|
||||||
|
digitalWrite(SPEAKERVOLPIN, LOW);
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
// use for test purposes
|
// use for test purposes
|
||||||
//setTime(23, 59, 40, 31, 12, 13);
|
//setTime(23, 59, 40, 31, 12, 13);
|
||||||
//RTC.set(now());
|
//RTC.set(now());
|
||||||
@@ -325,6 +351,10 @@ void loop()
|
|||||||
// display 'HI' and 'LO' temperature on specific moments
|
// display 'HI' and 'LO' temperature on specific moments
|
||||||
switch (second())
|
switch (second())
|
||||||
{
|
{
|
||||||
|
case 5:
|
||||||
|
// hourly chime OFF
|
||||||
|
digitalWrite(CHIMEPIN, HIGH);
|
||||||
|
break;
|
||||||
case 30:
|
case 30:
|
||||||
// display 'HI' on display for Hi temperature
|
// display 'HI' on display for Hi temperature
|
||||||
lc1.clearDisplay(MaximDcfTime); // clear display
|
lc1.clearDisplay(MaximDcfTime); // clear display
|
||||||
@@ -361,8 +391,12 @@ void loop()
|
|||||||
lc1.setColumn(MaximDcfTime, 3, B01001110); // Display 'C' (Celcius) character. Binary pattern to lite up individual segments in this order is: .ABCDEFG
|
lc1.setColumn(MaximDcfTime, 3, B01001110); // Display 'C' (Celcius) character. Binary pattern to lite up individual segments in this order is: .ABCDEFG
|
||||||
lc1.setColumn(MaximDcfTime, 2, B00111110); // Display 'O' (Celcius) character. Binary pattern to lite up individual segments in this order is: .ABCDEFG
|
lc1.setColumn(MaximDcfTime, 2, B00111110); // Display 'O' (Celcius) character. Binary pattern to lite up individual segments in this order is: .ABCDEFG
|
||||||
break;
|
break;
|
||||||
// display current temperature
|
case 58:
|
||||||
|
// hourly chime ACTIVATE
|
||||||
|
if(chimeSwitch == 1 && dayTime == 1 && minute() == 59) digitalWrite(CHIMEPIN, LOW);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
// display current temperature
|
||||||
displayTemp();
|
displayTemp();
|
||||||
break;
|
break;
|
||||||
} //switch
|
} //switch
|
||||||
@@ -385,15 +419,15 @@ void loop()
|
|||||||
// display date, week LED's, week nr etc. if time is changed
|
// display date, week LED's, week nr etc. if time is changed
|
||||||
if (minute() != previousMinute)
|
if (minute() != previousMinute)
|
||||||
{
|
{
|
||||||
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
// DISPLAY SHUTS DOWN FROM 8 PM UNTIL 8 AM
|
||||||
|
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
// DISPLAY SHUTS DOWN FROM 11 PM UNTIL 8 AM
|
|
||||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
// check wether it is Day- or Nighttime
|
// check wether it is Day- or Nighttime
|
||||||
if (hour() >= 8 && hour() < 23)
|
if (hour() >= 8 && hour() < 21)
|
||||||
{
|
{
|
||||||
// it's DAYTIME so time to activate displays
|
// it's DAYTIME so time to activate displays
|
||||||
if (daytime == 0) // wake up displays is only once needed so check variable...
|
if (daytimeChange == 1) // test variable because daytime routine is needed only once
|
||||||
{
|
{
|
||||||
// activate all the displays and status LED's
|
// activate all the displays and status LED's
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
@@ -402,34 +436,42 @@ void loop()
|
|||||||
} //for
|
} //for
|
||||||
// Maxim Common Anode
|
// Maxim Common Anode
|
||||||
lc1.shutdown(0, false); // Common Anode display wake up
|
lc1.shutdown(0, false); // Common Anode display wake up
|
||||||
} //if
|
} //if (daytimeChange == 0)
|
||||||
|
|
||||||
daytime = 1; // set daytime variable to TRUE so display activation is disabled
|
daytimeChange = 0; // set variable so daytime routine is performed only once
|
||||||
|
dayTime = 1;
|
||||||
displayData(); // display date, week LED's, week nr etc.
|
displayData(); // display date, week LED's, week nr etc.
|
||||||
} //if
|
|
||||||
|
} //if (hour() >= 8 && hour() < 21)
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
{
|
{
|
||||||
daytime = 0; // 'reset' variable so display wakeup is performed when daytime is reached
|
// it's NIGHTTIME so time to deactivate displays
|
||||||
// time to shut down displays at night to save power...
|
if (daytimeChange == 0) // test variable because nighttime routine is needed only once
|
||||||
|
{
|
||||||
|
// deactivate all the displays and status LED's
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
lc.shutdown(i, true); // display shut down
|
lc.shutdown(i, true); // Common Cathode displays wakeup
|
||||||
} //for
|
} //for
|
||||||
// Maxim Common Anode
|
// Maxim Common Anode
|
||||||
lc1.shutdown(0, true); // display shut down
|
lc1.shutdown(0, true); // Common Anode display wake up
|
||||||
|
} //if (daytimeChange == 0)
|
||||||
|
|
||||||
|
dayTime = 0;
|
||||||
|
daytimeChange = 1; // set variable so nighttime routine is performed only once
|
||||||
|
|
||||||
} //else
|
} //else
|
||||||
|
|
||||||
//display the DCF time
|
|
||||||
//displayDCFTime();
|
|
||||||
previousMinute = minute();
|
previousMinute = minute();
|
||||||
}
|
|
||||||
|
|
||||||
|
} //if (minute() != previousMinute)
|
||||||
|
|
||||||
|
|
||||||
// reset errorCounter display every hour
|
// reset errorCounter display every hour
|
||||||
if (dcfHour != previousHour)
|
if (dcfHour != previousHour)
|
||||||
{
|
{
|
||||||
// reser errorCounter to '0' every hour
|
|
||||||
errorCounter = 0;
|
errorCounter = 0;
|
||||||
ledDisplay(MaximBufferBitError, "R", 0);
|
ledDisplay(MaximBufferBitError, "R", 0);
|
||||||
previousHour = dcfHour;
|
previousHour = dcfHour;
|
||||||
@@ -460,7 +502,7 @@ void loop()
|
|||||||
| 0 | | 1 | | 0 | | 0 | | 1 |
|
| 0 | | 1 | | 0 | | 0 | | 1 |
|
||||||
| | | | | | | | | |
|
| | | | | | | | | |
|
||||||
| | | | | | | | | |
|
| | | | | | | | | |
|
||||||
______| |_______________| |___________| |___________________________________| |_______________| |__ _ _ _
|
______| |_______________| |___________| |___________________________________| |_______________| |__ _ _ _
|
||||||
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
|
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
|
||||||
1000 2100 2000 2200 3000 3100 NO PULSE 5000 5100 6000 6200 << example millis() value
|
1000 2100 2000 2200 3000 3100 NO PULSE 5000 5100 6000 6200 << example millis() value
|
||||||
= end of Minute indication
|
= end of Minute indication
|
||||||
@@ -473,7 +515,7 @@ ______| |_______________| |___________| |_____________________________
|
|||||||
|
|
||||||
^
|
^
|
||||||
flanktime
|
flanktime
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -819,6 +861,9 @@ void initialize(void)
|
|||||||
trailingEdge = 0;
|
trailingEdge = 0;
|
||||||
previousLeadingEdge = 0;
|
previousLeadingEdge = 0;
|
||||||
bufferPosition = 0;
|
bufferPosition = 0;
|
||||||
|
|
||||||
|
digitalWrite(CHIMEPIN, HIGH); // Set Chimepin to default state
|
||||||
|
|
||||||
// Reset DCFbitBuffer array, positions 0-58 (=59 bits)
|
// Reset DCFbitBuffer array, positions 0-58 (=59 bits)
|
||||||
for (int i = 0; i < 59; i++) {
|
for (int i = 0; i < 59; i++) {
|
||||||
DCFbitBuffer[i] = 0;
|
DCFbitBuffer[i] = 0;
|
||||||
@@ -910,7 +955,7 @@ void displayBuffer(String message)
|
|||||||
//
|
//
|
||||||
// ledDisplay on Maxim 8 digit displays
|
// ledDisplay on Maxim 8 digit displays
|
||||||
//
|
//
|
||||||
// calles from processBuffer
|
// called from processBuffer
|
||||||
//================================================================================================================
|
//================================================================================================================
|
||||||
void ledDisplay(int addr, String leftOrRight, int value)
|
void ledDisplay(int addr, String leftOrRight, int value)
|
||||||
{
|
{
|
||||||
@@ -964,16 +1009,14 @@ void checkSwitches(void)
|
|||||||
|
|
||||||
|
|
||||||
//read state of switch CHIME
|
//read state of switch CHIME
|
||||||
chimeSwitch = digitalRead(CHIMEPIN);
|
chimeSwitch = digitalRead(CHIMESWITCHPIN);
|
||||||
|
|
||||||
if (chimeSwitch == 1)
|
if (chimeSwitch == 1)
|
||||||
{
|
{
|
||||||
Chime = 1;
|
|
||||||
lc.setLed(MaximLeds, ChimeLed / 10, ChimeLed % 10, true);
|
lc.setLed(MaximLeds, ChimeLed / 10, ChimeLed % 10, true);
|
||||||
} // if
|
} // if
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Chime = 0;
|
|
||||||
lc.setLed(MaximLeds, ChimeLed / 10, ChimeLed % 10, false);
|
lc.setLed(MaximLeds, ChimeLed / 10, ChimeLed % 10, false);
|
||||||
} // else
|
} // else
|
||||||
|
|
||||||
@@ -1027,20 +1070,20 @@ int error(int errorLed)
|
|||||||
/*
|
/*
|
||||||
Code from: http://forum.arduino.cc/index.php/topic,44476.0.html
|
Code from: http://forum.arduino.cc/index.php/topic,44476.0.html
|
||||||
|
|
||||||
you need to declare two global variables:
|
you need to declare two global variables:
|
||||||
Code:
|
Code:
|
||||||
short dayNumber; //Returns the number of day in the year
|
short dayNumber; //Returns the number of day in the year
|
||||||
short weekNumber; //Returns the number of the week in the year
|
short weekNumber; //Returns the number of the week in the year
|
||||||
|
|
||||||
and this is how you need to call the function in your loop:
|
and this is how you need to call the function in your loop:
|
||||||
Code:
|
Code:
|
||||||
dayWeekNumber(year(),month(),day(),weekday());
|
dayWeekNumber(year(),month(),day(),weekday());
|
||||||
|
|
||||||
Take into account that i use TIME library in my sketch, so how you call to year, month, day and day of week could change for other libraries.
|
Take into account that i use TIME library in my sketch, so how you call to year, month, day and day of week could change for other libraries.
|
||||||
|
|
||||||
and this is an example of how to call the function and show the results:
|
and this is an example of how to call the function and show the results:
|
||||||
Code:
|
Code:
|
||||||
dayWeekNumber(year(),month(),day(),weekday());
|
dayWeekNumber(year(),month(),day(),weekday());
|
||||||
Serial.print("Day #");
|
Serial.print("Day #");
|
||||||
Serial.print(dayNumber);
|
Serial.print(dayNumber);
|
||||||
Serial.print(" at week # ");
|
Serial.print(" at week # ");
|
||||||
@@ -1048,15 +1091,16 @@ dayWeekNumber(year(),month(),day(),weekday());
|
|||||||
Serial.print(" of ");
|
Serial.print(" of ");
|
||||||
Serial.println(year());
|
Serial.println(year());
|
||||||
|
|
||||||
Be aware than in the function, there is a problematic line:
|
Be aware than in the function, there is a problematic line:
|
||||||
Code:
|
Code:
|
||||||
WN = (DN-7+10)/7;
|
WN = (DN-7+10)/7;
|
||||||
This is because in the library the week starts on Sunday (0), however, in the ISO standard,
|
This is because in the library the week starts on Sunday (0), however, in the ISO standard,
|
||||||
week start on monday (1), and sunday is the last day (7). For that reason, i included this especial case in the code.
|
week start on monday (1), and sunday is the last day (7). For that reason, i included this especial case in the code.
|
||||||
*/
|
*/
|
||||||
int dayWeekNumber(int y, int m, int d, int w)
|
int dayWeekNumber(int y, int m, int d, int w)
|
||||||
{
|
{
|
||||||
int days[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; // Number of days at the beginning of the month in a (not leap) year.
|
int days[] = {
|
||||||
|
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; // Number of days at the beginning of the month in a (not leap) year.
|
||||||
//Start to calculate the number of day
|
//Start to calculate the number of day
|
||||||
if (m == 1 || m == 2) {
|
if (m == 1 || m == 2) {
|
||||||
//for any type of year, it calculate the number of days for January or february
|
//for any type of year, it calculate the number of days for January or february
|
||||||
@@ -1092,15 +1136,16 @@ int dayWeekNumber(int y, int m, int d, int w)
|
|||||||
//================================================================================================================
|
//================================================================================================================
|
||||||
|
|
||||||
/*****
|
/*****
|
||||||
Purpose: Determine if a given year is a leap year
|
* Purpose: Determine if a given year is a leap year
|
||||||
Parameters: int year // The year to test
|
* Parameters: int year // The year to test
|
||||||
Return value: int // '1' if the year is a leap year, '0'otherwise
|
* Return value: int // '1' if the year is a leap year, '0'otherwise
|
||||||
*****/
|
*****/
|
||||||
int calculateLeapYear(int year)
|
int calculateLeapYear(int year)
|
||||||
{
|
{
|
||||||
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
|
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1114,15 +1159,6 @@ int calculateLeapYear(int year)
|
|||||||
void displayData(void)
|
void displayData(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
// sound buzzer on whole hour
|
|
||||||
if (minute() == 00 && Chime == 1)
|
|
||||||
{
|
|
||||||
// beep-beep on whole hour
|
|
||||||
tone(BUZZER, 4000, 180);
|
|
||||||
delay (250);
|
|
||||||
tone(BUZZER, 4000, 180);
|
|
||||||
}
|
|
||||||
|
|
||||||
// display Day of Week on LED's
|
// display Day of Week on LED's
|
||||||
// first, clear all the 'Day' Led's (row '0') before displaying new value
|
// first, clear all the 'Day' Led's (row '0') before displaying new value
|
||||||
for (int i = 0; i < 7; i++) {
|
for (int i = 0; i < 7; i++) {
|
||||||
@@ -1174,9 +1210,10 @@ void displayData(void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// display Summer- or Wintertime LED
|
// display Summer- or Wintertime LED
|
||||||
if (dcfDST = 1) {
|
if (dcfDST == 1) {
|
||||||
lc.setLed(MaximLeds, SummerTimeLed / 10, SummerTimeLed % 10, true);
|
lc.setLed(MaximLeds, SummerTimeLed / 10, SummerTimeLed % 10, true);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
lc.setLed(MaximLeds, WinterTimeLed / 10, WinterTimeLed % 10, true);
|
lc.setLed(MaximLeds, WinterTimeLed / 10, WinterTimeLed % 10, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1291,16 +1328,16 @@ void displayTemp(void)
|
|||||||
lc1.setChar(MaximDcfTime, 5, 1, false); // activate top dot
|
lc1.setChar(MaximDcfTime, 5, 1, false); // activate top dot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
//================================================================================================================
|
|
||||||
//
|
|
||||||
// writeScratchpad - change data in memory of DS18B20 sensor
|
|
||||||
//
|
|
||||||
// USE ONLY once in LOOP() IF YOU WANT TO CHANGE RESOLUTION
|
|
||||||
//================================================================================================================
|
//================================================================================================================
|
||||||
|
//
|
||||||
|
// writeScratchpad - change data in memory of DS18B20 sensor
|
||||||
|
//
|
||||||
|
// USE ONLY once in LOOP() IF YOU WANT TO CHANGE RESOLUTION
|
||||||
|
//================================================================================================================
|
||||||
|
|
||||||
void writeScratchpad(void)
|
void writeScratchpad(void)
|
||||||
{
|
{
|
||||||
// This is done ONCE in setup()
|
// This is done ONCE in setup()
|
||||||
|
|
||||||
// INITIALIZATION
|
// INITIALIZATION
|
||||||
@@ -1310,7 +1347,8 @@ void writeScratchpad(void)
|
|||||||
ds.reset(); // The initialization sequence consists of a reset pulse transmitted by the bus master followed by presence pulse(s) transmitted by the slave(s).
|
ds.reset(); // The initialization sequence consists of a reset pulse transmitted by the bus master followed by presence pulse(s) transmitted by the slave(s).
|
||||||
|
|
||||||
// Select a specific DS18x20 device
|
// Select a specific DS18x20 device
|
||||||
byte addr[8] = {0x28, 0x13, 0x95, 0x7B, 0x05, 0x00, 0x00, 0x70};
|
byte addr[8] = {
|
||||||
|
0x28, 0x13, 0x95, 0x7B, 0x05, 0x00, 0x00, 0x70 };
|
||||||
ds.select(addr);
|
ds.select(addr);
|
||||||
|
|
||||||
// WRITE SCRATCHPAD
|
// WRITE SCRATCHPAD
|
||||||
@@ -1322,7 +1360,7 @@ void writeScratchpad(void)
|
|||||||
|
|
||||||
ds.write(0); // write zero into the alarm register HIGH
|
ds.write(0); // write zero into the alarm register HIGH
|
||||||
ds.write(0); // write zero into the alarm register LOW
|
ds.write(0); // write zero into the alarm register LOW
|
||||||
/* and write R1 and R2 into the configuration register to select the precision of the temperature
|
/* and write R1 and R2 into the configuration register to select the precision of the temperature
|
||||||
R1/R2 value | resolution | conversion time | increments
|
R1/R2 value | resolution | conversion time | increments
|
||||||
HEX DEC
|
HEX DEC
|
||||||
0 0 0 = 9 bits | 93,75 ms | 0,5 Celsius
|
0 0 0 = 9 bits | 93,75 ms | 0,5 Celsius
|
||||||
@@ -1333,7 +1371,7 @@ void writeScratchpad(void)
|
|||||||
------ Bit ------
|
------ Bit ------
|
||||||
7 6 5 4 3 2 1 0
|
7 6 5 4 3 2 1 0
|
||||||
0 R1 R0 1 1 1 1 1
|
0 R1 R0 1 1 1 1 1
|
||||||
*/
|
|
||||||
// CURRENT SETTING:
|
// CURRENT SETTING:
|
||||||
ds.write(0 << 5); // << 5 means shift value 5 positions to the left. ds.write(B00011111) does the same
|
ds.write(0 << 5); // << 5 means shift value 5 positions to the left. ds.write(B00011111) does the same
|
||||||
|
|
||||||
@@ -1346,5 +1384,163 @@ void writeScratchpad(void)
|
|||||||
// If the device is being used in parasite power mode, within 10μs (max) after this command is issued the master must
|
// If the device is being used in parasite power mode, within 10μs (max) after this command is issued the master must
|
||||||
// enable a strong pullup on the 1-Wire bus for at least 10ms as described in the Powering the DS18B20 section.
|
// enable a strong pullup on the 1-Wire bus for at least 10ms as described in the Powering the DS18B20 section.
|
||||||
ds.write(0x48);
|
ds.write(0x48);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//================================================================================================================
|
||||||
|
//
|
||||||
|
// ARCHIVE
|
||||||
|
//
|
||||||
|
//================================================================================================================
|
||||||
|
|
||||||
|
|
||||||
|
Basic Usage of Onewire Library
|
||||||
|
|
||||||
|
|
||||||
|
OneWire myWire(pin)
|
||||||
|
Create the OneWire object, using a specific pin. Even though you can connect many 1 wire devices to the same pin, if you have a large number, smaller groups each on their own pin can help isolate wiring problems. You can create multiple OneWire objects, one for each pin.
|
||||||
|
|
||||||
|
myWire.search(addrArray)
|
||||||
|
Search for the next device. The addrArray is an 8 byte array. If a device is found, addrArray is filled with the device's address and true is returned. If no more devices are found, false is returned.
|
||||||
|
|
||||||
|
myWire.reset_search()
|
||||||
|
Begin a new search. The next use of search will begin at the first device.
|
||||||
|
|
||||||
|
myWire.reset()
|
||||||
|
Reset the 1-wire bus. Usually this is needed before communicating with any device.
|
||||||
|
|
||||||
|
myWire.select(addrArray)
|
||||||
|
Select a device based on its address. After a reset, this is needed to choose which device you will use, and then all communication will be with that device, until another reset.
|
||||||
|
|
||||||
|
myWire.skip()
|
||||||
|
Skip the device selection. This only works if you have a single device, but you can avoid searching and use this to immediatly access your device.
|
||||||
|
|
||||||
|
myWire.write(num);
|
||||||
|
Write a byte.
|
||||||
|
|
||||||
|
myWire.write(num, 1);
|
||||||
|
Write a byte, and leave power applied to the 1 wire bus.
|
||||||
|
|
||||||
|
myWire.read()
|
||||||
|
Read a byte.
|
||||||
|
|
||||||
|
myWire.crc8(dataArray, length)
|
||||||
|
Compute a CRC check on an array of data.
|
||||||
|
|
||||||
|
|
||||||
|
//================================================================================================================
|
||||||
|
|
||||||
|
|
||||||
|
#include "Wire.h"
|
||||||
|
#define DS1307_I2C_ADDRESS 0x68
|
||||||
|
// 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) );
|
||||||
|
}
|
||||||
|
// Stops the DS1307, but it has the side effect of setting seconds to 0
|
||||||
|
// Probably only want to use this for testing
|
||||||
|
/*void stopDs1307()
|
||||||
|
{
|
||||||
|
Wire.beginTransmission(DS1307_I2C_ADDRESS);
|
||||||
|
Wire.send(0);
|
||||||
|
Wire.send(0x80);
|
||||||
|
Wire.endTransmission();
|
||||||
|
}
|
||||||
|
// 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());
|
||||||
|
}
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
|
||||||
|
Wire.begin();
|
||||||
|
Serial.begin(9600);
|
||||||
|
// Change these values to what you want to set your clock to.
|
||||||
|
// You probably only want to set your clock once and then remove
|
||||||
|
// the setDateDs1307 call.
|
||||||
|
second = 45;
|
||||||
|
minute = 3;
|
||||||
|
hour = 7;
|
||||||
|
dayOfWeek = 5;
|
||||||
|
dayOfMonth = 17;
|
||||||
|
month = 4;
|
||||||
|
year = 8;
|
||||||
|
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
|
||||||
|
}
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
|
||||||
|
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
|
||||||
|
Serial.print(hour, DEC);
|
||||||
|
Serial.print(":");
|
||||||
|
Serial.print(minute, DEC);
|
||||||
|
Serial.print(":");
|
||||||
|
Serial.print(second, DEC);
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.print(month, DEC);
|
||||||
|
Serial.print("/");
|
||||||
|
Serial.print(dayOfMonth, DEC);
|
||||||
|
Serial.print("/");
|
||||||
|
Serial.print(year, DEC);
|
||||||
|
Serial.print(" Day_of_week:");
|
||||||
|
Serial.println(dayOfWeek, DEC);
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//================================================================================================================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user