#include <Adafruit_NeoPixel.h>
#define PIN 13 // Pin connected to NeoPixel data input
#define NUMPIXELS 1 // Number of NeoPixels
#define SWITCH_PIN 12 // Pin connected to the switch
#define POT_PIN A5 // Pin connected to the potentiometer
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin();
pixels.clear(); // Turn off NeoPixel initially
pixels.show(); // Display the initial state
pinMode(SWITCH_PIN, INPUT_PULLUP); // Set the switch pin as input with internal pull-up resistor
}
void loop() {
// Read the state of the switch
int switchState = digitalRead(SWITCH_PIN);
if (switchState == LOW) { // If the switch is pressed
// Read the potentiometer value
int potValue = analogRead(POT_PIN);
// Map the potentiometer value (0-1023) to NeoPixel color range (0-255)
int hue = map(potValue, 0, 9, 0, 255);
// Set NeoPixel color
pixels.setPixelColor(0, pixels.ColorHSV(hue, 255, 255)); // Set color based on potentiometer value
pixels.show(); // Display the color
} else {
pixels.clear(); // Turn off NeoPixel when the switch is not pressed
pixels.show(); // Display the off state
}
}