Advertisement
Guest User

Arduino Clock | online marty

a guest
May 15th, 2020
1,664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.13 KB | None | 0 0
  1. // by online marty https://youtu.be/sF5Yk7fkcbA
  2.  
  3. #include <FastLED.h>
  4. #define NUM_LEDS 28
  5. #define DATA_PIN 6
  6.  
  7. CRGB leds[NUM_LEDS];
  8.  
  9. int currentTimeHours = 16;
  10. int currentTimeMinutes = 20 ;
  11.  
  12. int MaxBrightness = 255;
  13. int red = MaxBrightness; // keep this like this, for changing colors
  14. int green = 0;
  15. int blue = 0;
  16.  
  17. int dif =  0;
  18. int difco = 0;
  19.  
  20.  boolean if_in_array(int array[], int element);
  21.  boolean if_in_array(int array[], int element) {
  22.  for (int i = 0; i < 7; i++) {
  23.       if (array[i] == element) {
  24.           return true;
  25.       }
  26.     }
  27.   return false;
  28.  }
  29.  
  30. int turnon(int t[7], int digit){       //turn on leds that are required for that digit and turn other leds off
  31.   for (int i = 1; i < 8; i ++){
  32.       if (if_in_array(t,i)){
  33.        
  34.         leds[i-1 + digit*7].setRGB( red, green, blue);
  35.         }
  36.       else {
  37.         leds[i-1+ digit*7] = CRGB::Black;
  38.         }
  39.     }
  40.   }
  41. //  array with the saved led positions for each digit from 0 to 9
  42. 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}};
  43.  
  44. void setup() {
  45.   FastLED.addLeds<WS2811, DATA_PIN>(leds, NUM_LEDS); }
  46.  
  47. void loop(){  
  48.   dif ++;             //this part is used for changing colors of the leds
  49.   if (dif > MaxBrightness ){
  50.       dif = 0;
  51.       difco ++;
  52.       if (difco > 3){
  53.         difco = 0;
  54.         }
  55.     }
  56.     if (difco == 0){
  57.       red = MaxBrightness - dif;
  58.       green = dif;}
  59.     if (difco == 1){
  60.       green = MaxBrightness - dif;
  61.       blue = dif;}
  62.     if (difco == 2){
  63.       blue = MaxBrightness -dif;
  64.       red = dif;}
  65.  
  66.  int minutes = millis() / 60000 ; // get number of minutes since the arduino is turned on
  67.  minutes = minutes + currentTimeHours*60 + currentTimeMinutes; // this is used to set the current time
  68.  int hours = minutes/60;
  69.  minutes = minutes - hours*60;
  70.  hours = hours - (hours / 24)*24;
  71.  
  72.  turnon(ref[minutes-(minutes/10)*10],0);
  73.  turnon(ref[minutes/10],1);
  74.  turnon(ref[hours-(hours/10)*10],2);
  75.  turnon(ref[hours/10],3);
  76.  FastLED.show();
  77.  delay(1000); // change this, to control the speed of the changing colors
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement