// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// Released under the GPLv3 license to match the rest of the
// Adafruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#define FRECUENCY_7HZ 143 // Milliseconds
#define FRECUENCY_12HZ 83
#define FRECUENCY_18HZ 56
#define FRECUENCY_30HZ 33
// Which pin on the ESP is connected to the potentiometer?
#define POTENTIOMETER_INPUT 26
// Which pin on the ESP is connected to the botton?
#define BOTTON 4
// Which pin on the ESP is connected to the NeoPixels?
#define LED_PIN 15
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 16
Adafruit_NeoPixel pixels(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
int sequencing = 0;
int adcValue = 0;
int brightness = 0;
unsigned int aux_time = 0;
bool turn = true;
void setup() {
pixels.begin(); // INITIALIZE NeoPixel strip object
pinMode(BOTTON, INPUT_PULLUP);
//Serial.begin(115200);
}
void loop() {
adcValue = analogRead(POTENTIOMETER_INPUT);
brightness = map(adcValue, 0, 4095, 0, 255);
if(digitalRead(BOTTON) == LOW){
delay(100); //Time to debounce
if(digitalRead(BOTTON) == HIGH){
sequencing++;
}else if(millis() >= (3000UL + aux_time)){
colorWipe(pixels.Color(0, 0, 0), brightness);
if(turn){
turn = false;
aux_time = millis();
}else if(!turn){
turn = true;
aux_time = millis();
}
}
}else{
aux_time = millis();
}
if(turn){
switch(sequencing){
case 0:
colorWipe(pixels.Color(0, 0, 255), brightness);
delay(FRECUENCY_7HZ);
colorWipe(pixels.Color(255, 0, 0), brightness);
delay(FRECUENCY_7HZ);
//Serial.println("7Hz");
break;
case 1:
colorWipe(pixels.Color(0, 0, 255), brightness);
delay(FRECUENCY_12HZ);
colorWipe(pixels.Color(255, 0, 0), brightness);
delay(FRECUENCY_12HZ);
//Serial.println("12Hz");
break;
case 2:
colorWipe(pixels.Color(0, 0, 255), brightness);
delay(FRECUENCY_18HZ);
colorWipe(pixels.Color(255, 0, 0), brightness);
delay(FRECUENCY_18HZ);
//Serial.println("18Hz");
break;
case 3:
colorWipe(pixels.Color(0, 0, 255), brightness);
delay(FRECUENCY_30HZ);
colorWipe(pixels.Color(255, 0, 0), brightness);
delay(FRECUENCY_30HZ);
//Serial.println("30Hz");
break;
default:
sequencing = 0;
break;
}
}
}
void colorWipe(uint32_t color, int brightness_p) {
pixels.clear();
for(int i=0; i<pixels.numPixels(); i++) { // For each pixel in strip...
pixels.setPixelColor(i, color); // Set pixel's color (in RAM)
pixels.show(); // Update strip to match
}
pixels.setBrightness(brightness_p);
}