/**********************************************
This Arduino code snippet uses the Adafruit NeoPixel library to control
three separate NeoPixel LED strips, each with 16 LEDs. Here's a summary of what the code does:
1. It includes the necessary library `#include <Adafruit_NeoPixel.h>`.
2. Defines constants for the number of pixels (`NUM_PIXELS`) and
the pin numbers for each NeoPixel strip (`PIXEL_PIN_A1`, `PIXEL_PIN_A2`, `PIXEL_PIN_A3`).
3. Initializes three instances of the Adafruit NeoPixel library
for the three LED strips: `pixels_A1`, `pixels_A2`, and `pixels_A3`.
4. In the `setup` function, it initializes each of the NeoPixel
strips using the `begin` method.
5. The `loop` function performs the following steps repeatedly:
- Reads analog values from three different analog pins:
`A1`, `A2`, and `A3`.
- Defines colors (`color_A1`, `color_A2`, and `color_A3`)
for the NeoPixel strips.
- Maps the analog values to LED indices (`led_index_A1`, `led_index_A2`,
and `led_index_A3`) to determine which LEDs should be lit based on the input voltage.
- Sets the color of LEDs at the mapped indices for each NeoPixel strip and turns off the rest of the LEDs.
- Shows the updated LED colors on each NeoPixel strip using the `show` method.
In summary, this code reads analog input values from
three different pins, maps these values to LED indices on three
NeoPixel LED strips, and lights up specific LEDs in each strip based on the input voltage. This allows you to create a dynamic lighting effect on three separate NeoPixel strips based on
analog sensor inputs.
by arvind patil 8/10/23
**********************************************************/
include <Adafruit_NeoPixel.h>
#define NUM_PIXELS 16
#define PIXEL_PIN_A1 5
#define PIXEL_PIN_A2 6
#define PIXEL_PIN_A3 7
Adafruit_NeoPixel pixels_A1(NUM_PIXELS, PIXEL_PIN_A1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels_A2(NUM_PIXELS, PIXEL_PIN_A2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels_A3(NUM_PIXELS, PIXEL_PIN_A3, NEO_GRB + NEO_KHZ800);
void setup() {
pixels_A1.begin();
pixels_A2.begin();
pixels_A3.begin();
}
void loop() {
int analog_val_A1 = analogRead(A1);
int analog_val_A2 = analogRead(A2);
int analog_val_A3 = analogRead(A3);
// Define a cor dos LEDs da faixa Neopixel
uint32_t color_A1 = pixels_A1.Color(255, 0, 0);
uint32_t color_A2 = pixels_A2.Color(0, 255, 0);
uint32_t color_A3 = pixels_A3.Color(0, 0, 255);
// Mapeia a posição do LED aceso na faixa Neopixel com base na tensão de entrada na porta analógica correspondente
int led_index_A1 = map(analog_val_A1, 0, 1023, 0, NUM_PIXELS - 1);
int led_index_A2 = map(analog_val_A2, 0, 1023, 0, NUM_PIXELS - 1);
int led_index_A3 = map(analog_val_A3, 0, 1023, 0, NUM_PIXELS - 1);
// Liga ou desliga os LEDs da faixa Neopixel com base na posição mapeada
for (int i = 0; i < NUM_PIXELS; i++) {
if (i == led_index_A1) {
pixels_A1.setPixelColor(i, color_A1);
} else {
pixels_A1.setPixelColor(i, 0);
}
if (i == led_index_A2) {
pixels_A2.setPixelColor(i, color_A2);
} else {
pixels_A2.setPixelColor(i, 0);
}
if (i == led_index_A3) {
pixels_A3.setPixelColor(i, color_A3);
} else {
pixels_A3.setPixelColor(i, 0);
}
}
pixels_A1.show();
pixels_A2.show();
pixels_A3.show();
}