forked from luon/wordclock
Added get/set date + lightsensor reading, bugfixes
Added commands to get / set date from rtc. Added commands to get current and average reading from light sensor. Fixed bug in display mode 'round'.
This commit is contained in:
parent
6ac27a1183
commit
9db65799da
|
@ -233,11 +233,10 @@ void displaytime_round(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// now we can illuminate the extra minute LEDs
|
// now we can illuminate the extra minute LEDs
|
||||||
|
if ((n+30-((n/(5*60))*(5*60))) / 60 == 1) { LED1; }
|
||||||
if ((minute-(minute/5)*5)==1) { LED1; }
|
if ((n+30-((n/(5*60))*(5*60))) / 60 == 2) { LED1; LED2; }
|
||||||
if ((minute-(minute/5)*5)==2) { LED1; LED2; }
|
if ((n+30-((n/(5*60))*(5*60))) / 60 == 3) { LED3; LED4; }
|
||||||
if ((minute-(minute/5)*5)==3) { LED3; LED4; }
|
if ((n+30-((n/(5*60))*(5*60))) / 60 == 4) { LED4; }
|
||||||
if ((minute-(minute/5)*5)==4) { LED4; }
|
|
||||||
|
|
||||||
// WriteLEDs();
|
// WriteLEDs();
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,7 @@ void SWversion(void);
|
||||||
// scale the brightness levels to something closer to avoid having to work with
|
// scale the brightness levels to something closer to avoid having to work with
|
||||||
// floating point numbers
|
// floating point numbers
|
||||||
|
|
||||||
|
unsigned int year = 2010, month = 4, day = 28, day_week = 1;
|
||||||
int hour=12, minute=0, second=0;
|
int hour=12, minute=0, second=0;
|
||||||
// incremented the second counter
|
// incremented the second counter
|
||||||
int count;
|
int count;
|
||||||
|
@ -73,6 +74,8 @@ char Display1=0, Display2=0, Display3=0, Led1=0, Led2=0, Led3=0, Led4=0;
|
||||||
int OldHardware = 0; // 1 = we are running on old hardware
|
int OldHardware = 0; // 1 = we are running on old hardware
|
||||||
int BTNActive = 1; // the sense of the button inputs (Changes based on hardware type)
|
int BTNActive = 1; // the sense of the button inputs (Changes based on hardware type)
|
||||||
int timercount=10; // used for interrupt counting to determine the brightnes of the display
|
int timercount=10; // used for interrupt counting to determine the brightnes of the display
|
||||||
|
unsigned long int lightlevel_avg;
|
||||||
|
unsigned long int lightlevel_sample;
|
||||||
|
|
||||||
// hardware constants
|
// hardware constants
|
||||||
int LEDClockPin=5; // Arduino Pin#11 - 4094 Pin 3 clock
|
int LEDClockPin=5; // Arduino Pin#11 - 4094 Pin 3 clock
|
||||||
|
@ -307,6 +310,10 @@ void setup()
|
||||||
if (DS1302Present==1) {
|
if (DS1302Present==1) {
|
||||||
// Get the current time and date from the chip
|
// Get the current time and date from the chip
|
||||||
Time t = rtc.time();
|
Time t = rtc.time();
|
||||||
|
year = t.yr;
|
||||||
|
month = t.mon;
|
||||||
|
day = t.date;
|
||||||
|
day_week = t.day;
|
||||||
second=t.sec;
|
second=t.sec;
|
||||||
minute=t.min;
|
minute=t.min;
|
||||||
hour=t.hr;
|
hour=t.hr;
|
||||||
|
@ -392,6 +399,7 @@ void incrementtime(void)
|
||||||
minute=0;
|
minute=0;
|
||||||
if (++hour == 25) {
|
if (++hour == 25) {
|
||||||
hour=1;
|
hour=1;
|
||||||
|
// should we increment date here as well?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* // debug outputs
|
/* // debug outputs
|
||||||
|
@ -404,7 +412,6 @@ void incrementtime(void)
|
||||||
Serial.print(":");
|
Serial.print(":");
|
||||||
Serial.print(second);
|
Serial.print(second);
|
||||||
Serial.print(" ");*/
|
Serial.print(" ");*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SWversion(void)
|
void SWversion(void)
|
||||||
|
@ -476,7 +483,7 @@ void process_buttons(unsigned char button_status)
|
||||||
// flash doesnt happen when setting time
|
// flash doesnt happen when setting time
|
||||||
if (DS1302Present==1) {
|
if (DS1302Present==1) {
|
||||||
// Make a new time object to set the date and time
|
// Make a new time object to set the date and time
|
||||||
Time t(2010, 04, 28, hour, minute, second, 01);
|
Time t(year, month, day, hour, minute, second, day_week);
|
||||||
// Set the time and date on the chip
|
// Set the time and date on the chip
|
||||||
rtc.time(t);
|
rtc.time(t);
|
||||||
}
|
}
|
||||||
|
@ -502,7 +509,7 @@ void process_buttons(unsigned char button_status)
|
||||||
|
|
||||||
if (DS1302Present==1) {
|
if (DS1302Present==1) {
|
||||||
// Make a new time object to set the date and time
|
// Make a new time object to set the date and time
|
||||||
Time t(2010, 04, 28, hour, minute, second, 01);
|
Time t(year, month, day, hour, minute, second, day_week);
|
||||||
// Set the time and date on the chip
|
// Set the time and date on the chip
|
||||||
rtc.time(t);
|
rtc.time(t);
|
||||||
}
|
}
|
||||||
|
@ -525,7 +532,7 @@ void process_buttons(unsigned char button_status)
|
||||||
|
|
||||||
static int uart_thread(struct pt *pt)
|
static int uart_thread(struct pt *pt)
|
||||||
{
|
{
|
||||||
char cmd, arg1, arg2, arg3;
|
unsigned char cmd, arg1, arg2, arg3;
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
PT_BEGIN(pt);
|
PT_BEGIN(pt);
|
||||||
|
@ -564,16 +571,25 @@ static int uart_thread(struct pt *pt)
|
||||||
switch(arg1)
|
switch(arg1)
|
||||||
{
|
{
|
||||||
case 'Y':
|
case 'Y':
|
||||||
// set year
|
// set year, assuming offset of
|
||||||
|
// 2000
|
||||||
|
year = 2000 + 10 * (arg2 - 0x30) +
|
||||||
|
(arg3 - 0x30);
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
// set month
|
// set month
|
||||||
|
month = 10 * (arg2 - 0x30) +
|
||||||
|
(arg3 - 0x30);
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
// set day of month
|
// set day of month
|
||||||
|
day = 10 * (arg2 - 0x30) +
|
||||||
|
(arg3 - 0x30);
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
// set day of week
|
// set day of week
|
||||||
|
// Sunday == 1, Saturday == 7
|
||||||
|
day_week = arg2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -595,10 +611,12 @@ static int uart_thread(struct pt *pt)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the time and date on the chip
|
if (DS1302Present==1) {
|
||||||
Time t(2010, 4, 28, hour, minute,
|
// Set the time and date on the chip
|
||||||
second, 1);
|
Time t(year, month, day, hour,
|
||||||
rtc.time(t);
|
minute, second, day_week);
|
||||||
|
rtc.time(t);
|
||||||
|
}
|
||||||
displaytime();
|
displaytime();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -614,15 +632,23 @@ static int uart_thread(struct pt *pt)
|
||||||
{
|
{
|
||||||
case 'Y':
|
case 'Y':
|
||||||
// get year
|
// get year
|
||||||
|
Serial.print("g: Y: ");
|
||||||
|
Serial.println(year);
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
// get month
|
// get month
|
||||||
|
Serial.print("g: M: ");
|
||||||
|
Serial.println(month);
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
// get day of month
|
// get day of month
|
||||||
|
Serial.print("g: D: ");
|
||||||
|
Serial.println(day);
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
// get day of week
|
// get day of week
|
||||||
|
Serial.print("g: d: ");
|
||||||
|
Serial.println(day_week);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -646,6 +672,33 @@ static int uart_thread(struct pt *pt)
|
||||||
Serial.print(0, DEC);
|
Serial.print(0, DEC);
|
||||||
Serial.println(second);
|
Serial.println(second);
|
||||||
break;
|
break;
|
||||||
|
case 'I':
|
||||||
|
//get ambient light intensity
|
||||||
|
if (length < 2)
|
||||||
|
Serial.println("E: too few arguments");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arg2 = inputBuffer.charAt(2);
|
||||||
|
switch(arg2)
|
||||||
|
{
|
||||||
|
case 'c':
|
||||||
|
// get current value
|
||||||
|
Serial.print("g: Ic: ");
|
||||||
|
Serial.println(lightlevel_sample,
|
||||||
|
DEC);
|
||||||
|
break;
|
||||||
|
case 'a':
|
||||||
|
// get average
|
||||||
|
Serial.print("g: Ia: ");
|
||||||
|
Serial.println(lightlevel_avg,
|
||||||
|
DEC);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Serial.println("E: unknown argument for command I");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -692,8 +745,6 @@ static int buttons_thread(struct pt *pt)
|
||||||
static int lightsensor_thread(struct pt *pt)
|
static int lightsensor_thread(struct pt *pt)
|
||||||
{
|
{
|
||||||
static unsigned long msTick =0; // the number of Millisecond Ticks since we last
|
static unsigned long msTick =0; // the number of Millisecond Ticks since we last
|
||||||
static unsigned long int lightlevel_avg;
|
|
||||||
unsigned long int lightlevel_sample;
|
|
||||||
static char millisWillOverflow = 0;
|
static char millisWillOverflow = 0;
|
||||||
static char n_lightlevel_samples = 0;
|
static char n_lightlevel_samples = 0;
|
||||||
|
|
||||||
|
@ -742,12 +793,14 @@ static int lightsensor_thread(struct pt *pt)
|
||||||
|
|
||||||
current_brightness = ambient_light_to_brightness[lightlevel_avg];
|
current_brightness = ambient_light_to_brightness[lightlevel_avg];
|
||||||
|
|
||||||
|
#if (PRINT_DEBUG_LEVEL <= 0)
|
||||||
Serial.print("D: lightsensor: ");
|
Serial.print("D: lightsensor: ");
|
||||||
Serial.print(lightlevel_sample);
|
Serial.print(lightlevel_sample);
|
||||||
Serial.print(", avg: ");
|
Serial.print(", avg: ");
|
||||||
Serial.print(lightlevel_avg);
|
Serial.print(lightlevel_avg);
|
||||||
Serial.print(", brightness: ");
|
Serial.print(", brightness: ");
|
||||||
Serial.println(current_brightness);
|
Serial.println(current_brightness);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
PT_END(pt);
|
PT_END(pt);
|
||||||
|
@ -817,7 +870,10 @@ static int wordclock_thread(struct pt *pt)
|
||||||
second++;
|
second++;
|
||||||
|
|
||||||
//test to see if we need to increment the time counters
|
//test to see if we need to increment the time counters
|
||||||
if ((second==60) || (second == 30))
|
if (second == 30)
|
||||||
|
displaytime();
|
||||||
|
|
||||||
|
if (second == 60)
|
||||||
{
|
{
|
||||||
incrementtime();
|
incrementtime();
|
||||||
displaytime();
|
displaytime();
|
||||||
|
@ -840,6 +896,10 @@ static int wordclock_thread(struct pt *pt)
|
||||||
if (DS1302Present==1) {
|
if (DS1302Present==1) {
|
||||||
// Get the current time and date from the chip
|
// Get the current time and date from the chip
|
||||||
Time t = rtc.time();
|
Time t = rtc.time();
|
||||||
|
year = t.yr;
|
||||||
|
month = t.mon;
|
||||||
|
day = t.date;
|
||||||
|
day_week = t.day;
|
||||||
second=t.sec;
|
second=t.sec;
|
||||||
minute=t.min;
|
minute=t.min;
|
||||||
hour=t.hr;
|
hour=t.hr;
|
||||||
|
|
Loading…
Reference in New Issue