Repository navigation
Expand file tree
/
Copy pathST2_Sleep.ino
More file actions
137 lines (105 loc) · 4.55 KB
/
Copy pathST2_Sleep.ino
File metadata and controls
137 lines (105 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//*******************************************************************************************************************
// 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();
}