Hello Im creating a project that would control an LED strip through the serial but I am currently having issues and I am lost at this point. The code is verified but when I run it and type a color in the serial it doesn't change. Any help would be appreciated. Code is Below
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define N_LEDS 30
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
Serial.begin(9600);
}
void loop() {
Serial.read();
int incomingByte;
if(Serial.available() > 0) {
incomingByte = Serial.read();
Serial.print(" I received:");
Serial.println(incomingByte);
if(incomingByte=="red"){
colorWipe(strip.Color(255, 0, 0), 50);}
if(incomingByte=="blue"){
colorWipe(strip.Color(0, 0, 255), 50);}
if(incomingByte=="green"){
colorWipe(strip.Color(0, 255, 0), 50);}
}
if(incomingByte=="red"){
colorWipe(strip.Color(255, 0, 0), 50);}
if(incomingByte=="blue"){
colorWipe(strip.Color(0, 0, 255), 50);}
if(incomingByte=="green"){
colorWipe(strip.Color(0, 255, 0), 50);}
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
serial_led_code.ino (975 Bytes)