Advertisement
ErnestoGrimes

Arduino Clock

May 20th, 2018
1,460
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Use if you want to force the software SPI subsystem to be used for some reason (generally, you don't)
  2. // #define FASTLED_FORCE_SOFTWARE_SPI
  3. // Use if you want to force non-accelerated pin access (hint: you really don't, it breaks lots of things)
  4. // #define FASTLED_FORCE_SOFTWARE_SPI
  5. // #define FASTLED_FORCE_SOFTWARE_PINS
  6. #include <FastLED.h>
  7.  
  8. // How many leds are in the strip?
  9. #define NUM_LEDS 12
  10.  
  11. // Data pin that led data will be written out over
  12. #define DATA_PIN 3
  13.  
  14. // Clock pin only needed for SPI based chipsets when not using hardware SPI
  15. //#define CLOCK_PIN 8
  16.  
  17.  
  18. CRGB leds[NUM_LEDS];
  19.  
  20. int buttoncount=0;
  21. int seconds=0;
  22. int secondsColor=95;
  23. int minutes=01;
  24. int minutesColor=0;
  25. int hours=12 ;
  26. int hoursColor=160;
  27.  
  28. long previousMillis;
  29.  
  30.  
  31. void setup() {
  32.     // sanity check delay - allows reprogramming if accidently blowing power w/leds
  33.     delay(1000);
  34.  
  35.       // Uncomment one of the following lines for your leds arrangement.
  36.       // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
  37.       // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
  38.       // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
  39.       ///FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
  40.       //FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
  41.       FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
  42.       // FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  43.       // FastLED.addLeds<APA104, DATA_PIN>(leds, NUM_LEDS);
  44.       // FastLED.addLeds<WS2811_400, DATA_PIN, RGB>(leds, NUM_LEDS);
  45.       // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
  46.       // FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
  47.       // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
  48.       // FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
  49.  
  50.       // FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
  51.       // FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
  52.       // FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
  53.       // FastLED.addLeds<P9813, RGB>(leds, NUM_LEDS);
  54.       // FastLED.addLeds<APA102, RGB>(leds, NUM_LEDS);
  55.       // FastLED.addLeds<DOTSTAR, RGB>(leds, NUM_LEDS);
  56.      
  57.       // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  58.       // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  59.       // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  60.       // FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  61.       // FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  62.       // FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  63.  
  64.       FastLED.setBrightness(5);
  65.       pinMode(7, INPUT);
  66.       Serial.begin(19200);
  67.  
  68.       leds[0].setHSV(150,255,255);
  69.       FastLED.show();
  70.       delay(2000);
  71.       FastLED.clear();
  72.  
  73. }
  74.  
  75. void loop() {
  76.   incrementTime();    
  77.   showSeconds(seconds);
  78.   showMinutes(minutes);
  79.   showHours(hours);
  80.   //printTime();
  81.   tick(1000);
  82.  
  83.   FastLED.show();
  84. //  delay(1000);
  85.  
  86.   FastLED.clear();
  87.  
  88. }
  89.  
  90. void showSeconds(int a){            // map secounds to led
  91.   int b = map(a,1,60,0,NUM_LEDS-1);
  92.   leds[b].setHSV(secondsColor,255,255);
  93. //  Serial.print(a);
  94. //  Serial.print(" ");
  95. //  Serial.println(b);
  96. }
  97.  
  98. void showMinutes(int a){            //map minutes to led
  99.   int b = map(a,1,60,0,NUM_LEDS-1);
  100.   leds[b].setHSV(minutesColor,255,255);
  101. //  Serial.print(a);
  102. //  Serial.print(" ");
  103. //  Serial.println(b);
  104. }
  105.  
  106. void showHours(int a){              //map hours to led
  107.   if (NUM_LEDS > 12) {
  108.     a = map(a,0,23,0,NUM_LEDS-1);
  109.     leds[a].setHSV(hoursColor,255,255);
  110.   }
  111.   else
  112.   {
  113.   a = a%12;
  114.   leds[a].setHSV(hoursColor,255,255);
  115. }
  116. }
  117.  
  118. void incrementTime(){               //roll seconds > minutes > hours
  119.   //seconds++;
  120.   if (seconds > 60){
  121.     seconds = 1;
  122.     minutes++;
  123.   }
  124.     if (minutes > 60){
  125.     minutes = 1;
  126.     hours++;
  127.   }
  128.     if (hours > 23){
  129.     hours = 0;
  130.   }
  131. }
  132.  
  133. void printTime(){                   //print current time to serial
  134.   Serial.print(hours);
  135.   Serial.print(":");
  136.   Serial.print(minutes);
  137.   Serial.print(":");
  138.   Serial.println(seconds);
  139. }
  140.  
  141. void tick(int a){                        // increment secounds based on input millis
  142.     if ( millis() - previousMillis >= a) {
  143.     seconds++;
  144.     previousMillis = millis();
  145.     //Serial.println(previousMillis);
  146.   }
  147. }
Advertisement
RAW Paste Data Copied
Advertisement