// Include the required Wire library for I2C
#include
#include
#define numpixels 1
#define pixelpower 11
#define pixelpin 12
Adafruit_NeoPixel pixel(numpixels, pixelpin, NEO_GRB + NEO_KHZ800);
int LED = 13;
int x = 0;
void setup() {
// Define the LED pin as Output
pinMode (LED, OUTPUT);
Serial.begin();
pixel.begin();
pinMode(pixelpower, OUTPUT);
digitalWrite(pixelpower, HIGH);
// Start the I2C Bus as Slave on address 9
Wire.begin(9);
// Attach a function to trigger when something is received.
Wire.onReceive(receiveEvent);
}
void receiveEvent(int bytes) {
x = Wire.read(); // read one character from the I2C
Serial.println(x);
}
void loop() {
if (x == 0)
{
pixel.setPixelColor(0, pixel.Color(255, 0, 0));
pixel.show();
delay(200);
}
if (x == 1)
{
pixel.setPixelColor(0, pixel.Color(0, 255, 0));
pixel.show();
delay(200);
}
if (x == 2)
{
pixel.setPixelColor(0, pixel.Color(0, 0, 255));
pixel.show();
delay(200);
}
if (x == 3)
{
pixel.setPixelColor(0, pixel.Color(255, 255, 0));
pixel.show();
delay(200);
}
if (x == 4)
{
pixel.setPixelColor(0, pixel.Color(0, 255, 255));
pixel.show();
delay(200);
}
if (x == 5)
{
pixel.setPixelColor(0, pixel.Color(255, 0, 255));
pixel.show();
delay(200);
}
else
{
pixel.setPixelColor(0, pixel.Color(255, 255, 255));
pixel.show();
delay(200);
}
Serial.println(x);
}