![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Dependencies: DigitDisplay PCF8563 Led-libary dPrell mbed
main.cpp@0:c7b01fe7c67c, 2016-06-03 (annotated)
- Committer:
- 04M04
- Date:
- Fri Jun 03 08:25:06 2016 +0000
- Revision:
- 0:c7b01fe7c67c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
04M04 | 0:c7b01fe7c67c | 1 | //______________________________________________________Bibliotheken |
04M04 | 0:c7b01fe7c67c | 2 | #include "mbed.h" |
04M04 | 0:c7b01fe7c67c | 3 | #include "WS2812B.h" |
04M04 | 0:c7b01fe7c67c | 4 | #include "PCF8563.h" |
04M04 | 0:c7b01fe7c67c | 5 | #include "DigitDisplay.h" |
04M04 | 0:c7b01fe7c67c | 6 | #include "dPrell.h" |
04M04 | 0:c7b01fe7c67c | 7 | //______________________________________________________Farbdefinitionen |
04M04 | 0:c7b01fe7c67c | 8 | // G R B |
04M04 | 0:c7b01fe7c67c | 9 | // | | | |
04M04 | 0:c7b01fe7c67c | 10 | #define rGb (0x0f0000) //Grün |
04M04 | 0:c7b01fe7c67c | 11 | #define Rgb (0x00ff00) //Rot |
04M04 | 0:c7b01fe7c67c | 12 | #define rgB (0x0000ff) //Blau |
04M04 | 0:c7b01fe7c67c | 13 | #define RgB (0x00ffff) //Violet |
04M04 | 0:c7b01fe7c67c | 14 | #define rGB (0xff00ff) //Türkis |
04M04 | 0:c7b01fe7c67c | 15 | #define RGb (0xffff00) //Rot-Grün |
04M04 | 0:c7b01fe7c67c | 16 | #define RGB (0xffffff) //Weiß |
04M04 | 0:c7b01fe7c67c | 17 | #define rgb (0x000000) //Aus |
04M04 | 0:c7b01fe7c67c | 18 | //halbe Helligkeit |
04M04 | 0:c7b01fe7c67c | 19 | #define hrGb (0x0f0000) //Grün |
04M04 | 0:c7b01fe7c67c | 20 | #define hRgb (0x000f00) //Rot |
04M04 | 0:c7b01fe7c67c | 21 | #define hrgB (0x00000f) //Blau |
04M04 | 0:c7b01fe7c67c | 22 | #define hRgB (0x000f0f) //Violet |
04M04 | 0:c7b01fe7c67c | 23 | #define hrGB (0x0f000f) //Türkis |
04M04 | 0:c7b01fe7c67c | 24 | #define hRGb (0x0f0f00) //Rot-Grün |
04M04 | 0:c7b01fe7c67c | 25 | #define hRGB (0x0f0f0f) //Weiß |
04M04 | 0:c7b01fe7c67c | 26 | //______________________________________________________Schnittstellen |
04M04 | 0:c7b01fe7c67c | 27 | Ticker TickerOutput; |
04M04 | 0:c7b01fe7c67c | 28 | |
04M04 | 0:c7b01fe7c67c | 29 | PCF8563 rtc; |
04M04 | 0:c7b01fe7c67c | 30 | |
04M04 | 0:c7b01fe7c67c | 31 | DigitalOut Led1(LED1); |
04M04 | 0:c7b01fe7c67c | 32 | DigitalOut Led2(LED2); |
04M04 | 0:c7b01fe7c67c | 33 | DigitalOut Led3(LED3); |
04M04 | 0:c7b01fe7c67c | 34 | DigitalOut Led4(LED4); |
04M04 | 0:c7b01fe7c67c | 35 | |
04M04 | 0:c7b01fe7c67c | 36 | dPrell Taster1(p17); |
04M04 | 0:c7b01fe7c67c | 37 | dPrell Taster2(p18); |
04M04 | 0:c7b01fe7c67c | 38 | dPrell Taster3(p19); |
04M04 | 0:c7b01fe7c67c | 39 | dPrell Taster4(p20); |
04M04 | 0:c7b01fe7c67c | 40 | dPrell InternTaster1(P1_16); |
04M04 | 0:c7b01fe7c67c | 41 | dPrell InternTaster2(P0_23); |
04M04 | 0:c7b01fe7c67c | 42 | dPrell InternTaster3(P0_10); |
04M04 | 0:c7b01fe7c67c | 43 | dPrell InternTaster4(P0_15); |
04M04 | 0:c7b01fe7c67c | 44 | |
04M04 | 0:c7b01fe7c67c | 45 | PwmOut Summer(p6); |
04M04 | 0:c7b01fe7c67c | 46 | |
04M04 | 0:c7b01fe7c67c | 47 | LedOut RGBStripe(p25); |
04M04 | 0:c7b01fe7c67c | 48 | // (CLK, I/O) |
04M04 | 0:c7b01fe7c67c | 49 | DigitDisplay TimerDisplay(p21, p22); |
04M04 | 0:c7b01fe7c67c | 50 | // (CLK, I/O) |
04M04 | 0:c7b01fe7c67c | 51 | DigitDisplay UhrDisplay(p23, p24); |
04M04 | 0:c7b01fe7c67c | 52 | |
04M04 | 0:c7b01fe7c67c | 53 | Serial pc(USBTX, USBRX); |
04M04 | 0:c7b01fe7c67c | 54 | //______________________________________________________Variablen |
04M04 | 0:c7b01fe7c67c | 55 | |
04M04 | 0:c7b01fe7c67c | 56 | uint8_t hour, minute, sec; |
04M04 | 0:c7b01fe7c67c | 57 | |
04M04 | 0:c7b01fe7c67c | 58 | int color = rgb; |
04M04 | 0:c7b01fe7c67c | 59 | int ColorTime = 0; |
04M04 | 0:c7b01fe7c67c | 60 | int Prozent = 0; |
04M04 | 0:c7b01fe7c67c | 61 | int TimerZeit = 0; |
04M04 | 0:c7b01fe7c67c | 62 | int TimerMinuten = 0; |
04M04 | 0:c7b01fe7c67c | 63 | int TimerSekunden = 0; |
04M04 | 0:c7b01fe7c67c | 64 | int UhrZeit = 0; |
04M04 | 0:c7b01fe7c67c | 65 | int SetMenu = 0; |
04M04 | 0:c7b01fe7c67c | 66 | int StartStop = 0; |
04M04 | 0:c7b01fe7c67c | 67 | int End = 0; |
04M04 | 0:c7b01fe7c67c | 68 | //______________________________________________________Funktionen |
04M04 | 0:c7b01fe7c67c | 69 | |
04M04 | 0:c7b01fe7c67c | 70 | void Set(); |
04M04 | 0:c7b01fe7c67c | 71 | void Plus(); |
04M04 | 0:c7b01fe7c67c | 72 | void Minus(); |
04M04 | 0:c7b01fe7c67c | 73 | void TimerStartStop(); |
04M04 | 0:c7b01fe7c67c | 74 | void TasterTrig(); |
04M04 | 0:c7b01fe7c67c | 75 | |
04M04 | 0:c7b01fe7c67c | 76 | void TimerIn(); |
04M04 | 0:c7b01fe7c67c | 77 | void TimerPlay(); |
04M04 | 0:c7b01fe7c67c | 78 | void TimerOut(); |
04M04 | 0:c7b01fe7c67c | 79 | void ChangeColor(); |
04M04 | 0:c7b01fe7c67c | 80 | void StripeOut(); |
04M04 | 0:c7b01fe7c67c | 81 | void UhrOut(); |
04M04 | 0:c7b01fe7c67c | 82 | void SummerOut(); |
04M04 | 0:c7b01fe7c67c | 83 | void Output(); |
04M04 | 0:c7b01fe7c67c | 84 | void EndSignal(); |
04M04 | 0:c7b01fe7c67c | 85 | //______________________________________________________Main |
04M04 | 0:c7b01fe7c67c | 86 | int main() |
04M04 | 0:c7b01fe7c67c | 87 | { |
04M04 | 0:c7b01fe7c67c | 88 | TickerOutput.attach(&Output, 0.1); |
04M04 | 0:c7b01fe7c67c | 89 | |
04M04 | 0:c7b01fe7c67c | 90 | Taster1.rise(&Set); |
04M04 | 0:c7b01fe7c67c | 91 | Taster2.rise(&Plus); |
04M04 | 0:c7b01fe7c67c | 92 | Taster3.rise(&Minus); |
04M04 | 0:c7b01fe7c67c | 93 | Taster4.rise(&TimerStartStop); |
04M04 | 0:c7b01fe7c67c | 94 | InternTaster1.rise(&Set); |
04M04 | 0:c7b01fe7c67c | 95 | InternTaster2.rise(&Plus); |
04M04 | 0:c7b01fe7c67c | 96 | InternTaster3.rise(&Minus); |
04M04 | 0:c7b01fe7c67c | 97 | InternTaster4.rise(&TimerStartStop); |
04M04 | 0:c7b01fe7c67c | 98 | while(1) { |
04M04 | 0:c7b01fe7c67c | 99 | if(SetMenu == 0 && (TimerMinuten > 0 || TimerSekunden > 0) && StartStop == 1) { |
04M04 | 0:c7b01fe7c67c | 100 | TimerPlay(); |
04M04 | 0:c7b01fe7c67c | 101 | } else if(SetMenu == 0 && StartStop >=0) { |
04M04 | 0:c7b01fe7c67c | 102 | StartStop = 0; |
04M04 | 0:c7b01fe7c67c | 103 | } |
04M04 | 0:c7b01fe7c67c | 104 | if(End > 0) { |
04M04 | 0:c7b01fe7c67c | 105 | EndSignal(); |
04M04 | 0:c7b01fe7c67c | 106 | } |
04M04 | 0:c7b01fe7c67c | 107 | } |
04M04 | 0:c7b01fe7c67c | 108 | } |
04M04 | 0:c7b01fe7c67c | 109 | //______________________________________________________Interrupts |
04M04 | 0:c7b01fe7c67c | 110 | |
04M04 | 0:c7b01fe7c67c | 111 | void Set() |
04M04 | 0:c7b01fe7c67c | 112 | { |
04M04 | 0:c7b01fe7c67c | 113 | Led1 = !Led1; |
04M04 | 0:c7b01fe7c67c | 114 | if (SetMenu == 0 && StartStop == 0) { |
04M04 | 0:c7b01fe7c67c | 115 | SetMenu++; |
04M04 | 0:c7b01fe7c67c | 116 | } else if (SetMenu >= 1 && StartStop == 0) { |
04M04 | 0:c7b01fe7c67c | 117 | SetMenu = 0; |
04M04 | 0:c7b01fe7c67c | 118 | } |
04M04 | 0:c7b01fe7c67c | 119 | End = 0; |
04M04 | 0:c7b01fe7c67c | 120 | Summer.pulsewidth(0); |
04M04 | 0:c7b01fe7c67c | 121 | TasterTrig(); |
04M04 | 0:c7b01fe7c67c | 122 | } |
04M04 | 0:c7b01fe7c67c | 123 | void Plus() |
04M04 | 0:c7b01fe7c67c | 124 | { |
04M04 | 0:c7b01fe7c67c | 125 | Led2 = !Led2; |
04M04 | 0:c7b01fe7c67c | 126 | if(SetMenu==1) { |
04M04 | 0:c7b01fe7c67c | 127 | TimerMinuten++; |
04M04 | 0:c7b01fe7c67c | 128 | TimerSekunden = 0; |
04M04 | 0:c7b01fe7c67c | 129 | } |
04M04 | 0:c7b01fe7c67c | 130 | TasterTrig(); |
04M04 | 0:c7b01fe7c67c | 131 | |
04M04 | 0:c7b01fe7c67c | 132 | } |
04M04 | 0:c7b01fe7c67c | 133 | void Minus() |
04M04 | 0:c7b01fe7c67c | 134 | { |
04M04 | 0:c7b01fe7c67c | 135 | Led3 = !Led3; |
04M04 | 0:c7b01fe7c67c | 136 | if(SetMenu==1 && minute>0) { |
04M04 | 0:c7b01fe7c67c | 137 | TimerMinuten--; |
04M04 | 0:c7b01fe7c67c | 138 | TimerSekunden = 0; |
04M04 | 0:c7b01fe7c67c | 139 | } |
04M04 | 0:c7b01fe7c67c | 140 | TasterTrig(); |
04M04 | 0:c7b01fe7c67c | 141 | |
04M04 | 0:c7b01fe7c67c | 142 | } |
04M04 | 0:c7b01fe7c67c | 143 | void TimerStartStop() |
04M04 | 0:c7b01fe7c67c | 144 | { |
04M04 | 0:c7b01fe7c67c | 145 | Led4 = !Led4; |
04M04 | 0:c7b01fe7c67c | 146 | if(SetMenu == 0 && (TimerMinuten > 0 || TimerSekunden > 0) && StartStop == 0) { |
04M04 | 0:c7b01fe7c67c | 147 | StartStop++; |
04M04 | 0:c7b01fe7c67c | 148 | } else if(SetMenu == 0 && StartStop >=1) { |
04M04 | 0:c7b01fe7c67c | 149 | StartStop = 0; |
04M04 | 0:c7b01fe7c67c | 150 | } |
04M04 | 0:c7b01fe7c67c | 151 | TasterTrig(); |
04M04 | 0:c7b01fe7c67c | 152 | } |
04M04 | 0:c7b01fe7c67c | 153 | //______________________________________________________Funktionen |
04M04 | 0:c7b01fe7c67c | 154 | |
04M04 | 0:c7b01fe7c67c | 155 | void TasterTrig() |
04M04 | 0:c7b01fe7c67c | 156 | { |
04M04 | 0:c7b01fe7c67c | 157 | Taster1.trig(); |
04M04 | 0:c7b01fe7c67c | 158 | Taster2.trig(); |
04M04 | 0:c7b01fe7c67c | 159 | Taster3.trig(); |
04M04 | 0:c7b01fe7c67c | 160 | Taster4.trig(); |
04M04 | 0:c7b01fe7c67c | 161 | InternTaster1.trig(); |
04M04 | 0:c7b01fe7c67c | 162 | InternTaster2.trig(); |
04M04 | 0:c7b01fe7c67c | 163 | InternTaster3.trig(); |
04M04 | 0:c7b01fe7c67c | 164 | InternTaster4.trig(); |
04M04 | 0:c7b01fe7c67c | 165 | } |
04M04 | 0:c7b01fe7c67c | 166 | //______________________________________________________Timer-Bereich |
04M04 | 0:c7b01fe7c67c | 167 | |
04M04 | 0:c7b01fe7c67c | 168 | void TimerPlay() |
04M04 | 0:c7b01fe7c67c | 169 | { |
04M04 | 0:c7b01fe7c67c | 170 | while(TimerMinuten > 0) { |
04M04 | 0:c7b01fe7c67c | 171 | if(TimerSekunden == 0) { |
04M04 | 0:c7b01fe7c67c | 172 | TimerMinuten--; |
04M04 | 0:c7b01fe7c67c | 173 | TimerSekunden = 60; |
04M04 | 0:c7b01fe7c67c | 174 | } |
04M04 | 0:c7b01fe7c67c | 175 | while(TimerSekunden >0) { |
04M04 | 0:c7b01fe7c67c | 176 | TimerSekunden--; |
04M04 | 0:c7b01fe7c67c | 177 | wait(1); |
04M04 | 0:c7b01fe7c67c | 178 | if(StartStop==0) { |
04M04 | 0:c7b01fe7c67c | 179 | return; |
04M04 | 0:c7b01fe7c67c | 180 | } |
04M04 | 0:c7b01fe7c67c | 181 | } |
04M04 | 0:c7b01fe7c67c | 182 | } |
04M04 | 0:c7b01fe7c67c | 183 | if(TimerMinuten < 1 && TimerSekunden < 1) { |
04M04 | 0:c7b01fe7c67c | 184 | End++; |
04M04 | 0:c7b01fe7c67c | 185 | StartStop = 0; |
04M04 | 0:c7b01fe7c67c | 186 | } |
04M04 | 0:c7b01fe7c67c | 187 | return; |
04M04 | 0:c7b01fe7c67c | 188 | } |
04M04 | 0:c7b01fe7c67c | 189 | |
04M04 | 0:c7b01fe7c67c | 190 | void TimerOut() |
04M04 | 0:c7b01fe7c67c | 191 | { |
04M04 | 0:c7b01fe7c67c | 192 | TimerZeit = (TimerMinuten * 100) + TimerSekunden; |
04M04 | 0:c7b01fe7c67c | 193 | TimerDisplay.write(TimerZeit); |
04M04 | 0:c7b01fe7c67c | 194 | TimerDisplay.setColon(1); |
04M04 | 0:c7b01fe7c67c | 195 | } |
04M04 | 0:c7b01fe7c67c | 196 | //______________________________________________________RGB-,Uhr-,Summer-Bereich |
04M04 | 0:c7b01fe7c67c | 197 | |
04M04 | 0:c7b01fe7c67c | 198 | void ChangeColor() |
04M04 | 0:c7b01fe7c67c | 199 | { |
04M04 | 0:c7b01fe7c67c | 200 | if(ColorTime <= 10) { |
04M04 | 0:c7b01fe7c67c | 201 | color = Rgb; |
04M04 | 0:c7b01fe7c67c | 202 | } else if(ColorTime <= 50) { |
04M04 | 0:c7b01fe7c67c | 203 | color = rGB; |
04M04 | 0:c7b01fe7c67c | 204 | } else |
04M04 | 0:c7b01fe7c67c | 205 | color = rGb; |
04M04 | 0:c7b01fe7c67c | 206 | } |
04M04 | 0:c7b01fe7c67c | 207 | |
04M04 | 0:c7b01fe7c67c | 208 | void StripeOut() |
04M04 | 0:c7b01fe7c67c | 209 | { |
04M04 | 0:c7b01fe7c67c | 210 | __disable_irq(); //Interrupt deaktivieren |
04M04 | 0:c7b01fe7c67c | 211 | |
04M04 | 0:c7b01fe7c67c | 212 | for(int r=1; r<=Prozent; r++) |
04M04 | 0:c7b01fe7c67c | 213 | RGBStripe.WriteLed(color); //Farbe rausschreiben |
04M04 | 0:c7b01fe7c67c | 214 | |
04M04 | 0:c7b01fe7c67c | 215 | __enable_irq(); //Interrupt reaktivieren |
04M04 | 0:c7b01fe7c67c | 216 | } |
04M04 | 0:c7b01fe7c67c | 217 | |
04M04 | 0:c7b01fe7c67c | 218 | void UhrOut() |
04M04 | 0:c7b01fe7c67c | 219 | { |
04M04 | 0:c7b01fe7c67c | 220 | hour = rtc.read(HOURS); |
04M04 | 0:c7b01fe7c67c | 221 | minute = rtc.read(MINUTES); |
04M04 | 0:c7b01fe7c67c | 222 | sec = rtc.read(SECONDS); |
04M04 | 0:c7b01fe7c67c | 223 | |
04M04 | 0:c7b01fe7c67c | 224 | UhrDisplay.write(0, (minute >> 4)- 8); |
04M04 | 0:c7b01fe7c67c | 225 | UhrDisplay.write(1, (minute & 0x0F)); |
04M04 | 0:c7b01fe7c67c | 226 | UhrDisplay.setColon(1); |
04M04 | 0:c7b01fe7c67c | 227 | UhrDisplay.write(2, (sec >> 4)- 8); |
04M04 | 0:c7b01fe7c67c | 228 | UhrDisplay.write(3, (sec & 0x0F)); |
04M04 | 0:c7b01fe7c67c | 229 | } |
04M04 | 0:c7b01fe7c67c | 230 | |
04M04 | 0:c7b01fe7c67c | 231 | void SummerOut() |
04M04 | 0:c7b01fe7c67c | 232 | { |
04M04 | 0:c7b01fe7c67c | 233 | // specify period first, then everything else |
04M04 | 0:c7b01fe7c67c | 234 | Summer.period(0.001f); // 0.001 second period |
04M04 | 0:c7b01fe7c67c | 235 | Summer.pulsewidth(0.0004); // 0.0004 second pulse (on) |
04M04 | 0:c7b01fe7c67c | 236 | // led flashing |
04M04 | 0:c7b01fe7c67c | 237 | wait(4); |
04M04 | 0:c7b01fe7c67c | 238 | Summer.pulsewidth(0); |
04M04 | 0:c7b01fe7c67c | 239 | } |
04M04 | 0:c7b01fe7c67c | 240 | |
04M04 | 0:c7b01fe7c67c | 241 | void Output() |
04M04 | 0:c7b01fe7c67c | 242 | { |
04M04 | 0:c7b01fe7c67c | 243 | TimerOut(); |
04M04 | 0:c7b01fe7c67c | 244 | //StripeOut(); |
04M04 | 0:c7b01fe7c67c | 245 | UhrOut(); |
04M04 | 0:c7b01fe7c67c | 246 | } |
04M04 | 0:c7b01fe7c67c | 247 | |
04M04 | 0:c7b01fe7c67c | 248 | void EndSignal() |
04M04 | 0:c7b01fe7c67c | 249 | { |
04M04 | 0:c7b01fe7c67c | 250 | __disable_irq(); |
04M04 | 0:c7b01fe7c67c | 251 | color = Rgb; |
04M04 | 0:c7b01fe7c67c | 252 | Prozent = 10; |
04M04 | 0:c7b01fe7c67c | 253 | StripeOut(); |
04M04 | 0:c7b01fe7c67c | 254 | SummerOut(); |
04M04 | 0:c7b01fe7c67c | 255 | color = rgb; |
04M04 | 0:c7b01fe7c67c | 256 | StripeOut(); |
04M04 | 0:c7b01fe7c67c | 257 | End = 0; |
04M04 | 0:c7b01fe7c67c | 258 | __enable_irq(); |
04M04 | 0:c7b01fe7c67c | 259 | } |