I am trying to make a simple clock made from LED strips. I have hardly any experience with coding but have looked at a lot of examples online for LED clocks. This clock does not need to be very accurate meaning it does not need to have an RTC connected to it. This project is for a high school marching band prop and they want 6 of these clocks on the field during their show. Each clock will run at different speeds meaning there could be more or less than 60 seconds between minute changes. Some clocks will run fast and some will run slow. The clocks will only have hours and minutes. I'll eventually want to have all 6 clocks run off of a single arduino if possible but we can tackle that at some other time. Right now I just want to prototype a single LED strip clock using 5V WS2812b LEDs and get the code working.
To start this project I made this clock Prototype Clock to use as the prototype . I did not need the Bluetooth, RTC, or temp/humidity sensor. I just used the arduino and leds. I wired up the LEDs and dots just like his project. His code was to hard for me to decouple so I had to research another way. I ran into this guys clock and tried using his code Clock and Code. I am having a hard time getting his code to work. Maybe I should start from scratch but I'm not really sharp enough to know where to start.
24 17 8 1 <----- Arduino connects to LED 1.
29 25 22 18 15 13 9 6 2 LED connections follow in numerical order
30 23 14 7
28 26 21 19 16 12 10 5 3
27 20 11 4
Hour Hour dots minute minute
This is the code I started with:
#include <FastLED.h>
#define NUM_LEDS 28
#define DATA_PIN 6
CRGB leds[NUM_LEDS];
int currentTimeHours = 16;
int currentTimeMinutes = 17 ;
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]= CRGB::Green;
}
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},{2,3},{1,2,4,5,7},{1,2,7,3,4},{2,3,6,7},{1,3,4,6,7},{1,3,4,5,6,7},{1,2,3},{1,2,3,4,5,6,7},{1,2,3,4,6,7}};
void setup() {
FastLED.addLeds<WS2812, DATA_PIN>(leds, NUM_LEDS); }
void loop(){
//int minutes = millis() / 60000 ; // get number of minutes since the arduino is turned on
int minutes = millis() / 1000 ; // 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();
}
I can get the minutes to work but the dots are messing me up since they are in the middle of the array. I don't know how to code around the dots. If there is an easier way to code this whole clock please help me out. I was just trying to use something that was already out there that was similar to what I need the LED clock to do. Thanks in advance!