Class to display Time in words on WS2812B-LED-Stripe. * Drive LEDs with PixelArray * with 11x10 LED-Matrix and 4 minute-LEDS * GERMAN LAYOUT !!!!!!
Details and usage see https://os.mbed.com/users/charly/code/WordClock/wiki/Homepage
WordClock.cpp@0:0f571ea154f8, 2017-11-05 (annotated)
- Committer:
- charly
- Date:
- Sun Nov 05 20:30:51 2017 +0000
- Revision:
- 0:0f571ea154f8
- Child:
- 1:dd9657c12de6
Class to display time in words with WS2812B LEDs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
charly | 0:0f571ea154f8 | 1 | #include "mbed.h" |
charly | 0:0f571ea154f8 | 2 | #include "WordClock.h" |
charly | 0:0f571ea154f8 | 3 | #include "neopixel.h" |
charly | 0:0f571ea154f8 | 4 | |
charly | 0:0f571ea154f8 | 5 | WordClock::WordClock (PinName pin) : di_pin_(pin, PullDown), array_(pin) |
charly | 0:0f571ea154f8 | 6 | { |
charly | 0:0f571ea154f8 | 7 | |
charly | 0:0f571ea154f8 | 8 | // Create a temporary DigitalIn so we can configure the pull-down resistor. |
charly | 0:0f571ea154f8 | 9 | // (The mbed API doesn't provide any other way to do this.) |
charly | 0:0f571ea154f8 | 10 | // An alternative is to connect an external pull-down resistor. |
charly | 0:0f571ea154f8 | 11 | //DigitalIn(pin, PullDown); |
charly | 0:0f571ea154f8 | 12 | // The pixel array control class. |
charly | 0:0f571ea154f8 | 13 | //neopixel::PixelArray array(pin); |
charly | 0:0f571ea154f8 | 14 | |
charly | 0:0f571ea154f8 | 15 | // initialize hsv |
charly | 0:0f571ea154f8 | 16 | //hue_ = 0.0; //red |
charly | 0:0f571ea154f8 | 17 | hue_ = 0.2917; //limett-green |
charly | 0:0f571ea154f8 | 18 | saturation_ = 1.0; //full color |
charly | 0:0f571ea154f8 | 19 | value_ = 1.0; //brightness |
charly | 0:0f571ea154f8 | 20 | |
charly | 0:0f571ea154f8 | 21 | } |
charly | 0:0f571ea154f8 | 22 | |
charly | 0:0f571ea154f8 | 23 | /** Convert a color from the HSV representation to RGB. |
charly | 0:0f571ea154f8 | 24 | * |
charly | 0:0f571ea154f8 | 25 | * @param h hue 0.0 ... 1.0 |
charly | 0:0f571ea154f8 | 26 | * @param s saturation 0.0 ... 1.0 |
charly | 0:0f571ea154f8 | 27 | * @param v value 0.0 ... 1.0 |
charly | 0:0f571ea154f8 | 28 | */ |
charly | 0:0f571ea154f8 | 29 | neopixel::Pixel WordClock::hsvToRgb(float h, float s, float v) |
charly | 0:0f571ea154f8 | 30 | { |
charly | 0:0f571ea154f8 | 31 | int i = floor(h * 6); |
charly | 0:0f571ea154f8 | 32 | float f = h * 6 - i; |
charly | 0:0f571ea154f8 | 33 | float p = v * (1 - s); |
charly | 0:0f571ea154f8 | 34 | float q = v * (1 - f * s); |
charly | 0:0f571ea154f8 | 35 | float t = v * (1 - (1 - f) * s); |
charly | 0:0f571ea154f8 | 36 | float r = 0, g = 0, b = 0; |
charly | 0:0f571ea154f8 | 37 | switch(i % 6) { |
charly | 0:0f571ea154f8 | 38 | case 0: |
charly | 0:0f571ea154f8 | 39 | r = v; |
charly | 0:0f571ea154f8 | 40 | g = t; |
charly | 0:0f571ea154f8 | 41 | b = p; |
charly | 0:0f571ea154f8 | 42 | break; |
charly | 0:0f571ea154f8 | 43 | case 1: |
charly | 0:0f571ea154f8 | 44 | r = q; |
charly | 0:0f571ea154f8 | 45 | g = v; |
charly | 0:0f571ea154f8 | 46 | b = p; |
charly | 0:0f571ea154f8 | 47 | break; |
charly | 0:0f571ea154f8 | 48 | case 2: |
charly | 0:0f571ea154f8 | 49 | r = p; |
charly | 0:0f571ea154f8 | 50 | g = v; |
charly | 0:0f571ea154f8 | 51 | b = t; |
charly | 0:0f571ea154f8 | 52 | break; |
charly | 0:0f571ea154f8 | 53 | case 3: |
charly | 0:0f571ea154f8 | 54 | r = p; |
charly | 0:0f571ea154f8 | 55 | g = q; |
charly | 0:0f571ea154f8 | 56 | b = v; |
charly | 0:0f571ea154f8 | 57 | break; |
charly | 0:0f571ea154f8 | 58 | case 4: |
charly | 0:0f571ea154f8 | 59 | r = t; |
charly | 0:0f571ea154f8 | 60 | g = p; |
charly | 0:0f571ea154f8 | 61 | b = v; |
charly | 0:0f571ea154f8 | 62 | break; |
charly | 0:0f571ea154f8 | 63 | case 5: |
charly | 0:0f571ea154f8 | 64 | r = v; |
charly | 0:0f571ea154f8 | 65 | g = p; |
charly | 0:0f571ea154f8 | 66 | b = q; |
charly | 0:0f571ea154f8 | 67 | break; |
charly | 0:0f571ea154f8 | 68 | } |
charly | 0:0f571ea154f8 | 69 | return (neopixel::Pixel) { |
charly | 0:0f571ea154f8 | 70 | r * 255, g * 255, b * 255 |
charly | 0:0f571ea154f8 | 71 | }; |
charly | 0:0f571ea154f8 | 72 | } |
charly | 0:0f571ea154f8 | 73 | |
charly | 0:0f571ea154f8 | 74 | void WordClock::cls() |
charly | 0:0f571ea154f8 | 75 | { |
charly | 0:0f571ea154f8 | 76 | int i; |
charly | 0:0f571ea154f8 | 77 | for (i=0; i<NUMLEDS; i++) { |
charly | 0:0f571ea154f8 | 78 | ledstripe_[i].red=0; |
charly | 0:0f571ea154f8 | 79 | ledstripe_[i].green=0; |
charly | 0:0f571ea154f8 | 80 | ledstripe_[i].blue=0; |
charly | 0:0f571ea154f8 | 81 | } |
charly | 0:0f571ea154f8 | 82 | } |
charly | 0:0f571ea154f8 | 83 | |
charly | 0:0f571ea154f8 | 84 | void WordClock::es_ist() |
charly | 0:0f571ea154f8 | 85 | { |
charly | 0:0f571ea154f8 | 86 | ledstripe_[0] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 87 | ledstripe_[1] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 88 | ledstripe_[3] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 89 | ledstripe_[4] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 90 | ledstripe_[5] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 91 | } |
charly | 0:0f571ea154f8 | 92 | void WordClock::fuenf_m() |
charly | 0:0f571ea154f8 | 93 | { |
charly | 0:0f571ea154f8 | 94 | ledstripe_[7] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 95 | ledstripe_[8] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 96 | ledstripe_[9] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 97 | ledstripe_[10]= hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 98 | } |
charly | 0:0f571ea154f8 | 99 | void WordClock::zehn_m() |
charly | 0:0f571ea154f8 | 100 | { |
charly | 0:0f571ea154f8 | 101 | ledstripe_[21] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 102 | ledstripe_[20] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 103 | ledstripe_[19] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 104 | ledstripe_[18] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 105 | } |
charly | 0:0f571ea154f8 | 106 | |
charly | 0:0f571ea154f8 | 107 | void WordClock::zwanzig() |
charly | 0:0f571ea154f8 | 108 | { |
charly | 0:0f571ea154f8 | 109 | ledstripe_[17] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 110 | ledstripe_[16] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 111 | ledstripe_[15] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 112 | ledstripe_[14] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 113 | ledstripe_[13] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 114 | ledstripe_[12] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 115 | ledstripe_[11] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 116 | } |
charly | 0:0f571ea154f8 | 117 | |
charly | 0:0f571ea154f8 | 118 | void WordClock::drei_m() |
charly | 0:0f571ea154f8 | 119 | { |
charly | 0:0f571ea154f8 | 120 | ledstripe_[22] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 121 | ledstripe_[23] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 122 | ledstripe_[24] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 123 | ledstripe_[25] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 124 | } |
charly | 0:0f571ea154f8 | 125 | |
charly | 0:0f571ea154f8 | 126 | void WordClock::vier_m() |
charly | 0:0f571ea154f8 | 127 | { |
charly | 0:0f571ea154f8 | 128 | ledstripe_[26] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 129 | ledstripe_[27] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 130 | ledstripe_[28] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 131 | ledstripe_[29] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 132 | } |
charly | 0:0f571ea154f8 | 133 | |
charly | 0:0f571ea154f8 | 134 | void WordClock::tel() |
charly | 0:0f571ea154f8 | 135 | { |
charly | 0:0f571ea154f8 | 136 | ledstripe_[30] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 137 | ledstripe_[31] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 138 | ledstripe_[32] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 139 | } |
charly | 0:0f571ea154f8 | 140 | |
charly | 0:0f571ea154f8 | 141 | void WordClock::nach() |
charly | 0:0f571ea154f8 | 142 | { |
charly | 0:0f571ea154f8 | 143 | ledstripe_[41] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 144 | ledstripe_[40] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 145 | ledstripe_[39] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 146 | ledstripe_[38] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 147 | } |
charly | 0:0f571ea154f8 | 148 | |
charly | 0:0f571ea154f8 | 149 | void WordClock::vor() |
charly | 0:0f571ea154f8 | 150 | { |
charly | 0:0f571ea154f8 | 151 | ledstripe_[37] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 152 | ledstripe_[36] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 153 | ledstripe_[35] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 154 | } |
charly | 0:0f571ea154f8 | 155 | |
charly | 0:0f571ea154f8 | 156 | void WordClock::halb() |
charly | 0:0f571ea154f8 | 157 | { |
charly | 0:0f571ea154f8 | 158 | ledstripe_[44] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 159 | ledstripe_[45] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 160 | ledstripe_[46] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 161 | ledstripe_[47] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 162 | } |
charly | 0:0f571ea154f8 | 163 | |
charly | 0:0f571ea154f8 | 164 | void WordClock::zwoelf() |
charly | 0:0f571ea154f8 | 165 | { |
charly | 0:0f571ea154f8 | 166 | ledstripe_[49] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 167 | ledstripe_[50] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 168 | ledstripe_[51] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 169 | ledstripe_[52] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 170 | ledstripe_[53] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 171 | } |
charly | 0:0f571ea154f8 | 172 | |
charly | 0:0f571ea154f8 | 173 | void WordClock::zwei() |
charly | 0:0f571ea154f8 | 174 | { |
charly | 0:0f571ea154f8 | 175 | ledstripe_[65] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 176 | ledstripe_[64] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 177 | ledstripe_[63] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 178 | ledstripe_[62] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 179 | } |
charly | 0:0f571ea154f8 | 180 | |
charly | 0:0f571ea154f8 | 181 | void WordClock::eins() |
charly | 0:0f571ea154f8 | 182 | { |
charly | 0:0f571ea154f8 | 183 | ledstripe_[63] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 184 | ledstripe_[62] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 185 | ledstripe_[61] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 186 | ledstripe_[60] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 187 | } |
charly | 0:0f571ea154f8 | 188 | |
charly | 0:0f571ea154f8 | 189 | void WordClock::ein() |
charly | 0:0f571ea154f8 | 190 | { |
charly | 0:0f571ea154f8 | 191 | ledstripe_[63] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 192 | ledstripe_[62] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 193 | ledstripe_[61] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 194 | } |
charly | 0:0f571ea154f8 | 195 | |
charly | 0:0f571ea154f8 | 196 | void WordClock::sieben() |
charly | 0:0f571ea154f8 | 197 | { |
charly | 0:0f571ea154f8 | 198 | ledstripe_[60] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 199 | ledstripe_[59] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 200 | ledstripe_[58] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 201 | ledstripe_[57] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 202 | ledstripe_[56] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 203 | ledstripe_[55] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 204 | |
charly | 0:0f571ea154f8 | 205 | } |
charly | 0:0f571ea154f8 | 206 | |
charly | 0:0f571ea154f8 | 207 | void WordClock::drei_h() |
charly | 0:0f571ea154f8 | 208 | { |
charly | 0:0f571ea154f8 | 209 | ledstripe_[67] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 210 | ledstripe_[68] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 211 | ledstripe_[69] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 212 | ledstripe_[70] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 213 | } |
charly | 0:0f571ea154f8 | 214 | |
charly | 0:0f571ea154f8 | 215 | void WordClock::fuenf_h() |
charly | 0:0f571ea154f8 | 216 | { |
charly | 0:0f571ea154f8 | 217 | ledstripe_[73] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 218 | ledstripe_[74] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 219 | ledstripe_[75] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 220 | ledstripe_[76] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 221 | } |
charly | 0:0f571ea154f8 | 222 | |
charly | 0:0f571ea154f8 | 223 | void WordClock::elf() |
charly | 0:0f571ea154f8 | 224 | { |
charly | 0:0f571ea154f8 | 225 | ledstripe_[87] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 226 | ledstripe_[86] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 227 | ledstripe_[85] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 228 | } |
charly | 0:0f571ea154f8 | 229 | |
charly | 0:0f571ea154f8 | 230 | void WordClock::neun() |
charly | 0:0f571ea154f8 | 231 | { |
charly | 0:0f571ea154f8 | 232 | ledstripe_[84] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 233 | ledstripe_[83] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 234 | ledstripe_[82] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 235 | ledstripe_[81] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 236 | } |
charly | 0:0f571ea154f8 | 237 | |
charly | 0:0f571ea154f8 | 238 | void WordClock::vier_h() |
charly | 0:0f571ea154f8 | 239 | { |
charly | 0:0f571ea154f8 | 240 | ledstripe_[80] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 241 | ledstripe_[79] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 242 | ledstripe_[78] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 243 | ledstripe_[77] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 244 | } |
charly | 0:0f571ea154f8 | 245 | |
charly | 0:0f571ea154f8 | 246 | void WordClock::acht() |
charly | 0:0f571ea154f8 | 247 | { |
charly | 0:0f571ea154f8 | 248 | ledstripe_[89] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 249 | ledstripe_[90] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 250 | ledstripe_[91] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 251 | ledstripe_[92] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 252 | } |
charly | 0:0f571ea154f8 | 253 | |
charly | 0:0f571ea154f8 | 254 | void WordClock::zehn_h() |
charly | 0:0f571ea154f8 | 255 | { |
charly | 0:0f571ea154f8 | 256 | ledstripe_[93] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 257 | ledstripe_[94] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 258 | ledstripe_[95] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 259 | ledstripe_[96] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 260 | } |
charly | 0:0f571ea154f8 | 261 | |
charly | 0:0f571ea154f8 | 262 | void WordClock::sechs() |
charly | 0:0f571ea154f8 | 263 | { |
charly | 0:0f571ea154f8 | 264 | ledstripe_[108] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 265 | ledstripe_[107] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 266 | ledstripe_[106] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 267 | ledstripe_[105] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 268 | ledstripe_[104] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 269 | } |
charly | 0:0f571ea154f8 | 270 | |
charly | 0:0f571ea154f8 | 271 | void WordClock::uhr() |
charly | 0:0f571ea154f8 | 272 | { |
charly | 0:0f571ea154f8 | 273 | ledstripe_[101] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 274 | ledstripe_[100] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 275 | ledstripe_[99] = hsvToRgb(hue_, saturation_, value_); |
charly | 0:0f571ea154f8 | 276 | } |
charly | 0:0f571ea154f8 | 277 | |
charly | 0:0f571ea154f8 | 278 | void WordClock::m1(int second) |
charly | 0:0f571ea154f8 | 279 | { |
charly | 0:0f571ea154f8 | 280 | ledstripe_[110] = hsvToRgb(hue_, saturation_, float(second)/60); |
charly | 0:0f571ea154f8 | 281 | } |
charly | 0:0f571ea154f8 | 282 | |
charly | 0:0f571ea154f8 | 283 | void WordClock::m2(int second) |
charly | 0:0f571ea154f8 | 284 | { |
charly | 0:0f571ea154f8 | 285 | ledstripe_[111] = hsvToRgb(hue_, saturation_, float(second)/60); |
charly | 0:0f571ea154f8 | 286 | } |
charly | 0:0f571ea154f8 | 287 | |
charly | 0:0f571ea154f8 | 288 | void WordClock::m3(int second) |
charly | 0:0f571ea154f8 | 289 | { |
charly | 0:0f571ea154f8 | 290 | ledstripe_[112] = hsvToRgb(hue_, saturation_, float(second)/60); |
charly | 0:0f571ea154f8 | 291 | } |
charly | 0:0f571ea154f8 | 292 | |
charly | 0:0f571ea154f8 | 293 | void WordClock::m4(int second) |
charly | 0:0f571ea154f8 | 294 | { |
charly | 0:0f571ea154f8 | 295 | ledstripe_[113] = hsvToRgb(hue_, saturation_, float(second)/60); |
charly | 0:0f571ea154f8 | 296 | } |
charly | 0:0f571ea154f8 | 297 | |
charly | 0:0f571ea154f8 | 298 | |
charly | 0:0f571ea154f8 | 299 | void WordClock::test_display(int option, int index) |
charly | 0:0f571ea154f8 | 300 | { |
charly | 0:0f571ea154f8 | 301 | cls(); |
charly | 0:0f571ea154f8 | 302 | //build and display the content of ledarray |
charly | 0:0f571ea154f8 | 303 | switch (option) { |
charly | 0:0f571ea154f8 | 304 | case 1 : { |
charly | 0:0f571ea154f8 | 305 | // color gradient from red to red through hsv colors |
charly | 0:0f571ea154f8 | 306 | for (int i=0; i<NUMLEDS; i++) { |
charly | 0:0f571ea154f8 | 307 | ledstripe_[i] = hsvToRgb(1.0*i/NUMLEDS, saturation_, value_); |
charly | 0:0f571ea154f8 | 308 | } |
charly | 0:0f571ea154f8 | 309 | array_.update(ledstripe_,NUMLEDS); |
charly | 0:0f571ea154f8 | 310 | break; |
charly | 0:0f571ea154f8 | 311 | } |
charly | 0:0f571ea154f8 | 312 | case 2 : { |
charly | 0:0f571ea154f8 | 313 | //display one LED in WHite, full brightness |
charly | 0:0f571ea154f8 | 314 | ledstripe_[index] = hsvToRgb(1.0, 0.0, 1.0);//white |
charly | 0:0f571ea154f8 | 315 | array_.update(ledstripe_,NUMLEDS); |
charly | 0:0f571ea154f8 | 316 | break; |
charly | 0:0f571ea154f8 | 317 | } |
charly | 0:0f571ea154f8 | 318 | case 3 : { |
charly | 0:0f571ea154f8 | 319 | //display a word |
charly | 0:0f571ea154f8 | 320 | cls(); |
charly | 0:0f571ea154f8 | 321 | switch (index) { |
charly | 0:0f571ea154f8 | 322 | case 1: { |
charly | 0:0f571ea154f8 | 323 | es_ist(); |
charly | 0:0f571ea154f8 | 324 | break; |
charly | 0:0f571ea154f8 | 325 | } |
charly | 0:0f571ea154f8 | 326 | case 2: { |
charly | 0:0f571ea154f8 | 327 | fuenf_m(); |
charly | 0:0f571ea154f8 | 328 | break; |
charly | 0:0f571ea154f8 | 329 | } |
charly | 0:0f571ea154f8 | 330 | case 3: { |
charly | 0:0f571ea154f8 | 331 | zehn_m(); |
charly | 0:0f571ea154f8 | 332 | break; |
charly | 0:0f571ea154f8 | 333 | } |
charly | 0:0f571ea154f8 | 334 | case 4: { |
charly | 0:0f571ea154f8 | 335 | zwanzig(); |
charly | 0:0f571ea154f8 | 336 | break; |
charly | 0:0f571ea154f8 | 337 | } |
charly | 0:0f571ea154f8 | 338 | case 5: { |
charly | 0:0f571ea154f8 | 339 | drei_m(); |
charly | 0:0f571ea154f8 | 340 | break; |
charly | 0:0f571ea154f8 | 341 | } |
charly | 0:0f571ea154f8 | 342 | case 6: { |
charly | 0:0f571ea154f8 | 343 | vier_m(); |
charly | 0:0f571ea154f8 | 344 | break; |
charly | 0:0f571ea154f8 | 345 | } |
charly | 0:0f571ea154f8 | 346 | case 7: { |
charly | 0:0f571ea154f8 | 347 | tel(); |
charly | 0:0f571ea154f8 | 348 | break; |
charly | 0:0f571ea154f8 | 349 | } |
charly | 0:0f571ea154f8 | 350 | case 8: { |
charly | 0:0f571ea154f8 | 351 | nach(); |
charly | 0:0f571ea154f8 | 352 | break; |
charly | 0:0f571ea154f8 | 353 | } |
charly | 0:0f571ea154f8 | 354 | case 9: { |
charly | 0:0f571ea154f8 | 355 | vor(); |
charly | 0:0f571ea154f8 | 356 | break; |
charly | 0:0f571ea154f8 | 357 | } |
charly | 0:0f571ea154f8 | 358 | case 10: { |
charly | 0:0f571ea154f8 | 359 | halb(); |
charly | 0:0f571ea154f8 | 360 | break; |
charly | 0:0f571ea154f8 | 361 | } |
charly | 0:0f571ea154f8 | 362 | case 11: { |
charly | 0:0f571ea154f8 | 363 | zwoelf(); |
charly | 0:0f571ea154f8 | 364 | break; |
charly | 0:0f571ea154f8 | 365 | } |
charly | 0:0f571ea154f8 | 366 | case 12: { |
charly | 0:0f571ea154f8 | 367 | zwei(); |
charly | 0:0f571ea154f8 | 368 | break; |
charly | 0:0f571ea154f8 | 369 | } |
charly | 0:0f571ea154f8 | 370 | case 13: { |
charly | 0:0f571ea154f8 | 371 | eins(); |
charly | 0:0f571ea154f8 | 372 | break; |
charly | 0:0f571ea154f8 | 373 | } |
charly | 0:0f571ea154f8 | 374 | case 14: { |
charly | 0:0f571ea154f8 | 375 | sieben(); |
charly | 0:0f571ea154f8 | 376 | break; |
charly | 0:0f571ea154f8 | 377 | } |
charly | 0:0f571ea154f8 | 378 | case 15: { |
charly | 0:0f571ea154f8 | 379 | drei_h(); |
charly | 0:0f571ea154f8 | 380 | break; |
charly | 0:0f571ea154f8 | 381 | } |
charly | 0:0f571ea154f8 | 382 | case 16: { |
charly | 0:0f571ea154f8 | 383 | fuenf_h(); |
charly | 0:0f571ea154f8 | 384 | break; |
charly | 0:0f571ea154f8 | 385 | } |
charly | 0:0f571ea154f8 | 386 | case 17: { |
charly | 0:0f571ea154f8 | 387 | elf(); |
charly | 0:0f571ea154f8 | 388 | break; |
charly | 0:0f571ea154f8 | 389 | } |
charly | 0:0f571ea154f8 | 390 | case 18: { |
charly | 0:0f571ea154f8 | 391 | neun(); |
charly | 0:0f571ea154f8 | 392 | break; |
charly | 0:0f571ea154f8 | 393 | } |
charly | 0:0f571ea154f8 | 394 | case 19: { |
charly | 0:0f571ea154f8 | 395 | vier_h(); |
charly | 0:0f571ea154f8 | 396 | break; |
charly | 0:0f571ea154f8 | 397 | } |
charly | 0:0f571ea154f8 | 398 | case 20: { |
charly | 0:0f571ea154f8 | 399 | acht(); |
charly | 0:0f571ea154f8 | 400 | break; |
charly | 0:0f571ea154f8 | 401 | } |
charly | 0:0f571ea154f8 | 402 | case 21: { |
charly | 0:0f571ea154f8 | 403 | zehn_h(); |
charly | 0:0f571ea154f8 | 404 | break; |
charly | 0:0f571ea154f8 | 405 | } |
charly | 0:0f571ea154f8 | 406 | case 22: { |
charly | 0:0f571ea154f8 | 407 | sechs(); |
charly | 0:0f571ea154f8 | 408 | break; |
charly | 0:0f571ea154f8 | 409 | } |
charly | 0:0f571ea154f8 | 410 | case 23: { |
charly | 0:0f571ea154f8 | 411 | uhr(); |
charly | 0:0f571ea154f8 | 412 | break; |
charly | 0:0f571ea154f8 | 413 | } |
charly | 0:0f571ea154f8 | 414 | case 24: { |
charly | 0:0f571ea154f8 | 415 | m1(); |
charly | 0:0f571ea154f8 | 416 | break; |
charly | 0:0f571ea154f8 | 417 | } |
charly | 0:0f571ea154f8 | 418 | case 25: { |
charly | 0:0f571ea154f8 | 419 | m2(); |
charly | 0:0f571ea154f8 | 420 | break; |
charly | 0:0f571ea154f8 | 421 | } |
charly | 0:0f571ea154f8 | 422 | case 26: { |
charly | 0:0f571ea154f8 | 423 | m3(); |
charly | 0:0f571ea154f8 | 424 | break; |
charly | 0:0f571ea154f8 | 425 | } |
charly | 0:0f571ea154f8 | 426 | case 27: { |
charly | 0:0f571ea154f8 | 427 | m4(); |
charly | 0:0f571ea154f8 | 428 | break; |
charly | 0:0f571ea154f8 | 429 | } |
charly | 0:0f571ea154f8 | 430 | case 28: { |
charly | 0:0f571ea154f8 | 431 | ein(); |
charly | 0:0f571ea154f8 | 432 | break; |
charly | 0:0f571ea154f8 | 433 | } |
charly | 0:0f571ea154f8 | 434 | |
charly | 0:0f571ea154f8 | 435 | |
charly | 0:0f571ea154f8 | 436 | }//switch |
charly | 0:0f571ea154f8 | 437 | array_.update(ledstripe_,NUMLEDS); |
charly | 0:0f571ea154f8 | 438 | break; |
charly | 0:0f571ea154f8 | 439 | } |
charly | 0:0f571ea154f8 | 440 | }//switch |
charly | 0:0f571ea154f8 | 441 | } |
charly | 0:0f571ea154f8 | 442 | |
charly | 0:0f571ea154f8 | 443 | void WordClock::display_time(int hour,int minute, int second) |
charly | 0:0f571ea154f8 | 444 | { |
charly | 0:0f571ea154f8 | 445 | //display the time in words |
charly | 0:0f571ea154f8 | 446 | if (hour < 0 ) hour = 0; |
charly | 0:0f571ea154f8 | 447 | if (hour > 23 ) hour = 23; |
charly | 0:0f571ea154f8 | 448 | if (minute < 0) minute = 0; |
charly | 0:0f571ea154f8 | 449 | if (minute > 59) minute = 59; |
charly | 0:0f571ea154f8 | 450 | if (second < 0) second = 0; |
charly | 0:0f571ea154f8 | 451 | if (second > 59) second = 59; |
charly | 0:0f571ea154f8 | 452 | |
charly | 0:0f571ea154f8 | 453 | //set the color depending on the hour |
charly | 0:0f571ea154f8 | 454 | hue_ = float(hour)/24; |
charly | 0:0f571ea154f8 | 455 | |
charly | 0:0f571ea154f8 | 456 | cls(); |
charly | 0:0f571ea154f8 | 457 | es_ist(); |
charly | 0:0f571ea154f8 | 458 | //minutes |
charly | 0:0f571ea154f8 | 459 | if (minute >=5 and minute <10) { |
charly | 0:0f571ea154f8 | 460 | fuenf_m(); |
charly | 0:0f571ea154f8 | 461 | nach(); |
charly | 0:0f571ea154f8 | 462 | } |
charly | 0:0f571ea154f8 | 463 | if (minute >=10 and minute <15) { |
charly | 0:0f571ea154f8 | 464 | zehn_m(); |
charly | 0:0f571ea154f8 | 465 | nach(); |
charly | 0:0f571ea154f8 | 466 | } |
charly | 0:0f571ea154f8 | 467 | if (minute >=15 and minute <20) { |
charly | 0:0f571ea154f8 | 468 | vier_m(); |
charly | 0:0f571ea154f8 | 469 | tel(); |
charly | 0:0f571ea154f8 | 470 | nach(); |
charly | 0:0f571ea154f8 | 471 | } |
charly | 0:0f571ea154f8 | 472 | if (minute >=20 and minute <25) { |
charly | 0:0f571ea154f8 | 473 | zwanzig(); |
charly | 0:0f571ea154f8 | 474 | nach(); |
charly | 0:0f571ea154f8 | 475 | } |
charly | 0:0f571ea154f8 | 476 | if (minute >=25 and minute <30) { |
charly | 0:0f571ea154f8 | 477 | fuenf_m(); |
charly | 0:0f571ea154f8 | 478 | vor(); |
charly | 0:0f571ea154f8 | 479 | halb(); |
charly | 0:0f571ea154f8 | 480 | hour++; |
charly | 0:0f571ea154f8 | 481 | } |
charly | 0:0f571ea154f8 | 482 | if (minute >= 30 and minute<35) { |
charly | 0:0f571ea154f8 | 483 | halb(); |
charly | 0:0f571ea154f8 | 484 | hour++; |
charly | 0:0f571ea154f8 | 485 | } |
charly | 0:0f571ea154f8 | 486 | if (minute >=35 and minute<40) { |
charly | 0:0f571ea154f8 | 487 | fuenf_m(); |
charly | 0:0f571ea154f8 | 488 | nach(); |
charly | 0:0f571ea154f8 | 489 | halb(); |
charly | 0:0f571ea154f8 | 490 | hour++; |
charly | 0:0f571ea154f8 | 491 | } |
charly | 0:0f571ea154f8 | 492 | if (minute >=40 and minute<45) { |
charly | 0:0f571ea154f8 | 493 | zwanzig(); |
charly | 0:0f571ea154f8 | 494 | vor(); |
charly | 0:0f571ea154f8 | 495 | hour++; |
charly | 0:0f571ea154f8 | 496 | } |
charly | 0:0f571ea154f8 | 497 | if (minute >=45 and minute<50) { |
charly | 0:0f571ea154f8 | 498 | drei_m(); |
charly | 0:0f571ea154f8 | 499 | vier_m(); |
charly | 0:0f571ea154f8 | 500 | tel(); |
charly | 0:0f571ea154f8 | 501 | hour++; |
charly | 0:0f571ea154f8 | 502 | } |
charly | 0:0f571ea154f8 | 503 | if (minute >=50 and minute<55) { |
charly | 0:0f571ea154f8 | 504 | zehn_m(); |
charly | 0:0f571ea154f8 | 505 | vor(); |
charly | 0:0f571ea154f8 | 506 | hour++; |
charly | 0:0f571ea154f8 | 507 | } |
charly | 0:0f571ea154f8 | 508 | if (minute >=55 and minute<60) { |
charly | 0:0f571ea154f8 | 509 | fuenf_m(); |
charly | 0:0f571ea154f8 | 510 | vor(); |
charly | 0:0f571ea154f8 | 511 | hour++; |
charly | 0:0f571ea154f8 | 512 | } |
charly | 0:0f571ea154f8 | 513 | //hours |
charly | 0:0f571ea154f8 | 514 | if (hour >=13) hour -= 12; |
charly | 0:0f571ea154f8 | 515 | switch (hour){ |
charly | 0:0f571ea154f8 | 516 | case 0:{ |
charly | 0:0f571ea154f8 | 517 | zwoelf(); |
charly | 0:0f571ea154f8 | 518 | break; |
charly | 0:0f571ea154f8 | 519 | } |
charly | 0:0f571ea154f8 | 520 | case 1:{ |
charly | 0:0f571ea154f8 | 521 | ein(); |
charly | 0:0f571ea154f8 | 522 | break; |
charly | 0:0f571ea154f8 | 523 | } |
charly | 0:0f571ea154f8 | 524 | case 2:{ |
charly | 0:0f571ea154f8 | 525 | zwei(); |
charly | 0:0f571ea154f8 | 526 | break; |
charly | 0:0f571ea154f8 | 527 | } |
charly | 0:0f571ea154f8 | 528 | case 3:{ |
charly | 0:0f571ea154f8 | 529 | drei_h(); |
charly | 0:0f571ea154f8 | 530 | break; |
charly | 0:0f571ea154f8 | 531 | } |
charly | 0:0f571ea154f8 | 532 | case 4:{ |
charly | 0:0f571ea154f8 | 533 | vier_h(); |
charly | 0:0f571ea154f8 | 534 | break; |
charly | 0:0f571ea154f8 | 535 | } |
charly | 0:0f571ea154f8 | 536 | case 5:{ |
charly | 0:0f571ea154f8 | 537 | fuenf_h(); |
charly | 0:0f571ea154f8 | 538 | break; |
charly | 0:0f571ea154f8 | 539 | } |
charly | 0:0f571ea154f8 | 540 | case 6:{ |
charly | 0:0f571ea154f8 | 541 | sechs(); |
charly | 0:0f571ea154f8 | 542 | break; |
charly | 0:0f571ea154f8 | 543 | } |
charly | 0:0f571ea154f8 | 544 | case 7:{ |
charly | 0:0f571ea154f8 | 545 | sieben(); |
charly | 0:0f571ea154f8 | 546 | break; |
charly | 0:0f571ea154f8 | 547 | } |
charly | 0:0f571ea154f8 | 548 | case 8:{ |
charly | 0:0f571ea154f8 | 549 | acht(); |
charly | 0:0f571ea154f8 | 550 | break; |
charly | 0:0f571ea154f8 | 551 | } |
charly | 0:0f571ea154f8 | 552 | case 9:{ |
charly | 0:0f571ea154f8 | 553 | neun(); |
charly | 0:0f571ea154f8 | 554 | break; |
charly | 0:0f571ea154f8 | 555 | } |
charly | 0:0f571ea154f8 | 556 | case 10:{ |
charly | 0:0f571ea154f8 | 557 | zehn_h(); |
charly | 0:0f571ea154f8 | 558 | break; |
charly | 0:0f571ea154f8 | 559 | } |
charly | 0:0f571ea154f8 | 560 | case 11:{ |
charly | 0:0f571ea154f8 | 561 | elf(); |
charly | 0:0f571ea154f8 | 562 | break; |
charly | 0:0f571ea154f8 | 563 | } |
charly | 0:0f571ea154f8 | 564 | case 12:{ |
charly | 0:0f571ea154f8 | 565 | zwoelf(); |
charly | 0:0f571ea154f8 | 566 | break; |
charly | 0:0f571ea154f8 | 567 | } |
charly | 0:0f571ea154f8 | 568 | }//switch hour |
charly | 0:0f571ea154f8 | 569 | uhr(); |
charly | 0:0f571ea154f8 | 570 | |
charly | 0:0f571ea154f8 | 571 | //minutes 0..4 and seconds in brigtness |
charly | 0:0f571ea154f8 | 572 | switch (minute%5){ |
charly | 0:0f571ea154f8 | 573 | case 0:{ |
charly | 0:0f571ea154f8 | 574 | m1(second); |
charly | 0:0f571ea154f8 | 575 | break; |
charly | 0:0f571ea154f8 | 576 | } |
charly | 0:0f571ea154f8 | 577 | case 1:{ |
charly | 0:0f571ea154f8 | 578 | m1(); |
charly | 0:0f571ea154f8 | 579 | m2(second); |
charly | 0:0f571ea154f8 | 580 | break; |
charly | 0:0f571ea154f8 | 581 | } |
charly | 0:0f571ea154f8 | 582 | case 2:{ |
charly | 0:0f571ea154f8 | 583 | m1(); |
charly | 0:0f571ea154f8 | 584 | m2(); |
charly | 0:0f571ea154f8 | 585 | m3(second); |
charly | 0:0f571ea154f8 | 586 | break; |
charly | 0:0f571ea154f8 | 587 | } |
charly | 0:0f571ea154f8 | 588 | case 3:{ |
charly | 0:0f571ea154f8 | 589 | m1(); |
charly | 0:0f571ea154f8 | 590 | m2(); |
charly | 0:0f571ea154f8 | 591 | m3(); |
charly | 0:0f571ea154f8 | 592 | m4(second); |
charly | 0:0f571ea154f8 | 593 | break; |
charly | 0:0f571ea154f8 | 594 | } |
charly | 0:0f571ea154f8 | 595 | case 4:{ |
charly | 0:0f571ea154f8 | 596 | // we don't have a 5th led for minute 4..5 |
charly | 0:0f571ea154f8 | 597 | // dim down all 4 LEDs |
charly | 0:0f571ea154f8 | 598 | m1(59-second); |
charly | 0:0f571ea154f8 | 599 | m2(59-second); |
charly | 0:0f571ea154f8 | 600 | m3(59-second); |
charly | 0:0f571ea154f8 | 601 | m4(59-second); |
charly | 0:0f571ea154f8 | 602 | break; |
charly | 0:0f571ea154f8 | 603 | } |
charly | 0:0f571ea154f8 | 604 | }//switch minute%5 |
charly | 0:0f571ea154f8 | 605 | //display the LED-Array |
charly | 0:0f571ea154f8 | 606 | array_.update(ledstripe_,NUMLEDS); |
charly | 0:0f571ea154f8 | 607 | } |