mirror of
https://github.com/KevinMidboe/Arduino.git
synced 2025-10-29 17:40:11 +00:00
Init commit with many years of arduino sketches and projects. I dont know if the esp8266 includes much, but there are also libraries. I hope they dont have crazy automatic versioning through the Arduino IDE.
This commit is contained in:
222
Projects/ST_Two_Small_Clock/ST2_Main/ST2_Main.ino
Normal file
222
Projects/ST_Two_Small_Clock/ST2_Main/ST2_Main.ino
Normal file
@@ -0,0 +1,222 @@
|
||||
//*******************************************************************************************************************
|
||||
// Main Loop
|
||||
//*******************************************************************************************************************
|
||||
void loop()
|
||||
{
|
||||
// Test for Sleep ------------------------------------------------*
|
||||
|
||||
currentMillis = millis();
|
||||
OptionModeFlag = false;
|
||||
|
||||
if(((currentMillis - SleepTimer) > SleepLimit) && SleepEnable)
|
||||
{
|
||||
|
||||
if(STATE= 1) // New for ST Desk Clock - goto Time vs Sleep
|
||||
{
|
||||
SUBSTATE = 1;
|
||||
blinkON = true;
|
||||
blinkFlag = false;
|
||||
blinkMin = false;
|
||||
blinkHour = false;
|
||||
}else
|
||||
{
|
||||
STATE= 1; // was STATE= 99;
|
||||
SUBSTATE = 0;
|
||||
}
|
||||
|
||||
SleepTimer = millis();
|
||||
|
||||
}
|
||||
|
||||
// Test for Mode Button Press ------------------------------------*
|
||||
|
||||
bval = !digitalRead(MODEBUTTON);
|
||||
if(bval)
|
||||
{
|
||||
if(ALARMON)
|
||||
{
|
||||
CheckAlarm();
|
||||
}
|
||||
|
||||
if(ALARM1FLAG)
|
||||
{
|
||||
ALARM1FLAG = false;
|
||||
ALARMON = false;
|
||||
EnableAlarm1(false);
|
||||
STATE = 90;
|
||||
JustWokeUpFlag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(JustWokeUpFlag)
|
||||
{
|
||||
JustWokeUpFlag = false;
|
||||
JustWokeUpFlag2 = true; // Used to supress "Time" text from showing when waking up.
|
||||
}
|
||||
else
|
||||
{
|
||||
NextStateRequest = true;
|
||||
}
|
||||
// SUBSTATE = 99;
|
||||
|
||||
while(bval)
|
||||
{
|
||||
bval = !digitalRead(SETBUTTON);
|
||||
if(bval)
|
||||
{
|
||||
OptionModeFlag = true;
|
||||
NextStateRequest = false;
|
||||
NextSUBStateRequest = false;
|
||||
displayString("SPEC");
|
||||
delay(300);
|
||||
}
|
||||
bval = !digitalRead(MODEBUTTON);
|
||||
}
|
||||
|
||||
delay(100);
|
||||
SleepTimer = millis();
|
||||
}
|
||||
}
|
||||
|
||||
// Test for SET Button Press ------------------------------------*
|
||||
|
||||
bval = !digitalRead(SETBUTTON);
|
||||
if(bval && !OptionModeFlag)
|
||||
{
|
||||
NextSUBStateRequest = true;
|
||||
|
||||
while(bval)
|
||||
{
|
||||
|
||||
bval = !digitalRead(MODEBUTTON);
|
||||
if(bval)
|
||||
{
|
||||
OptionModeFlag = true;
|
||||
NextStateRequest = false;
|
||||
NextSUBStateRequest = false;
|
||||
displayString("SPEC");
|
||||
delay(300);
|
||||
}
|
||||
|
||||
|
||||
bval = !digitalRead(SETBUTTON);
|
||||
}
|
||||
delay(100);
|
||||
SleepTimer = millis();
|
||||
}
|
||||
|
||||
// Running Blink counter ------------------------------------*
|
||||
if(blinkFlag)
|
||||
{
|
||||
blinkCounter = blinkCounter +1;
|
||||
if(blinkCounter >blinkTime) // was 150
|
||||
{
|
||||
blinkON = !blinkON;
|
||||
blinkCounter = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
blinkON = true; // Not blinking, just leave the LEDs lit
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Main Loop - State Machine
|
||||
//*******************************************************************************************************************
|
||||
|
||||
switch (STATE)
|
||||
{
|
||||
case 0: // Set-Up
|
||||
STATE = 1;
|
||||
break;
|
||||
|
||||
case 1: // Display Time
|
||||
DisplayTimeSub();
|
||||
break;
|
||||
|
||||
case 2: // Set Time
|
||||
setAlarmSub();
|
||||
break;
|
||||
|
||||
case 3: // Config Alarm
|
||||
setTimeSub();
|
||||
break;
|
||||
|
||||
case 4: // Stop Watch
|
||||
StopWatch();
|
||||
break;
|
||||
|
||||
|
||||
case 5: // Serial Display
|
||||
DisplaySerialData();
|
||||
break;
|
||||
|
||||
case 6: // Graphic Demo
|
||||
graphican();
|
||||
break;
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
case 90: // Alarm Triggered
|
||||
|
||||
blinkFlag = true;
|
||||
displayString("Beep");
|
||||
|
||||
if(blinkON)
|
||||
{
|
||||
pinMode(SETBUTTON, OUTPUT);
|
||||
tone(SETBUTTON,4000) ;
|
||||
delay(100);
|
||||
noTone(SETBUTTON);
|
||||
digitalWrite(SETBUTTON, HIGH);
|
||||
}
|
||||
|
||||
#if ARDUINO >= 101
|
||||
pinMode(SETBUTTON, INPUT_PULLUP);
|
||||
// digitalWrite(SETBUTTON, HIGH);
|
||||
#else
|
||||
// digitalWrite(SETBUTTON, HIGH);
|
||||
pinMode(SETBUTTON, INPUT);
|
||||
#endif
|
||||
delay(250);
|
||||
|
||||
// bval = !digitalRead(SETBUTTON);
|
||||
if(NextSUBStateRequest | NextStateRequest)
|
||||
{
|
||||
STATE = 0;
|
||||
SUBSTATE = 0;
|
||||
// NextStateFlag = true;
|
||||
NextStateRequest = false;
|
||||
NextSUBStateRequest = false;
|
||||
blinkFlag = false;
|
||||
}
|
||||
break;
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
case 99: // Sleep
|
||||
displayString("Nite");
|
||||
delay(500);
|
||||
clearmatrix();
|
||||
GoToSleep();
|
||||
SleepTimer = millis();
|
||||
STATE = 0;
|
||||
SUBSTATE = 0;
|
||||
break;
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// End of Main Loop
|
||||
//*******************************************************************************************************************
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
170
Projects/ST_Two_Small_Clock/ST2_Matrix/ST2_Matrix.ino
Normal file
170
Projects/ST_Two_Small_Clock/ST2_Matrix/ST2_Matrix.ino
Normal file
@@ -0,0 +1,170 @@
|
||||
//*******************************************************************************************************************
|
||||
// Called by Timer 1 Interrupt to draw next column in LED matrix
|
||||
//*******************************************************************************************************************
|
||||
// Only light one ROW (and one column) ie one pixel at a time. = lower current draw, but lower refresh rate.
|
||||
|
||||
|
||||
void LEDupdateTWO() // ONE ROW of selected column at a time
|
||||
{
|
||||
|
||||
if(ROWBITINDEX >6)
|
||||
{
|
||||
Mcolumn = Mcolumn+1; // Prep for next column
|
||||
if(Mcolumn >19)
|
||||
{
|
||||
Mcolumn =0;
|
||||
}
|
||||
|
||||
PORTB = (PORTB & B10000000); // Clear last column
|
||||
PORTC = (PORTC & B11110000) | B00001111;
|
||||
|
||||
if(Mcolumn <16) // Matrix column (from 0 to 19)
|
||||
{
|
||||
PORTB = (PORTB & B01111111); //| (0<<PORTB7); // Decode digit Col. 1 to 16 - Select De-Mux chip
|
||||
|
||||
PORTD = (PORTD & B00001111) | (Mcolumn << 4); // Decode address to 74HC154
|
||||
}
|
||||
else
|
||||
{
|
||||
PORTB = (1<<PORTB7); // Decode digit Col. 17 to 20 - UN-Select De-Mux chip
|
||||
|
||||
PORTC = (PORTC & B11110000) | ~(1<<(Mcolumn-16)); // Using PC0 to PC4 to address col. 17 to 20 directly
|
||||
}
|
||||
|
||||
ROWBITINDEX = 0;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
PORTB = (PORTB & B10000000);
|
||||
if(bitRead(LEDMAT[Mcolumn],ROWBITINDEX))
|
||||
{
|
||||
// PORTB = (PORTB & B10000000);
|
||||
bitSet(PORTB,ROWBITINDEX);
|
||||
}
|
||||
|
||||
if(Mcolumn <16) // Matrix column (from 0 to 19)
|
||||
{
|
||||
delayMicroseconds(120);
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// bitClear(PORTB,ROWBITINDEX);
|
||||
// }
|
||||
|
||||
ROWBITINDEX = ROWBITINDEX +1;
|
||||
}
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Called by Timer 1 Interrupt to draw next column in LED matrix
|
||||
//*******************************************************************************************************************
|
||||
// This version of LED refresh / drawing lights full column at once = higher current draw (but can be brighter)
|
||||
|
||||
void LEDupdate() // All ROWs of selected column at the same time
|
||||
{
|
||||
|
||||
PORTB = (PORTB & B10000000); // Clear last column
|
||||
PORTC = (PORTC & B11110000) | B00001111;
|
||||
|
||||
if(Mcolumn <16) // Matrix column (from 0 to 19)
|
||||
{
|
||||
PORTB = (PORTB & B01111111); //| (0<<PORTB7); // Decode digit Col. 1 to 16 - Select De-Mux chip
|
||||
|
||||
PORTD = (PORTD & B00001111) | (Mcolumn << 4); // Decode address to 74HC154
|
||||
}
|
||||
else
|
||||
{
|
||||
PORTB = (1<<PORTB7); // Decode digit Col. 17 to 20 - UN-Select De-Mux chip
|
||||
|
||||
PORTC = (PORTC & B11110000) | ~(1<<(Mcolumn-16)); // Using PC0 to PC4 to address col. 17 to 20 directly
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
PORTB = (PORTB & B10000000) | (LEDMAT[Mcolumn]); // Light LEDs - turn on ROWs
|
||||
|
||||
// ---
|
||||
|
||||
Mcolumn = Mcolumn+1; // Prep for next column
|
||||
if(Mcolumn >19)
|
||||
{
|
||||
Mcolumn =0;
|
||||
}
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Used by STII Small Desk Clock
|
||||
//*******************************************************************************************************************
|
||||
// Only light one ROW (and one column) ie one pixel at a time. = lower current draw, but lower refresh rate.
|
||||
|
||||
|
||||
// Where:
|
||||
// PORTC2 - S1 (ADC1)
|
||||
// PORTC3 - S2 (ADC2)
|
||||
// When S1=H and S2=L Decoder 1 = Selected
|
||||
// When S1=L and S2=H Decoder 2 = Selected
|
||||
// When S1=L and S2=L Decoder 3 = Selected
|
||||
// When S1=H and S2=H None Selected = all columns are OFF
|
||||
|
||||
// PORTD4 - A
|
||||
// PORTD5 - B
|
||||
// PORTD6 - C
|
||||
// PORTD7 - Free pin (only with the "Small desk clock")
|
||||
|
||||
// PORTB 0 to 6 = ROWS 1 to 7
|
||||
|
||||
void LEDupdateTHREE() // ONE ROW of selected column at a time
|
||||
{
|
||||
|
||||
if(ROWBITINDEX >6)
|
||||
{
|
||||
ROWBITINDEX = 0;
|
||||
|
||||
Mcolumn = Mcolumn+1; // Prep for next column
|
||||
if(Mcolumn >19)
|
||||
{
|
||||
Mcolumn =0;
|
||||
}
|
||||
|
||||
// PORTB = (PORTB & B10000000); // Clear last column
|
||||
PORTB = (PORTB & B10000000);
|
||||
PORTC = (PORTC & B11110011) | B00001100; // Turn off decoders
|
||||
|
||||
|
||||
|
||||
if(Mcolumn < 8) // Matrix column (from 0 to 7)
|
||||
{
|
||||
PORTD = (PORTD & B10001111) | (Mcolumn << 4); // Decode address to 74HC138
|
||||
PORTC = (PORTC & B11110011) | B00000100; // Select Chip 1
|
||||
}
|
||||
|
||||
if(Mcolumn > 7 && Mcolumn < 16)
|
||||
{
|
||||
PORTD = (PORTD & B10001111) | ((Mcolumn - 8) << 4); // Decode address to 74HC138
|
||||
PORTC = (PORTC & B11110011) | B00001000; // Select Chip 2
|
||||
}
|
||||
|
||||
if(Mcolumn > 15)
|
||||
{
|
||||
PORTD = (PORTD & B10001111) | ((Mcolumn - 16) << 4); // Decode address to 74HC138
|
||||
PORTC = (PORTC & B11110011); // Select Chip 3
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// PORTB = (PORTB & B10000000);
|
||||
PORTB = (PORTB & B10000000);
|
||||
if(bitRead(LEDMAT[Mcolumn],ROWBITINDEX))
|
||||
{
|
||||
// PORTB = (PORTB & B10000000);
|
||||
bitSet(PORTB,ROWBITINDEX);
|
||||
}
|
||||
|
||||
ROWBITINDEX = ROWBITINDEX +1;
|
||||
|
||||
delayMicroseconds(50); // Test to see if this makes LEDs brighter
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
526
Projects/ST_Two_Small_Clock/ST2_RTC/ST2_RTC.ino
Normal file
526
Projects/ST_Two_Small_Clock/ST2_RTC/ST2_RTC.ino
Normal file
@@ -0,0 +1,526 @@
|
||||
//*******************************************************************************************************************
|
||||
// Check Time
|
||||
//*******************************************************************************************************************
|
||||
void checktime()
|
||||
{
|
||||
uint8_t temp =0;
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_SEC);
|
||||
SecOnes = i2cData & B00001111; //
|
||||
|
||||
SecTens = i2cData & B01110000; //
|
||||
SecTens = SecTens >> 4;
|
||||
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_MIN);
|
||||
MinOnes = i2cData & B00001111; //
|
||||
|
||||
MinTens = i2cData & B01110000; //
|
||||
MinTens = MinTens >> 4;
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_HOUR);
|
||||
HourOnes = i2cData & B00001111; //
|
||||
|
||||
TH_Not24_flag = bitRead(i2cData, 6); // False on RTC when 24 mode selected
|
||||
PM_NotAM_flag = bitRead(i2cData, 5);
|
||||
|
||||
if(TH_Not24_flag == true)
|
||||
{
|
||||
HourTens = i2cData & B00010000; //
|
||||
HourTens = HourTens >> 4;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
HourTens = i2cData & B00110000; //
|
||||
HourTens = HourTens >> 4;
|
||||
}
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Check Date
|
||||
//*******************************************************************************************************************
|
||||
void checkDate()
|
||||
{
|
||||
|
||||
int temp = 0;
|
||||
I2C_RX(RTCDS1337,RTC_DAY);
|
||||
Days = i2cData & B00000111; //
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_MONTH);
|
||||
MonthCode = i2cData & B00001111; //
|
||||
|
||||
temp = (i2cData & B00010000) >> 4;
|
||||
if(temp)
|
||||
{
|
||||
MonthCode = MonthCode +10; // Convert BCD month into interger month
|
||||
}
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_DATE);
|
||||
DateOnes = i2cData & B00001111; //
|
||||
DateTens = (i2cData & B00110000) >> 4;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// SET Time - NEW
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void settimeNEW(uint8_t setselect) // both min digits or both hour digits (advance one at a time)
|
||||
{
|
||||
uint8_t temp =0;
|
||||
switch(setselect)
|
||||
{
|
||||
|
||||
case 1:
|
||||
MinOnes = MinOnes +1;
|
||||
if(MinOnes >9)
|
||||
{
|
||||
MinOnes = 0;
|
||||
|
||||
MinTens = MinTens +1;
|
||||
if(MinTens >5)
|
||||
{
|
||||
MinTens = 0;
|
||||
}
|
||||
|
||||
// temp = (MinTens << 4) + MinOnes;
|
||||
// I2C_TX(RTCDS1337,RTC_MIN,temp);
|
||||
}
|
||||
|
||||
temp = (MinTens << 4) + MinOnes;
|
||||
I2C_TX(RTCDS1337,RTC_MIN,temp);
|
||||
break;
|
||||
|
||||
|
||||
// -----------------------------------------------
|
||||
|
||||
case 2:
|
||||
HourOnes = HourOnes +1;
|
||||
|
||||
if(TH_Not24_flag)
|
||||
// 12 hours mode increment
|
||||
{
|
||||
|
||||
if(HourOnes >9 )
|
||||
{
|
||||
HourOnes = 0;
|
||||
HourTens = 1;
|
||||
}
|
||||
|
||||
if((HourOnes ==2) && (HourTens == 1))
|
||||
{
|
||||
PM_NotAM_flag = !PM_NotAM_flag;
|
||||
}
|
||||
|
||||
if((HourOnes >2) && (HourTens == 1))
|
||||
{
|
||||
// PM_NotAM_flag = !PM_NotAM_flag;
|
||||
HourTens = 0;
|
||||
HourOnes = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
// 24 hours mode increment - S
|
||||
{
|
||||
|
||||
if((HourOnes >9) && (HourTens < 2))
|
||||
{
|
||||
HourOnes = 0;
|
||||
HourTens = HourTens +1;
|
||||
}
|
||||
|
||||
if((HourTens ==2) && (HourOnes == 4))
|
||||
{
|
||||
HourOnes = 0;
|
||||
HourTens = 0;
|
||||
}
|
||||
}
|
||||
// 24 hours mode increment - E
|
||||
|
||||
temp = (HourTens << 4) + HourOnes;
|
||||
if(TH_Not24_flag)
|
||||
{
|
||||
bitWrite(temp, 5, PM_NotAM_flag);
|
||||
}
|
||||
|
||||
bitWrite(temp, 6, TH_Not24_flag);
|
||||
I2C_TX(RTCDS1337,RTC_HOUR,temp);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
Days = Days +1 ;
|
||||
if(Days>7)
|
||||
{
|
||||
Days = 1;
|
||||
}
|
||||
temp = Days & B00000111; //
|
||||
I2C_TX(RTCDS1337,RTC_DAY,temp);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
temp = 0;
|
||||
MonthCode = MonthCode +1 ;
|
||||
if(MonthCode >12)
|
||||
{
|
||||
MonthCode = 1;
|
||||
}
|
||||
if(MonthCode>9)
|
||||
{
|
||||
temp = MonthCode - 10;
|
||||
// MonthCode = MonthCode & B00001111;
|
||||
bitSet(temp, 4); // Convert int to BCD
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = MonthCode & B00001111;
|
||||
}
|
||||
|
||||
I2C_TX(RTCDS1337,RTC_MONTH,temp);
|
||||
break;
|
||||
|
||||
case 5: // Date
|
||||
|
||||
// I2C_RX(RTCDS1337,RTC_DATE);
|
||||
// DateOnes = i2cData & B00001111;
|
||||
// DateTens = (i2cData & B00110000) >> 4;
|
||||
DateOnes = DateOnes + 1;
|
||||
if((DateTens == 3) && (DateOnes > 1))
|
||||
{
|
||||
DateOnes = 1;
|
||||
DateTens =0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(DateOnes>9)
|
||||
{
|
||||
DateOnes = 0;
|
||||
DateTens = DateTens +1;
|
||||
}
|
||||
}
|
||||
temp = (DateOnes & B00001111) | ((DateTens << 4) & B00110000);
|
||||
I2C_TX(RTCDS1337,RTC_DATE,temp);
|
||||
break;
|
||||
|
||||
case 6: // year
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// 12:00 Start Time
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void SetStartTime()
|
||||
{
|
||||
uint8_t temp =0;
|
||||
|
||||
HourTens = 1;
|
||||
HourOnes = 2;
|
||||
temp = (HourTens << 4) + HourOnes;
|
||||
bitWrite(temp, 5, PM_NotAM_flag);
|
||||
bitWrite(temp, 6, TH_Not24_flag);
|
||||
|
||||
I2C_TX(RTCDS1337,RTC_HOUR,temp);
|
||||
|
||||
MinTens = 0;
|
||||
MinOnes = 0;
|
||||
temp = (MinTens << 4) + MinOnes;
|
||||
I2C_TX(RTCDS1337,RTC_MIN,temp);
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// SET Alarm
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void SetAlarmTime() // Just for testing set to 12:01 PM
|
||||
{
|
||||
uint8_t temp =0;
|
||||
|
||||
HourTens = 1;
|
||||
HourOnes = 2;
|
||||
temp = (HourTens << 4) + HourOnes;
|
||||
bitWrite(temp, 5, A_PM_NotAM_flag);
|
||||
bitWrite(temp, 6, A_TH_Not24_flag);
|
||||
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1HOUR,temp);
|
||||
|
||||
MinTens = 0;
|
||||
MinOnes = 1;
|
||||
temp = (MinTens << 4) + MinOnes;
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1MIN,temp);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Check Alarm
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void CheckAlarm()
|
||||
{
|
||||
uint8_t temp =0;
|
||||
I2C_RX(RTCDS1337,RTCSTATUS);
|
||||
ALARM1FLAG = bitRead(i2cData, 0);
|
||||
|
||||
if(ALARM1FLAG)
|
||||
{
|
||||
temp =i2cData;
|
||||
bitClear(temp, 0);
|
||||
I2C_TX(RTCDS1337,RTCSTATUS,temp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Enable Alarm
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void EnableAlarm1(boolean onoff) // Trigger on Hours & Minutes Match
|
||||
{
|
||||
uint8_t temp =0;
|
||||
|
||||
// Adjust for Hours - Minutes Trigger -S
|
||||
I2C_RX(RTCDS1337,RTC_ALARM1SEC);
|
||||
temp =i2cData;
|
||||
bitClear(temp, 7);
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1SEC,temp);
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_ALARM1MIN);
|
||||
temp =i2cData;
|
||||
bitClear(temp, 7);
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1MIN,temp);
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_ALARM1HOUR);
|
||||
temp =i2cData;
|
||||
bitClear(temp, 7);
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1HOUR,temp);
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_ALARM1DATE);
|
||||
temp =i2cData;
|
||||
bitSet(temp, 7);
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1DATE,temp);
|
||||
// Adjust for Hours - Minutes Trigger -E
|
||||
|
||||
I2C_RX(RTCDS1337,RTCCONT); // Enable Alarm Pin on RTC
|
||||
temp =i2cData;
|
||||
|
||||
if(onoff)
|
||||
{
|
||||
bitSet(temp, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
bitClear(temp, 0);
|
||||
}
|
||||
I2C_TX(RTCDS1337,RTCCONT,temp);
|
||||
|
||||
I2C_RX(RTCDS1337,RTCSTATUS); // Clear Alarm RTC internal Alarm Flag
|
||||
temp =i2cData;
|
||||
bitClear(temp, 0);
|
||||
I2C_TX(RTCDS1337,RTCSTATUS,temp);
|
||||
}
|
||||
//*******************************************************************************************************************
|
||||
// SET ALARM TIME
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void setAlarm(uint8_t setselect) // both min digits or both hour digits (advance one at a time)
|
||||
{
|
||||
uint8_t temp =0;
|
||||
switch(setselect)
|
||||
{
|
||||
|
||||
case 1:
|
||||
AMinOnes = AMinOnes +1;
|
||||
if(AMinOnes >9)
|
||||
{
|
||||
AMinOnes = 0;
|
||||
|
||||
AMinTens = AMinTens +1;
|
||||
if(AMinTens >5)
|
||||
{
|
||||
AMinTens = 0;
|
||||
}
|
||||
}
|
||||
|
||||
temp = (AMinTens << 4) + AMinOnes;
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1MIN,temp);
|
||||
break;
|
||||
|
||||
|
||||
case 2:
|
||||
AHourOnes = AHourOnes +1;
|
||||
|
||||
// -----------*
|
||||
if(A_TH_Not24_flag)
|
||||
// 12 hours mode increment
|
||||
{
|
||||
|
||||
if(AHourOnes >9 )
|
||||
{
|
||||
AHourOnes = 0;
|
||||
AHourTens = 1;
|
||||
}
|
||||
|
||||
if((AHourOnes ==2) && (AHourTens == 1))
|
||||
{
|
||||
A_PM_NotAM_flag = !A_PM_NotAM_flag;
|
||||
}
|
||||
|
||||
if((AHourOnes >2) && (AHourTens == 1))
|
||||
{
|
||||
// PM_NotAM_flag = !PM_NotAM_flag;
|
||||
AHourTens = 0;
|
||||
AHourOnes = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
// 24 hours mode increment - S
|
||||
{
|
||||
|
||||
if((AHourOnes >9) && (AHourTens < 2))
|
||||
{
|
||||
AHourOnes = 0;
|
||||
AHourTens = AHourTens +1;
|
||||
}
|
||||
|
||||
if((AHourTens ==2) && (AHourOnes == 4))
|
||||
{
|
||||
AHourOnes = 0;
|
||||
AHourTens = 0;
|
||||
}
|
||||
}
|
||||
// 24 hours mode increment - E
|
||||
// -----------*
|
||||
|
||||
/*
|
||||
if(AHourOnes >9)
|
||||
{
|
||||
AHourOnes = 0;
|
||||
AHourTens = AHourTens +1;
|
||||
if((AHourTens >1) && (A_TH_Not24_flag))
|
||||
{
|
||||
AHourTens = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(AHourTens >2)
|
||||
{
|
||||
AHourTens = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
temp = (AHourTens << 4) + AHourOnes;
|
||||
if(A_TH_Not24_flag)
|
||||
{
|
||||
bitWrite(temp, 5, A_PM_NotAM_flag);
|
||||
}
|
||||
|
||||
bitWrite(temp, 6, A_TH_Not24_flag);
|
||||
I2C_TX(RTCDS1337,RTC_ALARM1HOUR,temp);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// Toggle Twelve and Twenty Four hour time
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void TwelveTwentyFourConvert()
|
||||
{
|
||||
|
||||
int temphours = 0;
|
||||
int temp = 0;
|
||||
|
||||
I2C_RX(RTCDS1337,RTC_HOUR);
|
||||
HourOnes = i2cData & B00001111; //
|
||||
|
||||
// TH_Not24_flag = bitRead(i2cData, 6); // False on RTC when 24 mode selected
|
||||
// PM_NotAM_flag = bitRead(i2cData, 5);
|
||||
|
||||
if(TH_Not24_flag)
|
||||
{
|
||||
HourTens = i2cData & B00010000; //
|
||||
HourTens = HourTens >> 4;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
HourTens = i2cData & B00110000; //
|
||||
HourTens = HourTens >> 4;
|
||||
}
|
||||
|
||||
temphours = HourOnes + (HourTens*10); // 12 .... 1.2.3...12 or 0 ..1.2.3. ...23
|
||||
|
||||
if(TH_Not24_flag != NewTimeFormate)
|
||||
{
|
||||
if(NewTimeFormate) // NewTimeFormate is same formate as TH_Not24_flag where H is 12 and LOW is 24
|
||||
{
|
||||
// ---------------- 24 -> 12
|
||||
// Convert into 12 hour clock
|
||||
if(temphours >= 12)
|
||||
{
|
||||
PM_NotAM_flag = true; // it is in the PM
|
||||
if(temphours> 12)
|
||||
{
|
||||
temphours = temphours - 12; // Convert from 13:00 .... 23:00 to 1:00 ... 11:00 [Go from 23:59 / 13:00 to 12:00 to 1:00] ?
|
||||
}
|
||||
else
|
||||
{
|
||||
temphours = temphours; // do nothing it is 12:00
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PM_NotAM_flag = false; // it is in the AM - No other conversion needed
|
||||
}
|
||||
if(temphours == 0)
|
||||
{
|
||||
temphours = 12;
|
||||
}
|
||||
}
|
||||
else
|
||||
// ---------------- 12 -> 24 // Convert into 24 hour clock
|
||||
{
|
||||
if((PM_NotAM_flag == false) && (temphours == 12)) // AM only check for 00 hours
|
||||
{
|
||||
temphours = 0;
|
||||
}
|
||||
if(PM_NotAM_flag == true)
|
||||
{ // PM conversion
|
||||
if(temphours != 12) // Leave 12 as 12 in 24h time
|
||||
{
|
||||
temphours = temphours + 12;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Common finish conversion section
|
||||
TH_Not24_flag = NewTimeFormate;
|
||||
HourTens = temphours / 10;
|
||||
HourOnes = temphours % 10;
|
||||
|
||||
// ---
|
||||
temp = (HourTens << 4) + HourOnes;
|
||||
if(TH_Not24_flag)
|
||||
{
|
||||
bitWrite(temp, 5, PM_NotAM_flag);
|
||||
}
|
||||
|
||||
bitWrite(temp, 6, TH_Not24_flag);
|
||||
I2C_TX(RTCDS1337,RTC_HOUR,temp);
|
||||
|
||||
// ---
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
1449
Projects/ST_Two_Small_Clock/ST2_Routines/ST2_Routines.ino
Normal file
1449
Projects/ST_Two_Small_Clock/ST2_Routines/ST2_Routines.ino
Normal file
File diff suppressed because it is too large
Load Diff
112
Projects/ST_Two_Small_Clock/ST2_Setup/ST2_Setup.ino
Normal file
112
Projects/ST_Two_Small_Clock/ST2_Setup/ST2_Setup.ino
Normal file
@@ -0,0 +1,112 @@
|
||||
//*******************************************************************************************************************
|
||||
// Setup
|
||||
//*******************************************************************************************************************
|
||||
void setup()
|
||||
{
|
||||
|
||||
// Rows Digital pin 0 to 7
|
||||
// pinMode(0, OUTPUT); // Not used
|
||||
// pinMode(1, OUTPUT); // Not used
|
||||
|
||||
// User interface Button Pins
|
||||
/*
|
||||
digitalWrite(2, HIGH); // Write a high to pin, acts as weak pull-up
|
||||
digitalWrite(3, HIGH);
|
||||
pinMode(2, INPUT);
|
||||
pinMode(3, INPUT);
|
||||
*/
|
||||
|
||||
#if ARDUINO >= 101
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
pinMode(3, INPUT_PULLUP);
|
||||
digitalWrite(2, HIGH); // Write a high to pin, acts as weak pull-up
|
||||
digitalWrite(3, HIGH);
|
||||
#else
|
||||
digitalWrite(2, HIGH); // Write a high to pin, acts as weak pull-up
|
||||
digitalWrite(3, HIGH);
|
||||
pinMode(2, INPUT);
|
||||
pinMode(3, INPUT);
|
||||
#endif
|
||||
|
||||
// Column address bits 4 to 16 decode
|
||||
pinMode(4, OUTPUT); // DeMux A
|
||||
pinMode(5, OUTPUT); // DeMux B
|
||||
pinMode(6, OUTPUT); // DeMux C
|
||||
pinMode(7, OUTPUT); // DeMux D
|
||||
|
||||
/*
|
||||
//
|
||||
pinMode(8, OUTPUT); // ROW 1
|
||||
pinMode(9, OUTPUT); // ROW 2
|
||||
pinMode(10, OUTPUT); // ROW 3
|
||||
pinMode(11, OUTPUT); // ROW 4
|
||||
pinMode(12, OUTPUT); // ROW 5
|
||||
pinMode(13, OUTPUT); // ROW 6
|
||||
|
||||
// Make these pins outputs (Was the crystal Pins) B6 = Row 7, B7 = demux select
|
||||
DDRB = (1<<DDB7)|(1<<DDB6);
|
||||
*/
|
||||
|
||||
//test with
|
||||
DDRB = (1<<DDB7)|(1<<DDB6)|(1<<DDB5)|(1<<DDB4)|(1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0);
|
||||
|
||||
|
||||
// Make these pins outputs (analog 0 to 3)
|
||||
DDRC = DDRC | 1 << PORTC0; // Column 17
|
||||
DDRC = DDRC | 1 << PORTC1; // Column 18
|
||||
DDRC = DDRC | 1 << PORTC2; // Column 19
|
||||
DDRC = DDRC | 1 << PORTC3; // Column 20
|
||||
|
||||
|
||||
|
||||
|
||||
// attachInterrupt(0, MinuteUP, FALLING);
|
||||
// attachInterrupt(1, MinuteDOWN, FALLING);
|
||||
|
||||
// Turn one Interupts, used to update the displayed LED matrix
|
||||
Timer1.initialize(100); // was 100
|
||||
// Timer1.attachInterrupt(LEDupdate);
|
||||
Timer1.attachInterrupt(LEDupdateTHREE);
|
||||
|
||||
|
||||
// I2C Inits
|
||||
Wire.begin();
|
||||
|
||||
|
||||
// Power Reduction - S
|
||||
power_adc_disable();
|
||||
power_spi_disable();
|
||||
power_usart0_disable();
|
||||
//
|
||||
// power_timer0_disable(); // Seems required (for delay ?)
|
||||
// power_timer2_disable(); // Seems required for tone (crashes without)
|
||||
|
||||
|
||||
wdt_disable();
|
||||
|
||||
//Special
|
||||
//power_all_disable();
|
||||
//power_timer1_disable();
|
||||
|
||||
// Power Reduction - E
|
||||
|
||||
// Program specific inits
|
||||
// fillmatrix();
|
||||
delay(300);
|
||||
bval = !digitalRead(SETBUTTON);
|
||||
if(bval)
|
||||
{
|
||||
lamptest();
|
||||
}
|
||||
|
||||
displayString("v1.0");
|
||||
delay(1500);
|
||||
clearmatrix();
|
||||
|
||||
// SetStartTime(); // Basic start time of 12:00 PM
|
||||
SetAlarmTime(); // for testing
|
||||
EnableAlarm1(false); // for testing
|
||||
|
||||
SleepTimer = millis();
|
||||
|
||||
}
|
||||
137
Projects/ST_Two_Small_Clock/ST2_Sleep/ST2_Sleep.ino
Normal file
137
Projects/ST_Two_Small_Clock/ST2_Sleep/ST2_Sleep.ino
Normal file
@@ -0,0 +1,137 @@
|
||||
//*******************************************************************************************************************
|
||||
// Enter Sleep Mode
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void GoToSleep()
|
||||
{
|
||||
// SLEEP_MODE_EXT_STANDBY
|
||||
|
||||
// PORTB = (PORTB & B10000000); // Clear ROWs and De-select Demux chip
|
||||
UltraPowerDown(false);
|
||||
|
||||
attachInterrupt(0, MinuteUP, FALLING);
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // was (SLEEP_MODE_EXT_STANDBY);
|
||||
cli();
|
||||
// if (some_condition)
|
||||
// {
|
||||
sleep_enable();
|
||||
// sleep_bod_disable();
|
||||
sei();
|
||||
sleep_cpu();
|
||||
// _NOP();
|
||||
// _NOP();
|
||||
sleep_disable();
|
||||
// }
|
||||
sei();
|
||||
|
||||
detachInterrupt(0);
|
||||
|
||||
UltraPowerDown(true);
|
||||
|
||||
blinkFlag = false; // Incase sleep started during time set
|
||||
// MODEOVERRIDEFLAG = false;
|
||||
NextStateFlag = false;
|
||||
|
||||
NextStateRequest = false;
|
||||
NextSUBStateRequest = false;
|
||||
|
||||
SetTimeFlag = false;
|
||||
// SetDigit = 4;
|
||||
|
||||
STATE = 0;
|
||||
SUBSTATE = 0;
|
||||
JustWokeUpFlag = true;
|
||||
|
||||
// CheckAlarm();
|
||||
// if(ALARM1FLAG)
|
||||
// {
|
||||
// ALARM1FLAG = false;
|
||||
// EnableAlarm1(false);
|
||||
// STATE = 90;
|
||||
// }
|
||||
|
||||
// displayString("Wake");
|
||||
// delay(1000);
|
||||
// clearmatrix();
|
||||
|
||||
SleepTimer = millis();
|
||||
|
||||
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// MAX power Savings
|
||||
//*******************************************************************************************************************
|
||||
void UltraPowerDown(boolean onoff)
|
||||
{
|
||||
if(onoff) // True = full power mode = ON
|
||||
{
|
||||
// pinMode(4, OUTPUT); // DeMux A
|
||||
// pinMode(5, OUTPUT); // DeMux B
|
||||
// pinMode(6, OUTPUT); // DeMux C
|
||||
// pinMode(7, OUTPUT); // DeMux D
|
||||
|
||||
power_timer1_enable(); // Used for LED matrix refresh
|
||||
power_timer0_enable(); // Seems required (for delay ?)
|
||||
power_timer2_enable(); // Seems required for tone (crashes without)
|
||||
|
||||
power_twi_enable();
|
||||
}
|
||||
else // False is LOW Power mode
|
||||
{
|
||||
// LED MATRIX
|
||||
//
|
||||
// Port C: C0 to C3 set to high. Columns 17 to 20 of LED matrix - Cathode connection
|
||||
PORTC = (PORTC & B11110000) | B00001111;
|
||||
|
||||
// Port B: Unselect the MUX chip
|
||||
PORTB = (1<<PORTB7);
|
||||
// Port B: Set all the ROWs to high: High on both cathode and annode = no current ?
|
||||
PORTB = PORTB | B01111111; // Could be PORTB =B11111111;
|
||||
|
||||
// pinMode(4, INPUT); // DeMux A // Set these to inputs to lower current on mux inputs
|
||||
// pinMode(5, INPUT); // DeMux B
|
||||
// pinMode(6, INPUT); // DeMux C
|
||||
// pinMode(7, INPUT); // DeMux D
|
||||
|
||||
PORTD = (PORTD & B00001111) | B11110000 ; // SET all address pins
|
||||
|
||||
|
||||
// Other Peripherals
|
||||
//
|
||||
power_timer1_disable(); // Used for LED matrix refresh
|
||||
power_timer0_disable(); // Seems required (for delay ?)
|
||||
power_timer2_disable(); // Seems required for tone (crashes without)
|
||||
|
||||
power_twi_disable();
|
||||
|
||||
PORTC = PORTC | 1 << PORTC4; // Set SDA and SCL to high so they do not pull current from external pull-up
|
||||
PORTC = PORTC | 1 << PORTC5;
|
||||
|
||||
DDRC = DDRC | 1 << PORTC4; // Make SDA and SCL inputs = lower current
|
||||
DDRC = DDRC | 1 << PORTC5; //
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//*******************************************************************************************************************
|
||||
// WAKE-UP - Called by Interrupt 0 on Digital pin 2
|
||||
//*******************************************************************************************************************
|
||||
|
||||
void MinuteUP()
|
||||
{
|
||||
MINUP = true;
|
||||
}
|
||||
|
||||
/*
|
||||
void MinuteDOWN()
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
void ResetSleepCount()
|
||||
{
|
||||
SleepTimer = millis();
|
||||
}
|
||||
|
||||
25
Projects/ST_Two_Small_Clock/ST2_TWI/ST2_TWI.ino
Normal file
25
Projects/ST_Two_Small_Clock/ST2_TWI/ST2_TWI.ino
Normal file
@@ -0,0 +1,25 @@
|
||||
//*******************************************************************************************************************
|
||||
// I2C TX RX
|
||||
//*******************************************************************************************************************
|
||||
void I2C_TX(byte device, byte regadd, byte tx_data) // Transmit I2C Data
|
||||
{
|
||||
Wire.beginTransmission(device);
|
||||
Wire.write(regadd);
|
||||
Wire.write(tx_data);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
void I2C_RX(byte devicerx, byte regaddrx) // Receive I2C Data
|
||||
{
|
||||
Wire.beginTransmission(devicerx);
|
||||
Wire.write(regaddrx);
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(int(devicerx), 1);
|
||||
|
||||
byte c = 0;
|
||||
if(Wire.available())
|
||||
{
|
||||
i2cData = Wire.read();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,356 @@
|
||||
|
||||
|
||||
// *****************************************************************************************************************
|
||||
// * *
|
||||
// * SpikenzieLabs.com *
|
||||
// * *
|
||||
// * Solder:Time Desk Clock *
|
||||
// * *
|
||||
// *****************************************************************************************************************
|
||||
//
|
||||
// BY: MARK DEMERS
|
||||
// May 2013
|
||||
// VERSION 1.0
|
||||
//
|
||||
// Brief:
|
||||
// Sketch used in the Solder: Time Desk Clock Kit, more info and build instructions at http://www.spikenzielabs.com/stdc
|
||||
//
|
||||
//
|
||||
// LEGAL:
|
||||
// This code is provided as is. No guaranties or warranties are given in any form. It is your responsibilty to
|
||||
// determine this codes suitability for your application.
|
||||
//
|
||||
// Changes:
|
||||
// A. Modified LEDupdateTHREE() void used by ST:2 Watch to function with the new circuits in the Solder:Time Desk Clock
|
||||
// B. Modified port dirctions on some pins to deal with new circuits.
|
||||
// C. Changed sleep mode into a "change back to display time" mode
|
||||
|
||||
#include <Wire.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
#include <TimerOne.h>
|
||||
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/wdt.h>
|
||||
|
||||
// Worm animation
|
||||
int c =0;
|
||||
int y = 3;
|
||||
int target = 3;
|
||||
int targdist =0;
|
||||
boolean targdir = true;
|
||||
int wormlenght = 15;
|
||||
boolean soundeffect = false;
|
||||
|
||||
// int i =0;
|
||||
// int i2 =0;
|
||||
// int vite = 2;
|
||||
// uint8_t incro = 0;
|
||||
// uint8_t column = 0;
|
||||
uint8_t TEXT = 65;
|
||||
uint8_t i2cData = 0;
|
||||
// int nextcounter = 0;
|
||||
|
||||
int STATE = 0;
|
||||
int SUBSTATE = 0;
|
||||
int MAXSTATE = 6;
|
||||
boolean NextStateRequest = false;
|
||||
boolean NextSUBStateRequest = false;
|
||||
boolean JustWokeUpFlag = false;
|
||||
boolean JustWokeUpFlag2= false;
|
||||
boolean OptionModeFlag = false;
|
||||
|
||||
int ROWBITINDEX = 0;
|
||||
int scrollCounter =0;
|
||||
int ScrollLoops = 3;
|
||||
int scrollSpeed = 300; // was 1200
|
||||
int blinkCounter = 0;
|
||||
boolean blinkFlag = false;
|
||||
boolean blinkON = true;
|
||||
boolean blinkHour = false;
|
||||
boolean blinkMin = false;
|
||||
#define blinkTime 500 // was 1000
|
||||
|
||||
boolean displayFLAG = true;
|
||||
|
||||
unsigned long SleepTimer;
|
||||
unsigned long currentMillis;
|
||||
unsigned long SleepLimit = 6000;
|
||||
boolean SleepEnable = true;
|
||||
int UpdateTime = 0;
|
||||
|
||||
#define BUTTON1 2
|
||||
#define MODEBUTTON 2
|
||||
#define BUTTON2 3
|
||||
#define SETBUTTON 3
|
||||
boolean bval = false;
|
||||
|
||||
//char Str1[] = "Hi";
|
||||
char IncomingMessage[24];
|
||||
char MessageRead;
|
||||
//uint8_t INBYTE;
|
||||
uint8_t Message[275];
|
||||
int IncomingIndex = 0;
|
||||
int IncomingMessIndex =0;
|
||||
int IncomingMax = 0;
|
||||
int MessagePointer = 0;
|
||||
int StartWindow = 0;
|
||||
int IncomingLoaded =0;
|
||||
|
||||
|
||||
char days[7][4] = {
|
||||
"Sun","Mon","Tue","Wed","Thr","Fri","Sat"};
|
||||
char months[12][4] = {
|
||||
"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
|
||||
|
||||
// Time Variables
|
||||
uint8_t HourTens = 1;
|
||||
uint8_t HourOnes = 2;
|
||||
uint8_t MinTens = 0;
|
||||
uint8_t MinOnes = 0;
|
||||
uint8_t SecTens = 0;
|
||||
uint8_t SecOnes = 0;
|
||||
|
||||
uint8_t Days =1;
|
||||
uint8_t DateOnes = 1;
|
||||
uint8_t DateTens =0;
|
||||
uint8_t MonthOnes =1;
|
||||
uint8_t MonthTens = 1;
|
||||
uint8_t YearsOnes = 2;
|
||||
uint8_t YearsTens = 1;
|
||||
|
||||
uint8_t DayCode =1;
|
||||
uint8_t MonthCode =1;
|
||||
|
||||
|
||||
boolean TH_Not24_flag = true;
|
||||
boolean PM_NotAM_flag = false;
|
||||
boolean NewTimeFormate = TH_Not24_flag;
|
||||
uint8_t AMPMALARMDOTS = 0;
|
||||
|
||||
// Alarm
|
||||
uint8_t AHourTens = 1;
|
||||
uint8_t AHourOnes = 2;
|
||||
uint8_t AMinTens = 0;
|
||||
uint8_t AMinOnes = 0;
|
||||
|
||||
boolean A_TH_Not24_flag = true;
|
||||
boolean A_PM_NotAM_flag = false;
|
||||
|
||||
// StopWatch
|
||||
int OldTime = 0;
|
||||
int CurrentTime = 0;
|
||||
int TotalTime = 0;
|
||||
|
||||
uint8_t SWDigit4 = 0;
|
||||
uint8_t SWDigit3 = 0;
|
||||
uint8_t SWDigit2 = 0;
|
||||
uint8_t SWDigit1 = 0;
|
||||
|
||||
int SWMINUTES = 0;
|
||||
int SWSECONDS = 0;
|
||||
|
||||
int dayIndex = 0;
|
||||
|
||||
//uint8_t SetDigit = 4;
|
||||
//boolean MODEOVERRIDEFLAG = false;
|
||||
boolean NextStateFlag = false;
|
||||
boolean SetTimeFlag = false;
|
||||
boolean ALARM1FLAG = false;
|
||||
boolean ALARMON = false;
|
||||
|
||||
boolean scrollDirFlag = false;
|
||||
|
||||
|
||||
//
|
||||
volatile uint8_t Mcolumn = 0;
|
||||
//volatile uint8_t McolumnTemp = 0;
|
||||
//volatile uint8_t Mrow = 0;
|
||||
volatile uint8_t LEDMAT[20];
|
||||
|
||||
volatile boolean MINUP = false;
|
||||
volatile boolean MINDOWN = false;
|
||||
volatile boolean TFH = false;
|
||||
|
||||
const int digitoffset = 95; // 95 // was 16
|
||||
|
||||
|
||||
// Constants
|
||||
// DS1337+ Address locations
|
||||
#define RTCDS1337 B01101000 // was B11010000
|
||||
#define RTCCONT B00001110 //; Control
|
||||
#define RTCSTATUS B00001111 //; Status
|
||||
|
||||
//#define RTC_HSEC B00000001 //; Hundredth of a secound
|
||||
#define RTC_SEC B00000000 //; Seconds
|
||||
#define RTC_MIN B00000001 //; Minuites
|
||||
#define RTC_HOUR B00000010 //; Hours
|
||||
|
||||
#define RTC_DAY B00000011 //; Day
|
||||
#define RTC_DATE B00000100 //; Date
|
||||
#define RTC_MONTH B00000101 //; Month
|
||||
#define RTC_YEAR B00000110 //; Year
|
||||
|
||||
#define RTC_ALARM1SEC B00000111 //; Seconds
|
||||
#define RTC_ALARM1MIN B00001000 //; Minuites
|
||||
#define RTC_ALARM1HOUR B00001001 //; Hours
|
||||
#define RTC_ALARM1DATE B00001010 //; Date
|
||||
|
||||
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// Bit Map Letter - data array
|
||||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// const byte LETTERS[95][5] = {
|
||||
const byte LETTERS[106][5] = {
|
||||
0,0,0,0,0, // Space
|
||||
0,0,95,0,0, // !
|
||||
0,3,0,3,0, // "
|
||||
18,63,18,63,18, // #
|
||||
4,42,127,42,16, // $
|
||||
34,21,42,84,34, // %
|
||||
54,73,81,34,80, // &
|
||||
0,0,3,0,0, // '
|
||||
0,28,34,65,0, // (
|
||||
0,65,34,28,0, // (
|
||||
4,20,15,20,4, // *
|
||||
8,8,62,8,8, // +
|
||||
0,0,2,1,0, // ' (not sure)
|
||||
8,8,8,8,8, // -
|
||||
0,0,64,0,0, // .
|
||||
32,16,8,4,2, // /
|
||||
|
||||
62,65,65,65,62, // 0
|
||||
64,66,127,64,64, // 1
|
||||
98,81,73,73,70, // 2
|
||||
34,65,73,73,54, // 3
|
||||
7,8,8,127,8, // 4
|
||||
47,73,73,73,49, // 5
|
||||
62,73,73,73,50, // 6
|
||||
65,33,17,9,7, // 7
|
||||
54,73,73,73,54, // 8
|
||||
6,9,9,9,126, // 9
|
||||
|
||||
0,0,54,0,0, // :
|
||||
0,64,54,0,0, // ;
|
||||
8,20,34,65,0, // <
|
||||
20,20,20,20,20, // =
|
||||
0,65,34,20,8, // >
|
||||
6,1,81,9,6, // ?
|
||||
62,65,73,85,10, // @
|
||||
|
||||
124,10,9,10,124, // A
|
||||
127,73,73,73,54, // B
|
||||
62,65,65,65,34, // C
|
||||
127,65,65,65,62, // D
|
||||
127,73,73,73,65, // E
|
||||
127,9,9,9,1, // F
|
||||
62,65,73,73,50, // G
|
||||
127,8,8,8,127, // H
|
||||
0,65,127,65,0, // I was 65,65,127,65,65,
|
||||
32,64,65,63,1, // J
|
||||
127,8,20,34,65, // K
|
||||
127,64,64,64,64, // L
|
||||
127,2,4,2,127, // M
|
||||
127,4,8,16,127, // N
|
||||
62,65,65,65,62, // O
|
||||
127,9,9,9,6, // P
|
||||
62,65,81,33,94, // Q
|
||||
127,9,25,41,70, // R
|
||||
38,73,73,73,50, // S
|
||||
1,1,127,1,1, // T
|
||||
63,64,64,64,63, // U
|
||||
31,32,64,32,31, // V
|
||||
63,64,48,64,63, // W
|
||||
99,20,8,20,99, // X
|
||||
3,4,120,4,3, // Y
|
||||
97,81,73,69,67, // Z
|
||||
|
||||
0,127,65,65,0, // [
|
||||
2,4,8,16,32, // back slash
|
||||
0,65,65,127,0, // ]
|
||||
0,2,1,2,0, // ^
|
||||
128,128,128,128,128, // _
|
||||
0,0,1,2,0, // `
|
||||
|
||||
112,72,72,40,120, // a
|
||||
126,48,72,72,48, // b
|
||||
48,72,72,72,72, // c
|
||||
48,72,72,48,126, // d
|
||||
56,84,84,84,88, // e
|
||||
0,8,124,10,0, // f
|
||||
36,74,74,74,60, // g
|
||||
126,8,8,8,112, // h
|
||||
0,0,122,0,0, // i
|
||||
32,64,66,62,2, // j
|
||||
124,16,16,40,68, // k
|
||||
0,124,64,64,0, // l
|
||||
120,4,120,4,120, // m
|
||||
124,8,4,4,120, // n
|
||||
48,72,72,72,48, // o
|
||||
126,18,18,18,12, // p
|
||||
12,18,18,18,124, // q
|
||||
124,8,4,4,8, // r
|
||||
72,84,84,84,36, // s
|
||||
4,4,126,4,4, // t
|
||||
60,64,64,64,60, // u
|
||||
28,32,64,32,28, // v
|
||||
124,32,16,32,124, // w
|
||||
68,40,16,40,68, // x
|
||||
4,8,112,8,4, // y
|
||||
68,100,84,76,68, // z
|
||||
|
||||
0,8,54,65,0, // {
|
||||
0,0,127,0,0, // |
|
||||
0,65,54,8,0, // }
|
||||
16,8,24,16,8, // ~
|
||||
|
||||
// Small Numbers (for adding colon in clock applications)
|
||||
0,62,34,62,0, // 0
|
||||
0,0,62,0,0, // 1
|
||||
0,58,42,46,0, // 2
|
||||
0,42,42,62,0, // 3
|
||||
0,14,8,62,0, // 4
|
||||
0,46,42,58,0, // 5
|
||||
0,62,42,58,0, // 6
|
||||
0,2,2,62,0, // 7
|
||||
0,62,42,62,0, // 8
|
||||
0,14,10,62,0, // 9
|
||||
0,0,20,0,0, // :
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
const byte GRAPHIC[5][5] = {
|
||||
0,0,0,0,0,
|
||||
0,28,62,127,0, // Speaker cone
|
||||
34,28,65,34,28, // Sound wave
|
||||
16,32,16,8,4, // Check mark
|
||||
34,20,8,20,34, // "X"
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user