I am a beginner is all this sort of stuff but I know there has to be a quicker way to do this.
I am trying to make a clock using a RTC and a ledstrip and it is taking forever to write the code.
the code is still unfinished as I still need to do the rest of the minutes
#include <FastLED.h>
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
#define NUM_LEDS 28
#define LED_PIN 3
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(20);
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop() {
// put your main code here, to run repeatedly:
DateTime now = RTC.now();
int uur = now.hour();
int minuten = now.minute();
if(uur == 0){
leds[0] = CRGB::Red;
leds[1] = CRGB::Red;
leds[2] = CRGB::Red;
leds[3] = CRGB::Red;
leds[4] = CRGB::Red;
leds[5] = CRGB::Red;
}
if(uur == 1){
leds[1] = CRGB::Red;
leds[2] = CRGB::Red;
}
if(uur == 2){
leds[0] = CRGB::Red;
leds[1] = CRGB::Red;
leds[3] = CRGB::Red;
leds[4] = CRGB::Red;
leds[6] = CRGB::Red;
}
if(uur == 3){
leds[0] = CRGB::Red;
leds[1] = CRGB::Red;
leds[2] = CRGB::Red;
leds[3] = CRGB::Red;
leds[6] = CRGB::Red;
}
if (uur == 4){
leds[1] = CRGB::Red;
leds[2] = CRGB::Red;
leds[5] = CRGB::Red;
leds[6] = CRGB::Red;
}
if (uur == 5){
leds[0] = CRGB::Red;
leds[2] = CRGB::Red;
leds[3] = CRGB::Red;
leds[5] = CRGB::Red;
leds[6] = CRGB::Red;
}
if (uur == 6){
leds[0] = CRGB::Red;
leds[2] = CRGB::Red;
leds[3] = CRGB::Red;
leds[4] = CRGB::Red;
leds[5] = CRGB::Red;
leds[6] = CRGB::Red;
}
if (uur == 7){
leds[0] = CRGB::Red;
leds[1] = CRGB::Red;
leds[2] = CRGB::Red;
}
if (uur = 8){
leds[7] = CRGB::Red;
leds[8] = CRGB::Red;
leds[9] = CRGB::Red;
leds[10] = CRGB::Red;
leds[11] = CRGB::Red;
leds[12] = CRGB::Red;
leds[13] = CRGB::Red;
}
if (uur == 9){
leds[0] = CRGB::Red;
leds[1] = CRGB::Red;
leds[2] = CRGB::Red;
leds[3] = CRGB::Red;
leds[5] = CRGB::Red;
leds[6] = CRGB::Red;
}
if (uur == 10){
leds[1] = CRGB::Red;
leds[2] = CRGB::Red;
leds[7] = CRGB::Red;
leds[8] = CRGB::Red;
leds[9] = CRGB::Red;
leds[10] = CRGB::Red;
leds[11] = CRGB::Red;
leds[12] = CRGB::Red;
}
if (uur == 11){
leds[1] = CRGB::Red;
leds[2] = CRGB::Red;
leds[8] = CRGB::Red;
leds[9] = CRGB::Red;
}
if (uur == 12){
leds[1] = CRGB::Red;
leds[2] = CRGB::Red;
leds[7] = CRGB::Red;
leds[8] = CRGB::Red;
leds[10] = CRGB::Red;
leds[11] = CRGB::Red;
leds[13] = CRGB::Red;
}
if (minuten == 1){
leds[22] = CRGB::Red;
leds[23] = CRGB::Red;
}
if (minuten == 2){
leds[21] = CRGB::Red;
leds[22] = CRGB::Red;
leds[24] = CRGB::Red;
leds[25] = CRGB::Red;
leds[27] = CRGB::Red;
}
if (minuten == 3){
leds[21] = CRGB::Red;
leds[22] = CRGB::Red;
leds[23] = CRGB::Red;
leds[24] = CRGB::Red;
leds[27] = CRGB::Red;
}
if (minuten == 4){
leds[22] = CRGB::Red;
leds[23] = CRGB::Red;
leds[26] = CRGB::Red;
leds[27] = CRGB::Red;
}
if (minuten == 5){
}
FastLED.show();
//uur -> seg 1 en 2
// uur = 0 =>led à tem6 en 7 tem 12
// uur = 01 =>
//minuten -> seg 3 en 4
Serial.print(' ');
Serial.print(uur);
Serial.print(':');
Serial.print(minuten);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
}