BULME-TIMER_V2 funktionsdüchtig.

Dependencies:   DigitDisplay PCF8563 Led-libary dPrell mbed

Committer:
04M04
Date:
Thu Jun 23 19:15:16 2016 +0000
Revision:
0:524e857fe466
BULME-TIMER_V2

Who changed what in which revision?

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