initialcommit, linearclock with smallstrip
This commit is contained in:
53
linearclock/linearclock.ino
Normal file
53
linearclock/linearclock.ino
Normal file
@@ -0,0 +1,53 @@
|
||||
//code for a line clock
|
||||
|
||||
#include <FastLED.h>
|
||||
|
||||
#define NUM_LEDS 12
|
||||
#define DATA_PIN 4 // Change this to match your LED strip's data pin
|
||||
#define BRIGHTNESS 60
|
||||
|
||||
CRGB leds[NUM_LEDS];
|
||||
uint8_t pos = 0;
|
||||
bool toggle = false;
|
||||
int hour=17;
|
||||
int minute=54;
|
||||
int second=0;
|
||||
void setup() {
|
||||
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
|
||||
FastLED.setBrightness(BRIGHTNESS);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
uint8_t ledRed = (hour * NUM_LEDS) / 24;
|
||||
leds[ledRed] = CRGB::Red;
|
||||
|
||||
uint8_t ledBlue =(minute * NUM_LEDS) / 60;
|
||||
leds[ledBlue] = CRGB::Blue;
|
||||
|
||||
uint8_t ledGreen =(second * NUM_LEDS) / 60;
|
||||
leds[ledGreen] = CRGB::Green;
|
||||
|
||||
FastLED.show();
|
||||
|
||||
//compute next time
|
||||
second++;
|
||||
if( second == 60 ) {
|
||||
second=0;
|
||||
minute++;
|
||||
}
|
||||
if( minute ==60 ) {
|
||||
minute=0;
|
||||
hour = (hour++ ) % 24;
|
||||
}
|
||||
|
||||
// clear this led for the next time around the loop
|
||||
leds[ledRed] = CRGB::Black;
|
||||
leds[ledBlue] = CRGB::Black;
|
||||
leds[ledGreen] = CRGB::Black;
|
||||
delay(1000);
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user