Code: Select all
#include <Adafruit_NeoPixel.h>
#define PIN 6 // input pin Neopixel is attached to
#define NUMPIXELS 4 // number of neopixels in strip
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
const int button = 9;
int buttonState = 0;
int relay = 12;
void setup()
{
pinMode(relay, OUTPUT);
pinMode(button, INPUT);
delay(500);
pixels.begin(); // Initialize the NeoPixel library.
pixels.show();
}
void loop()
{
buttonState = digitalRead(button);
delay(500);
if(buttonState == HIGH)
{
digitalWrite (relay, HIGH); // turn on relay
delay(100);
uint32_t red = pixels.Color(255, 0, 0, 0);
pixels.fill(red, 0, 4);
pixels.show();
delay(500);
digitalWrite (relay, LOW); // turn off relay
delay(100);
}
}