#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 48
#define BRIGHTNESS 255
#define NUMCOLORS 7
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
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);
}
int delayval = 100;
int delayval1 = 500;
int delayval2 = 5000;
int pollutionValues[NUMPIXELS];
int thresholdValues[NUMCOLORS] = {0, 21, 43, 61, 81, 100};
int redColors[NUMCOLORS] = {0, 0, 0, 255, 255, 255};
int greenColors[NUMCOLORS] = {0, 255, 255, 255, 53, 0};
int blueColors[NUMCOLORS] = {0, 255, 0, 0, 0, 0};
void setup() {
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
strip.begin();
strip.show();
}
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*1; j++) {
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
void loop() {
for (int i=0; i<NUMPIXELS; i++) {
pollutionValues[i] = 2 * i;
}
for (int i=0; i<NUMPIXELS; i++) {
for (int j=0; j<NUMCOLORS; j++) {
if (pollutionValues[i] < thresholdValues[j]) {
pixels.setPixelColor(i, pixels.Color(redColors[j],greenColors[j],blueColors[j]));
pixels.show();
delay(delayval);
break;
}
}
}
rainbowCycle(6);
for (int i=0; i<NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(80,80,80));
}
pixels.show();
delay(delayval1);
int pollutionValuesBis[NUMPIXELS] = {43, 52, 91, 45, 36, 93, 62, 28, 26, 59, 21, 47, 28, 57, 33, 25, 36, 18, 30, 34, 27, 29, 41, 19, 29, 25, 25, 18, 30, 38, 44, 61, 37, 44, 45, 39, 34, 41, 40, 56, 42, 36, 35, 54, 81, 56, 38, 66};
for (int i=0; i<NUMPIXELS; i++) {
pollutionValues[i] = pollutionValuesBis[i];
}
for (int i=0; i<28; i++) {
for (int j=0; j<NUMCOLORS; j++) {
if (pollutionValues[i] < thresholdValues[j]) {
pixels.setPixelColor(i, pixels.Color(redColors[j],greenColors[j],blueColors[j]));
pixels.show();
delay(delayval);
break;
}
}
}
for (int i=28; i<29; i++) {
for (int j=0; j<NUMCOLORS; j++) {
if (pollutionValues[i] < thresholdValues[j]) {
pixels.setPixelColor(i, pixels.Color(redColors[j],greenColors[j],blueColors[j]));
pixels.show();
delay(delayval);
break;
}
}
}
for (int i=29; i<NUMPIXELS; i++) {
for (int j=0; j<NUMCOLORS; j++) {
if (pollutionValues[i] < thresholdValues[j]) {
pixels.setPixelColor(i, pixels.Color(redColors[j]/50,greenColors[j]/50,blueColors[j]/50));
pixels.show();
delay(delayval);
break;
}
}
}
int var = 0;
while(var < 15){
for (int i=28; i<29; i++) {
for (int j=0; j<NUMCOLORS; j++) {
if (pollutionValues[i] < thresholdValues[j]) {
pixels.setPixelColor(i, pixels.Color(redColors[j],greenColors[j],blueColors[j]));
pixels.show();
delay(delayval1);
pixels.setPixelColor(i, pixels.Color(0,0,0));
pixels.show();
delay(delayval1);
break;
}
}
}
var++;
}
for (int i=0; i<NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0,0,0));
}
pixels.show();
delay(delayval);
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.