Search code examples
arduinoled

Arduino code to make an led strip of 3 blink


I have an arduino board with an led strip with 3 led plugged into pin 1. a picture of the wiring is below. this is the code I used to attempt to lightup the led, with no luck:

#include <Adafruit_NeoPixel.h>
#define PIN 1

Adafruit_NeoPixel strip = Adafruit_NeoPixel(3, PIN, NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show();//Initialize all pixels to 'off'

  strip.setbrightness(50);
  forcint i=0; i<3;i++)

  strip.setPixelColor(0,255,255,255);
  strip.show();
}

void loop() {
  for (int i=255;i>=0;i--){
  lightColor(i,0,0);
  delay(10);
  i=i+2
  }
}

enter image description here

any help will be aprecited, this is my first time using arduino


Solution

  • #include <Adafruit_NeoPixel.h>
    #define PIN 13
    
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(3, PIN, NEO_KHZ800);
    
    void setup() {
      strip.begin();
      strip.show();//Initialize all pixels to 'off'
    
      strip.setbrightness(50);
    
      strip.setPixelColor(0,255,255,255);
      strip.show();
    }
    
    void loop() {
      for (int i=255;i>=0;i--){
          lightColor(i,0,0);
          delay(10);
      }
      delay(500);
    }
    

    With this code, LED will decrease RED channel until 0, wait 0'5 seconds and repeat. I change your setup function by deleting a malformed for loop. And in loop() I added a delay and removed i=i+2 bacause I didn't understand its function. And finally, you must use another pin because PIN 1 is for serial use.