Web Sacosta
Estroboscópico con potenciómetro
Cambio de frecuencia on/off por potenciómetro
//modificado a partir de https://elearn.ellak.gr/mod/book/view.php?id=4561&chapterid=2409
#include <Adafruit_NeoPixel.h>
#define PIN 2
#define NUM_LEDS 8
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
int sensorValue = 0;
int outputValue = 0;
int frecuencia=0;
void setup() {
pinMode(A0, INPUT);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
sensorValue = analogRead(A0);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 100,1023 );
// change the analog out value:
int frecuencia = int(outputValue);
// Strobe és un array de 6 términos,
//los tres primeros són los valores RGB para fijar el color
//el cuarto és el número de veces que se enciende y apaga la tira
// número de on/off seguidos en una serie(StrobeCount)
//el quinto fija el delay entre encender y apagar
//tiempo entre on/off(FlashDelay)
//el sexto fija el delay una vez acabada la serie de on/off antes de empezar una nueva serie
//tiempo entre serie y serie (EndPause)
Strobe(255, 0, 0, 10, frecuencia, 1000);
}
void Strobe(int red, int green, int blue, int StrobeCount, int FlashDelay, int EndPause){
for(int j = 0; j < StrobeCount; j++) {
setAll(red,green,blue);
strip.show();
delay(FlashDelay);
setAll(0,0,0);
strip.show();
delay(FlashDelay);
}
delay(EndPause);
}
void setPixel(int Pixel, int red, int green, int blue) {
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
}
void setAll(int red, int green, int blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
}
Obra publicada con Licencia Creative Commons Reconocimiento Compartir igual 4.0