Hello to all Arduino Forensics. I need some help, please.
I have an Arduino code for a LED strip clock, which is working correctly, but here's the problem: the wiring for the original circuit is coming from the top of the clock and I would like it to come from the bottom (foot) of the clock. So, is there any function in the code to reverse this wiring, so that I don't have to change the hardware? I would appreciate any help.
#include <ESP8266WiFi.h>
#include <Adafruit_NeoPixel.h>
#include "TimeClient.h"
#define PIN D5 // r400 --> DIN led
#define LEDNUM 60
#define BRIGHTNESS 40
int Q = (LEDNUM / 12);
int zero = 0;
int five = Q;
int ten = Q * 2;
int fifteen = Q * 3;
int twenty = Q * 4;
int twentyfive = Q * 5;
int therty = Q * 6;
int thertyfive = Q * 7;
int fourty = Q * 8;
int fourtyfive = Q * 9;
int fifty = Q * 10;
int fiftyfive = Q * 11;
long lastUpdate = millis();
long lastSecond = millis();
String hours, minutes, seconds;
int currentSecond, currentMinute, currentHour;
char ssid[] = "ssid"; // your network SSID (name)
char pass[] = "password"; // your network password
const float UTC_OFFSET = 7; // Brasil = -3
TimeClient timeClient(UTC_OFFSET);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN);
void setup() {
Serial.begin(115200);
strip.begin();
strip.setBrightness(BRIGHTNESS);
strip.show();
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
rainbowCycle(5);
rainbowCycle2(5);
}
timeClient.updateTime();
updateTime() ;
lastUpdate = millis();
lastSecond = millis();
meteorRain(0, 0, 255, 10, 64, false, 15);
}
void loop() {
if ((millis() - lastUpdate) > 1800000) updateTime();
if ((millis() - lastSecond) > 1000) {
strip.setPixelColor(currentSecond - 1 , 0, 0, 0);
strip.setPixelColor(currentSecond, 0, 0, 0);
strip.setPixelColor(currentMinute, 0, 0, 0);
strip.setPixelColor(currentHour * 5 - 1, 0, 0, 0);
strip.setPixelColor(currentHour * 5, 0, 0, 0);
strip.setPixelColor(currentHour * 5 + 1, 0, 0, 0);
strip.show();
lastSecond = millis();
currentSecond++;
if (currentSecond > 59) {
currentSecond = 0;
currentMinute++;
if (currentMinute > 59) {
currentMinute = 0;
currentHour++;
if (currentHour > 12) currentHour = 1;
}
}
String currentTime = String(currentHour) + ':' + String(currentMinute) + ':' + String(currentSecond);
Serial.println(currentTime);
//if (currentMinute == 0 && currentSecond == 0) { //meteor rain every hour
//if (currentMinute == 0 && currentMinute == 30 && currentSecond == 0) { //meteor rain every half hour
if ((currentMinute == 0 || currentMinute == 5 || currentMinute == 10 || currentMinute == 15 || currentMinute == 20 || currentMinute == 25 || currentMinute == 30 || currentMinute == 35 || currentMinute == 40 || currentMinute == 45 || currentMinute == 50 || currentMinute == 55) && (currentSecond == 0) ) { //meteor rain every five minute
meteorRain(0, 0, 255, 10, 64, false, 15);
currentSecond++;
} else {
strip.setPixelColor(zero, 125, 125, 125);
strip.setPixelColor(five, 10, 10, 10);
strip.setPixelColor(ten, 10, 10, 10);
strip.setPixelColor(fifteen, 125, 125, 125);
strip.setPixelColor(twenty, 10, 10, 10);
strip.setPixelColor(twentyfive, 10, 10, 10);
strip.setPixelColor(therty, 125, 125, 125);
strip.setPixelColor(thertyfive, 10, 10, 10);
strip.setPixelColor(fourty, 10, 10, 10);
strip.setPixelColor(fourtyfive, 125, 125, 125);
strip.setPixelColor(fifty, 10, 10, 10);
strip.setPixelColor(fiftyfive, 10, 10, 10);
if (currentHour == 12) {
strip.setPixelColor(59, 255, 0, 0);
strip.setPixelColor(0, 255, 0, 0);
strip.setPixelColor(1, 255, 0, 0);
} else {
strip.setPixelColor(currentHour * 5 - 1, 255, 0, 0);
strip.setPixelColor(currentHour * 5, 255, 0, 0);
strip.setPixelColor(currentHour * 5 + 1, 255, 0, 0);
}
strip.setPixelColor(currentMinute, 0, 255, 0);
strip.setPixelColor(currentSecond, 0, 0, 255);
strip.setPixelColor(currentSecond - 1 , 0, 0, 255);
strip.show();
}
}
}
void updateTime() {
hours = timeClient.getHours();
minutes = timeClient.getMinutes();
seconds = timeClient.getSeconds();
currentHour = hours.toInt();
if (currentHour > 12) currentHour = currentHour - 12;
currentMinute = minutes.toInt();
currentSecond = seconds.toInt();
lastUpdate = millis();
}
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256; j++) { // 5 cycles of all colors on wheel
for (i = 0; i < 60; i++) {
strip.setPixelColor(i, Wheel(((i * 256 / 60) + j) & 255));
}
strip.show();
delay(wait);
}
}
void rainbowCycle2(uint8_t wait) {
uint16_t i, j;
for (j = 256; j > 0; j--) { // 5 cycles of all colors on wheel
for (i = 0; i < 60; i++) {
strip.setPixelColor(i, Wheel(((i * 256 / 60) + j) & 255));
}
strip.show();
delay(wait);
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
setAll(0, 0, 0);
for (int i = 60; i > LEDNUM - LEDNUM; i--) {
for (int j = 0; j < LEDNUM; j++) {
if ( (!meteorRandomDecay) || (random(10) > 5) ) {
fadeToBlack(j, meteorTrailDecay );
}
}
for (int j = 0; j < meteorSize; j++) {
if ( ( i - j < LEDNUM) && (i - j >= 0) ) {
setPixel(i - j, red, green, blue);
}
}
strip.show();
delay(SpeedDelay);
}
for (int i = 0; i < LEDNUM + LEDNUM; i++) {
for (int j = 0; j < LEDNUM; j++) {
if ( (!meteorRandomDecay) || (random(10) > 5) ) {
fadeToBlack(j, meteorTrailDecay );
}
}
for (int j = 0; j < meteorSize; j++) {
if ( ( i - j < LEDNUM) && (i - j >= 0) ) {
setPixel(i - j, red, green, blue);
}
}
strip.show();
delay(SpeedDelay);
}
}
void fadeToBlack(int ledNo, byte fadeValue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
uint32_t oldColor;
uint8_t r, g, b;
int value;
oldColor = strip.getPixelColor(ledNo);
r = (oldColor & 0x00ff0000UL) >> 16;
g = (oldColor & 0x0000ff00UL) >> 8;
b = (oldColor & 0x000000ffUL);
r = (r <= 10) ? 0 : (int) r - (r * fadeValue / 256);
g = (g <= 10) ? 0 : (int) g - (g * fadeValue / 256);
b = (b <= 10) ? 0 : (int) b - (b * fadeValue / 256);
strip.setPixelColor(ledNo, r, g, b);
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[ledNo].fadeToBlackBy( fadeValue );
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
void setAll(byte red, byte green, byte blue) {
for (int i = 0; i < LEDNUM; i++ ) {
setPixel(i, red, green, blue);
}
strip.show();
}



