Greetings to all forensics. I need some help, please.
I got an Arduino code, made for a clock, using an LED strip and ESP8266 and, with a lot of effort, I adapted it to two LED strips; Hours + Minutes/Seconds. It is working correctly and was made to light up an LED for the Hours, an LED for the Minutes and an LED for the Seconds, but I would like it to light up 3 LEDs for the Hours (it is lighting up 1 LED).
I have tried a few ways but, due to my lack of knowledge in codes, I am not able to do it. I assume that the change has to do with the lines below...
void drawHands() {
clearHands();
// draw the LEDs for the hours, using the color red
pixels.setPixelColor(hour_hand, pixels.Color(255, 0, 0));
Code:
#include <NtpClientLib.h> // Biblioteca NtpClientLib by German Martin v3.0.2-beta
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager WiFi Configuration Magic
#include <Adafruit_NeoPixel.h> // Biblioteca Adafruit_NeoPixel v1.0.5
#define NUMPIXELS 60 // número de LEDs NeoPixel
#define LED_PIN 14 // pino 14 (D5) no ESP8266 (GPIO2/pino 3 no ESP-01)
#define LED_PIN2 12 // pino 12 (D6) no ESP8266 (GPIO3/pino 7 no ESP-01)
#define mirror_hands false // No caso do anel NeoPixel estar conectado no sentido anti-horário.
byte hour_hand, minute_hand, second_hand, previous_second;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(60, 14, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2 = Adafruit_NeoPixel(60, 12, NEO_GRB + NEO_KHZ800);
// limpe todos os leds para desligar
void clearHands() {
for (byte i = 0; i <= NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
pixels2.setPixelColor(i, pixels.Color(0, 0, 0));
}
}
void drawHands() {
clearHands();
// draw the LEDs for the hours, using the color red
pixels.setPixelColor(hour_hand, pixels.Color(255, 0, 0));
// desenha os LEDs dos minutos, usando a cor verde
pixels2.setPixelColor(minute_hand, pixels.Color(0, 128, 0));
// desenha os LEDs dos segundos, usando a cor azul intenso
pixels2.setPixelColor(second_hand, pixels.Color(0, 0, 255));
// mostra todos os LEDs - aqueles que definimos com uma cor que serão visíveis.
pixels.show();
pixels2.show();
// apenas uma string de depuração, pode ser removida
// Serial.printf("hour:%d (%d), minute:%d second:%d (%d) \n",hour(),hour_hand,minute_hand,true_second,second_hand);
}
void setup() {
Serial.begin(115200);
WiFiManager wifiManager; // assistente de configuração de WiFi
wifiManager.autoConnect("NeoPixel_Clock", "secret"); // configuração do ponto de acesso, defina seu próprio segredo.
Serial.println("WiFi Client connected!)");
NTP.begin("br.pool.ntp.org", -4, true); // obter tempo do pool de servidores NTP.
NTP.setInterval(63);
pixels.begin();
pixels2.begin();
pixels.setBrightness(254);
}
void loop() {
byte hour_offset;
minute_hand = minute();
if (minute_hand >= 10) {
hour_offset = (minute_hand / 10) - 1;
} else
{
hour_offset = 0;
}
if (hour() >= 12) {
hour_hand = ((hour() - 12) * 5) + hour_offset;
}
else {
hour_hand = (hour() * 5) + hour_offset;
}
if (mirror_hands) {
hour_hand = 60 - hour_hand;
minute_hand = 60 - minute_hand;
second_hand = (60 - second());
if (second_hand == 60) {
second_hand = 0;
}
if (minute_hand == 60) {
minute_hand = 0;
}
if (hour_hand == 60) {
hour_hand = 0;
}
} else {
second_hand = second();
}
if (second_hand != previous_second) {
previous_second = second_hand;
drawHands();
}
}