Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // by online marty https://youtu.be/sF5Yk7fkcbA
- #include <FastLED.h>
- #define NUM_LEDS 28
- #define DATA_PIN 6
- CRGB leds[NUM_LEDS];
- int currentTimeHours = 16;
- int currentTimeMinutes = 20 ;
- int MaxBrightness = 255;
- int red = MaxBrightness; // keep this like this, for changing colors
- int green = 0;
- int blue = 0;
- int dif = 0;
- int difco = 0;
- boolean if_in_array(int array[], int element);
- boolean if_in_array(int array[], int element) {
- for (int i = 0; i < 7; i++) {
- if (array[i] == element) {
- return true;
- }
- }
- return false;
- }
- int turnon(int t[7], int digit){ //turn on leds that are required for that digit and turn other leds off
- for (int i = 1; i < 8; i ++){
- if (if_in_array(t,i)){
- leds[i-1 + digit*7].setRGB( red, green, blue);
- }
- else {
- leds[i-1+ digit*7] = CRGB::Black;
- }
- }
- }
- // array with the saved led positions for each digit from 0 to 9
- int ref[10][7] = {{1,2,3,4,5,6},{1,6},{5,6,7,3,2},{5,6,7,1,2},{4,6,7,1},{5,4,7,1,2},{5,4,7,1,2,3},{5,6,1},{1,2,3,4,5,6,7},{1,2,4,5,6,7}};
- void setup() {
- FastLED.addLeds<WS2811, DATA_PIN>(leds, NUM_LEDS); }
- void loop(){
- dif ++; //this part is used for changing colors of the leds
- if (dif > MaxBrightness ){
- dif = 0;
- difco ++;
- if (difco > 3){
- difco = 0;
- }
- }
- if (difco == 0){
- red = MaxBrightness - dif;
- green = dif;}
- if (difco == 1){
- green = MaxBrightness - dif;
- blue = dif;}
- if (difco == 2){
- blue = MaxBrightness -dif;
- red = dif;}
- int minutes = millis() / 60000 ; // get number of minutes since the arduino is turned on
- minutes = minutes + currentTimeHours*60 + currentTimeMinutes; // this is used to set the current time
- int hours = minutes/60;
- minutes = minutes - hours*60;
- hours = hours - (hours / 24)*24;
- turnon(ref[minutes-(minutes/10)*10],0);
- turnon(ref[minutes/10],1);
- turnon(ref[hours-(hours/10)*10],2);
- turnon(ref[hours/10],3);
- FastLED.show();
- delay(1000); // change this, to control the speed of the changing colors
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement