Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Use if you want to force the software SPI subsystem to be used for some reason (generally, you don't)
- // #define FASTLED_FORCE_SOFTWARE_SPI
- // Use if you want to force non-accelerated pin access (hint: you really don't, it breaks lots of things)
- // #define FASTLED_FORCE_SOFTWARE_SPI
- // #define FASTLED_FORCE_SOFTWARE_PINS
- #include <FastLED.h>
- // How many leds are in the strip?
- #define NUM_LEDS 12
- // Data pin that led data will be written out over
- #define DATA_PIN 3
- // Clock pin only needed for SPI based chipsets when not using hardware SPI
- //#define CLOCK_PIN 8
- CRGB leds[NUM_LEDS];
- int buttoncount=0;
- int seconds=0;
- int secondsColor=95;
- int minutes=01;
- int minutesColor=0;
- int hours=12 ;
- int hoursColor=160;
- long previousMillis;
- void setup() {
- // sanity check delay - allows reprogramming if accidently blowing power w/leds
- delay(1000);
- // Uncomment one of the following lines for your leds arrangement.
- // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
- ///FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
- //FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
- FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- // FastLED.addLeds<APA104, DATA_PIN>(leds, NUM_LEDS);
- // FastLED.addLeds<WS2811_400, DATA_PIN, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<P9813, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<APA102, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<DOTSTAR, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
- // FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
- FastLED.setBrightness(5);
- pinMode(7, INPUT);
- Serial.begin(19200);
- leds[0].setHSV(150,255,255);
- FastLED.show();
- delay(2000);
- FastLED.clear();
- }
- void loop() {
- incrementTime();
- showSeconds(seconds);
- showMinutes(minutes);
- showHours(hours);
- //printTime();
- tick(1000);
- FastLED.show();
- // delay(1000);
- FastLED.clear();
- }
- void showSeconds(int a){ // map secounds to led
- int b = map(a,1,60,0,NUM_LEDS-1);
- leds[b].setHSV(secondsColor,255,255);
- // Serial.print(a);
- // Serial.print(" ");
- // Serial.println(b);
- }
- void showMinutes(int a){ //map minutes to led
- int b = map(a,1,60,0,NUM_LEDS-1);
- leds[b].setHSV(minutesColor,255,255);
- // Serial.print(a);
- // Serial.print(" ");
- // Serial.println(b);
- }
- void showHours(int a){ //map hours to led
- if (NUM_LEDS > 12) {
- a = map(a,0,23,0,NUM_LEDS-1);
- leds[a].setHSV(hoursColor,255,255);
- }
- else
- {
- a = a%12;
- leds[a].setHSV(hoursColor,255,255);
- }
- }
- void incrementTime(){ //roll seconds > minutes > hours
- //seconds++;
- if (seconds > 60){
- seconds = 1;
- minutes++;
- }
- if (minutes > 60){
- minutes = 1;
- hours++;
- }
- if (hours > 23){
- hours = 0;
- }
- }
- void printTime(){ //print current time to serial
- Serial.print(hours);
- Serial.print(":");
- Serial.print(minutes);
- Serial.print(":");
- Serial.println(seconds);
- }
- void tick(int a){ // increment secounds based on input millis
- if ( millis() - previousMillis >= a) {
- seconds++;
- previousMillis = millis();
- //Serial.println(previousMillis);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement