nein
Dependencies: Debouncer DigitDisplay Led-libary PCF8563 mbed
Fork of WS_7_Seg_mit_LM1635 by
main.cpp@2:503467a441e6, 2016-05-30 (annotated)
- Committer:
- sophia
- Date:
- Mon May 30 09:42:24 2016 +0000
- Revision:
- 2:503467a441e6
- Parent:
- 1:838565907c81
Haupt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sophia | 0:925e9ab5be17 | 1 | #include "mbed.h" |
sophia | 0:925e9ab5be17 | 2 | #include "DigitDisplay.h" |
sophia | 1:838565907c81 | 3 | #include "WS2812B.h" |
sophia | 1:838565907c81 | 4 | #include "PCF8563.h" |
sophia | 0:925e9ab5be17 | 5 | |
sophia | 1:838565907c81 | 6 | #define rGb (0x0f0000) //Rot |
sophia | 1:838565907c81 | 7 | #define Rgb (0x00ff00) //Grün |
sophia | 1:838565907c81 | 8 | #define rgB (0x0000ff) //Blau |
sophia | 1:838565907c81 | 9 | #define RgB (0x00ffff) //Violet |
sophia | 1:838565907c81 | 10 | #define rGB (0xff00ff) //Türkis |
sophia | 2:503467a441e6 | 11 | #define RGb (0xffff00) //Gelb |
sophia | 1:838565907c81 | 12 | #define RGB (0xffffff) //Weiß |
sophia | 1:838565907c81 | 13 | #define rgb (0x000000) //Aus |
sophia | 1:838565907c81 | 14 | //halbe Helligkeit |
sophia | 1:838565907c81 | 15 | #define hrGb (0x0f0000) //Rot |
sophia | 1:838565907c81 | 16 | #define hRgb (0x000f00) //Grün |
sophia | 1:838565907c81 | 17 | #define hrgB (0x00000f) //Blau |
sophia | 1:838565907c81 | 18 | #define hRgB (0x000f0f) //Violet |
sophia | 1:838565907c81 | 19 | #define hrGB (0x0f000f) //Türkis |
sophia | 2:503467a441e6 | 20 | #define hRGb (0x0f0f00) //Gelb |
sophia | 1:838565907c81 | 21 | #define hRGB (0x0f0f0f) //Weiß |
sophia | 1:838565907c81 | 22 | |
sophia | 2:503467a441e6 | 23 | Ticker UhrTick; |
sophia | 1:838565907c81 | 24 | Timeout timer; |
sophia | 1:838565907c81 | 25 | PCF8563 rtc; |
sophia | 0:925e9ab5be17 | 26 | |
sophia | 1:838565907c81 | 27 | DigitalOut Led1(LED1); |
sophia | 1:838565907c81 | 28 | DigitalOut Led2(LED2); |
sophia | 1:838565907c81 | 29 | DigitalOut Led3(LED3); |
sophia | 1:838565907c81 | 30 | DigitalOut Led4(LED4); |
sophia | 2:503467a441e6 | 31 | |
sophia | 1:838565907c81 | 32 | InterruptIn Taster1(p17); |
sophia | 1:838565907c81 | 33 | InterruptIn Taster2(p18); |
sophia | 1:838565907c81 | 34 | InterruptIn Taster3(p19); |
sophia | 1:838565907c81 | 35 | InterruptIn Taster4(p20); |
sophia | 1:838565907c81 | 36 | InterruptIn InternTaster1(P1_16); |
sophia | 1:838565907c81 | 37 | InterruptIn InternTaster2(P0_23); |
sophia | 1:838565907c81 | 38 | InterruptIn InternTaster3(P0_10); |
sophia | 1:838565907c81 | 39 | InterruptIn InternTaster4(P0_15); |
sophia | 1:838565907c81 | 40 | |
sophia | 1:838565907c81 | 41 | PwmOut Summer(p6); |
sophia | 2:503467a441e6 | 42 | |
sophia | 1:838565907c81 | 43 | LedOut RGBStripe(p25); |
sophia | 1:838565907c81 | 44 | // (CLK, I/O) |
sophia | 1:838565907c81 | 45 | DigitDisplay TimerDisplay(p21, p22); |
sophia | 1:838565907c81 | 46 | // (CLK, I/O) |
sophia | 1:838565907c81 | 47 | DigitDisplay UhrDisplay(p23, p24); |
sophia | 1:838565907c81 | 48 | uint8_t hour, minute, sec; |
sophia | 1:838565907c81 | 49 | |
sophia | 2:503467a441e6 | 50 | int zahl =01; // Schmiedi mach was mit den Tastern, dass man die Zahl einstellen kann |
sophia | 1:838565907c81 | 51 | int second = 00; |
sophia | 0:925e9ab5be17 | 52 | int t; |
sophia | 0:925e9ab5be17 | 53 | int h; |
sophia | 0:925e9ab5be17 | 54 | int z; |
sophia | 0:925e9ab5be17 | 55 | int e; |
sophia | 0:925e9ab5be17 | 56 | bool colon = true; |
sophia | 0:925e9ab5be17 | 57 | |
sophia | 1:838565907c81 | 58 | int color; |
sophia | 1:838565907c81 | 59 | |
sophia | 1:838565907c81 | 60 | Serial pc(USBTX, USBRX); |
sophia | 1:838565907c81 | 61 | |
sophia | 0:925e9ab5be17 | 62 | void berechne() |
sophia | 0:925e9ab5be17 | 63 | { |
sophia | 0:925e9ab5be17 | 64 | t= zahl/10; |
sophia | 0:925e9ab5be17 | 65 | h= (zahl-(t*10))/1; |
sophia | 1:838565907c81 | 66 | z= second/10; |
sophia | 1:838565907c81 | 67 | e= (second-(z*10))/1; |
sophia | 1:838565907c81 | 68 | } |
sophia | 1:838565907c81 | 69 | |
sophia | 2:503467a441e6 | 70 | void ausgabe(int zahlzurzeit, int vergleich) |
sophia | 1:838565907c81 | 71 | { |
sophia | 1:838565907c81 | 72 | TimerDisplay.write(0, t); |
sophia | 1:838565907c81 | 73 | TimerDisplay.write(1, h); |
sophia | 1:838565907c81 | 74 | TimerDisplay.write(2, z); |
sophia | 1:838565907c81 | 75 | TimerDisplay.write(3, e); |
sophia | 2:503467a441e6 | 76 | //pc.printf("\n %d %d : %d %d" ,t, h ,z,e); |
sophia | 2:503467a441e6 | 77 | pc.printf("Zahl: %d, Vergleich: %d", zahlzurzeit, vergleich); |
sophia | 0:925e9ab5be17 | 78 | } |
sophia | 0:925e9ab5be17 | 79 | |
sophia | 2:503467a441e6 | 80 | void SummerOut() |
sophia | 2:503467a441e6 | 81 | { |
sophia | 2:503467a441e6 | 82 | // specify period first, then everything else |
sophia | 2:503467a441e6 | 83 | Summer.period(0.001f); // 4 second period |
sophia | 2:503467a441e6 | 84 | Summer.pulsewidth(0.0004); // 2 second pulse (on) |
sophia | 2:503467a441e6 | 85 | // led flashing |
sophia | 2:503467a441e6 | 86 | //while(1); |
sophia | 2:503467a441e6 | 87 | } |
sophia | 1:838565907c81 | 88 | |
sophia | 1:838565907c81 | 89 | |
sophia | 1:838565907c81 | 90 | |
sophia | 1:838565907c81 | 91 | void StripeOut() |
sophia | 1:838565907c81 | 92 | { |
sophia | 1:838565907c81 | 93 | __disable_irq(); //Interrupt deaktivieren |
sophia | 1:838565907c81 | 94 | |
sophia | 2:503467a441e6 | 95 | |
sophia | 1:838565907c81 | 96 | for(int r=0; r<=10; r++) |
sophia | 1:838565907c81 | 97 | RGBStripe.WriteLed(color); //Farbe rausschreiben |
sophia | 1:838565907c81 | 98 | |
sophia | 2:503467a441e6 | 99 | |
sophia | 1:838565907c81 | 100 | __enable_irq(); //Interrupt reaktivieren |
sophia | 1:838565907c81 | 101 | } |
sophia | 1:838565907c81 | 102 | |
sophia | 1:838565907c81 | 103 | void UhrOut() |
sophia | 0:925e9ab5be17 | 104 | { |
sophia | 1:838565907c81 | 105 | hour = rtc.read(HOURS); |
sophia | 1:838565907c81 | 106 | minute = rtc.read(MINUTES); |
sophia | 1:838565907c81 | 107 | sec = rtc.read(SECONDS); |
sophia | 2:503467a441e6 | 108 | /* |
sophia | 2:503467a441e6 | 109 | UhrDisplay.write(0, (minute >> 4)- 8); |
sophia | 2:503467a441e6 | 110 | UhrDisplay.write(1, (minute & 0x0F)); |
sophia | 2:503467a441e6 | 111 | UhrDisplay.setColon(1); |
sophia | 2:503467a441e6 | 112 | UhrDisplay.write(2, (sec >> 4)- 8); |
sophia | 2:503467a441e6 | 113 | UhrDisplay.write(3, (sec & 0x0F));*/ |
sophia | 1:838565907c81 | 114 | |
sophia | 2:503467a441e6 | 115 | UhrDisplay.write(0, (hour >> 4) & 0x03); |
sophia | 2:503467a441e6 | 116 | UhrDisplay.write(1, (hour & 0x0F)); |
sophia | 1:838565907c81 | 117 | UhrDisplay.setColon(1); |
sophia | 2:503467a441e6 | 118 | UhrDisplay.write(2, (minute >> 4)- 8); |
sophia | 2:503467a441e6 | 119 | UhrDisplay.write(3, (minute & 0x0F)); |
sophia | 2:503467a441e6 | 120 | } |
sophia | 2:503467a441e6 | 121 | |
sophia | 2:503467a441e6 | 122 | void changecolor(int vergleich, int zahlzurzeit) |
sophia | 1:838565907c81 | 123 | { |
sophia | 2:503467a441e6 | 124 | if(zahlzurzeit<=vergleich) { |
sophia | 2:503467a441e6 | 125 | color = hRGb; |
sophia | 2:503467a441e6 | 126 | |
sophia | 2:503467a441e6 | 127 | if(zahlzurzeit <= 1) |
sophia | 2:503467a441e6 | 128 | color = hRgb; |
sophia | 2:503467a441e6 | 129 | } else |
sophia | 2:503467a441e6 | 130 | color = hrGb; |
sophia | 2:503467a441e6 | 131 | |
sophia | 2:503467a441e6 | 132 | |
sophia | 0:925e9ab5be17 | 133 | } |
sophia | 0:925e9ab5be17 | 134 | |
sophia | 2:503467a441e6 | 135 | |
sophia | 2:503467a441e6 | 136 | |
sophia | 1:838565907c81 | 137 | int main() |
sophia | 0:925e9ab5be17 | 138 | { |
sophia | 2:503467a441e6 | 139 | UhrTick.attach(UhrOut, 0.1); |
sophia | 2:503467a441e6 | 140 | int vergleich=(zahl*60)*0.2; |
sophia | 1:838565907c81 | 141 | |
sophia | 0:925e9ab5be17 | 142 | while(1) { |
sophia | 2:503467a441e6 | 143 | for( int x = (zahl+1); x > 0; x--) { |
sophia | 2:503467a441e6 | 144 | for (int y=second; y > 0; y--) { |
sophia | 1:838565907c81 | 145 | |
sophia | 1:838565907c81 | 146 | |
sophia | 2:503467a441e6 | 147 | int zahlzurzeit = (y+x*60)-60; |
sophia | 2:503467a441e6 | 148 | changecolor(vergleich,zahlzurzeit); |
sophia | 1:838565907c81 | 149 | |
sophia | 1:838565907c81 | 150 | TimerDisplay.setColon(colon); |
sophia | 1:838565907c81 | 151 | second--; |
sophia | 1:838565907c81 | 152 | berechne(); |
sophia | 2:503467a441e6 | 153 | ausgabe(zahlzurzeit, vergleich); |
sophia | 1:838565907c81 | 154 | StripeOut(); |
sophia | 1:838565907c81 | 155 | |
sophia | 2:503467a441e6 | 156 | wait(1); |
sophia | 1:838565907c81 | 157 | } |
sophia | 1:838565907c81 | 158 | zahl--; |
sophia | 1:838565907c81 | 159 | second = 60; |
sophia | 0:925e9ab5be17 | 160 | } |
sophia | 1:838565907c81 | 161 | |
sophia | 2:503467a441e6 | 162 | SummerOut(); |
sophia | 1:838565907c81 | 163 | TimerDisplay.on(); |
sophia | 0:925e9ab5be17 | 164 | wait(0.5); |
sophia | 2:503467a441e6 | 165 | SummerOut(); |
sophia | 1:838565907c81 | 166 | TimerDisplay.off(); |
sophia | 0:925e9ab5be17 | 167 | wait(0.5); |
sophia | 1:838565907c81 | 168 | |
sophia | 2:503467a441e6 | 169 | |
sophia | 0:925e9ab5be17 | 170 | } |
sophia | 0:925e9ab5be17 | 171 | } |