I am attempting to fade between colors, but for the purpose of the project, I need to fade in and out from colors that could be colors other than black or white. The idea is to make a function to simultaneously fade out the previous location (it may need to be a variety of colors), while fading in the previous color from the color that was previously in that square.
To clarify, the actual project is a clock. I am attempting to get the second value to fade in and out as it moves around the clock. So as it passes the hour marks or minute marks or hour markers it will have to fade in and out of different colors.
My code so far:
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 RTC;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, 11, NEO_GRB + NEO_KHZ800);
DateTime past = 0;
void setup ()
{
strip.begin();
strip.show();
Serial.begin(57600);
Wire.begin();
RTC.begin();
RTC.adjust(DateTime(__DATE__,__TIME__));
if (!RTC.isrunning())
{
Serial.println("RTC is NOT running!");
}
}
void loop()
{
DateTime present = RTC.now();
if (present.hour() != past.hour() || present.minute() != past.minute() || present.second() != past.second())
{
int hourPos = (present.hour()%12-1)*5+4;
if (hourPos == -1)
hourPos = 59;
int minutePos = present.minute()-1;
if (minutePos == -1)
minutePos = 59;
int secondPos = present.second()-1;
if (secondPos == -1)
secondPos = 59;
timeUpdate(hourPos,minutePos,secondPos);
past=present;
strip.show();
}
}
//void fade (int pos)
//{
// for(int i=0;i<256;i++)
// {
// strip.setPixelColor(pos, strip.getRed(pos-1)+i
// strip.setPixelColor(pos-1, strip.getRed(pos-1)-i,strip.getGreen(pos-1) i,strip.getGreen(pos-1)-i);
// strip.show();
// }
//}
void timeUpdate(int hourPos,int minutePos,int secondPos)
{
for (int i=0;i<strip.numPixels();i++)
strip.setPixelColor(i,0,0,0);
for (int i=4; i<strip.numPixels();i=i+5)
strip.setPixelColor(i,255,255,255);
strip.setPixelColor(hourPos,0,255,0);
strip.setPixelColor(minutePos, 0,0,255);
strip.setPixelColor(secondPos, 255,0,0);
//fade(secondPos);
}
A quick note, I have modified the Neopixel library to return the individual R, G and B values for an individual pixel. The current code has it so the clock doesn't fade when it changes.
Aucun commentaire:
Enregistrer un commentaire