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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
|
#include <Adafruit_NeoPixel.h>
#include "RTClib.h"
#define RGBLEDPIN 6
#define N_LEDS 121
const byte hours_switch = 5;
const byte minutes_switch = 4;
const byte colors_switch = 3;
int hours_offset = 0;
int minutes_offset = 0;
int the_hours = 0;
int the_minutes = 0;
bool pm = false;
// initialisation module RTC
RTC_DS3231 rtc;
// initialisation NeoPixel
//Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, RGBLEDPIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip(N_LEDS, RGBLEDPIN, NEO_GRB + NEO_KHZ800);
// luminosité
int the_brightness = 50;
int colors_offset = 0;
boolean oldState = HIGH;
int mode = 0; // Currently-active animation mode, 0-9
// couleurs
//uint32_t color_white = strip.Color(255, 0, 255);
// tableau des mots
int words[31][15] = {
{0, 1, 3, 4, 5}, // #0 / IL EST
{7, 8, 9}, // #1 / UNE
{18, 19, 20, 21}, // #2 / DEUX
{12, 13, 14, 15, 16}, // #3 / TROIS
{22, 23, 24, 25, 26, 27}, // #4 / QUATRE
{29, 30, 31, 32}, // #5 / CINQ
{40, 41, 42}, // #6 / SIX
{35, 36, 37, 38}, // #7 / SEPT
{44, 45, 46, 47}, // #8 / HUIT
{48, 49, 50, 51}, // #9 / NEUF
{52, 53, 54}, // #10 / DIX
{62, 63, 64, 65}, // #11 / ONZE
{56, 57, 58, 59, 60}, // #12 / HEURE
{55, 56, 57, 58, 59, 60}, // #13 / HEURES
{73, 74, 75, 76}, // #14 / MIDI
{67, 68, 69, 70, 71, 72}, // #15 / MINUIT
{100, 101, 102, 103}, // #16 / CINQ (2)
{89, 90, 91}, // #17 / DIX (2)
{86, 87, 111, 112, 113, 114, 115}, // #18 / ET QUART
{105, 106, 107, 108, 109}, // #19 / VINGT
{100, 101, 102, 103, 105, 106, 107, 108, 109}, // #20 / VINGT CINQ
{86, 87, 93, 94, 95, 96, 97}, // #21 / ET DEMIE
{80, 81, 82, 83, 84, 105, 106, 107, 108, 109, 100, 101, 102, 103}, // #22 / MOINS VINGT-CINQ
{80, 81, 82, 83, 84, 105, 106, 107, 108, 109}, // #23 / MOINS VINGT
{80, 81, 82, 83, 84, 77, 78, 111, 112, 113, 114, 115}, // #24 / MOINS LE QUART
{80, 81, 82, 83, 84, 89, 90, 91}, // #25 / MOINS DIX
{80, 81, 82, 83, 84, 100, 101, 102, 103}, // #26 / MOINS CINQ
{117}, // #27 / 1 POINT
{117, 118}, // #28 / 2 POINTS
{117, 118, 119}, // #29 / 3 POINTS
{117, 118, 119, 120} // #30 / 4 POINTS
};
void setup() {
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
pinMode(hours_switch, INPUT_PULLUP);
pinMode(minutes_switch, INPUT_PULLUP);
pinMode(colors_switch, INPUT_PULLUP);
strip.begin();
strip.show();
strip.setBrightness(the_brightness);
}
void loop() {
if (digitalRead(hours_switch) == LOW) {
hours_offset++;
}
if (digitalRead(minutes_switch) == LOW) {
minutes_offset++;
}
strip.clear();
int what_time_is_it[5] = {};
what_time_is_it[0] = 0; // IL EST
DateTime now = rtc.now();
the_hours = now.hour();
the_minutes = now.minute();
the_hours += hours_offset;
the_minutes += minutes_offset;
while (the_minutes > 59) {
the_minutes -= 60;
the_hours++;
}
while (the_hours > 23) {
the_hours -= 24;
}
if (the_minutes >= 5 && the_minutes < 10) {
what_time_is_it[3] = 16; // CINQ (2)
}
else if (the_minutes >= 10 && the_minutes < 15) {
what_time_is_it[3] = 17; // DIX (2)
}
else if (the_minutes >= 15 && the_minutes < 20) {
what_time_is_it[3] = 18; // ET QUART
}
else if (the_minutes >= 20 && the_minutes < 25) {
what_time_is_it[3] = 19; // VINGT
}
else if (the_minutes >= 25 && the_minutes < 30) {
what_time_is_it[3] = 20; // VINGT-CINQ
}
else if (the_minutes >= 30 && the_minutes < 35) {
what_time_is_it[3] = 21; // ET DEMIE
}
else if (the_minutes >= 35 && the_minutes < 40) {
what_time_is_it[3] = 22; // MOINS VINGT-CINQ
}
else if (the_minutes >= 40 && the_minutes < 45) {
what_time_is_it[3] = 23; // MOINS VINGT
}
else if (the_minutes >= 45 && the_minutes < 50) {
what_time_is_it[3] = 24; // MOINS LE QUART
}
else if (the_minutes >= 50 && the_minutes < 55) {
what_time_is_it[3] = 25; // MOINS DIX
}
else if (the_minutes >= 55) {
what_time_is_it[3] = 26; // MOINS CINQ
}
if (the_minutes >= 35) {
the_hours++;
}
if (the_hours > 12) {
the_hours -= 12;
pm = true;
}
else {
pm = false;
}
int the_minutes_last_digit = the_minutes % 10;
switch (the_minutes_last_digit) {
case 1:
case 6:
what_time_is_it[4] = 27; // 1 POINT
break;
case 2:
case 7:
what_time_is_it[4] = 28; // 2 POINTS
break;
case 3:
case 8:
what_time_is_it[4] = 29; // 3 POINTS
break;
case 4:
case 9:
what_time_is_it[4] = 30; // 4 POINTS
break;
}
if (the_hours == 12 && !pm) {
what_time_is_it[1] = 14; // MIDI
}
else if (the_hours == 0 || (the_hours == 12 && pm)) {
what_time_is_it[1] = 15; // MINUIT
}
else {
what_time_is_it[1] = the_hours;
}
if (the_hours == 1) {
what_time_is_it[2] = 12; // HEURE
}
else if (the_hours > 1 && the_hours < 12) {
what_time_is_it[2] = 13; // HEURES
}
int m = sizeof(words[0]) / sizeof(words[0][0]);
int n = sizeof(what_time_is_it) / sizeof(what_time_is_it[0]);
for(int j = 0; j < n; j++) {
for(int i = 0; i < m; i++) {
// strip.setPixelColor(words[what_time_is_it[j]][i], color_white);
boolean newState = digitalRead(colors_switch);
if((newState == LOW) && (oldState == HIGH)) {
delay(20);
newState = digitalRead(colors_switch);
if(newState == LOW) { // Yes, still low
if(++mode > 8) mode = 0; // Advance to next mode, wrap around after #8
switch(mode) { // Start the new animation...
case 0:
colorWipe(strip.Color( 127, 127, 127), 20); // Blanc
break;
case 1:
colorWipe(strip.Color(255, 0, 0), 20); // Rouge
break;
case 2:
colorWipe(strip.Color( 0, 255, 0), 20); // Vert
break;
case 3:
colorWipe(strip.Color( 0, 0, 255), 20); // Bleu
break;
case 4:
colorWipe(strip.Color(127, 127, 127), 20); // Blanc
break;
case 5:
colorWipe(strip.Color(255, 0, 255), 20); // Violet
break;
case 6:
colorWipe(strip.Color( 255, 255, 0), 20); // Vert clair
break;
case 7:
colorWipe(strip.Color( 0, 255, 255), 20); // Blanc
break;
case 8:
colorWipe(strip.Color( 255, 127, 255), 20); // Blanc
break;
}
}
}
}
void colorWipe(uint32_t color, int wait) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
} |
Partager