用Tinkercad学arduino之 霓虹灯条

#include <Adafruit_NeoPixel.h>

#define PIN 2     // input pin Neopixel is attached to

#define NUMPIXELS      12 // number of neopixels in strip

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 100; // timing delay in milliseconds

int redColor = 0;
int greenColor = 0;
int blueColor = 0;

void setup() {
  // Initialize the NeoPixel library.
  pixels.begin();
}

void loop() {
  setColor();

  for (int i=0; i < NUMPIXELS; i++) {
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(redColor, greenColor, blueColor));

    // This sends the updated pixel color to the hardware.
    pixels.show();

    // Delay for a period of time (in milliseconds).
    delay(delayval);
  }
}

// setColor()
// picks random values to set for RGB
void setColor(){
  redColor = random(0, 255);
  greenColor = random(0,255);
  blueColor = random(0, 255);
}

 

相关文章:

  • 2021-07-10
  • 2021-12-09
  • 2021-04-06
  • 2021-12-04
  • 2021-07-17
  • 2021-11-11
  • 2021-09-08
  • 2022-12-23
猜你喜欢
  • 2021-07-08
  • 2021-10-05
  • 2021-08-23
  • 2021-09-29
  • 2021-10-02
  • 2021-11-28
  • 2021-04-26
相关资源
相似解决方案