Lampor och en City-scape målning (8 / 9 steg)
Steg 8: Kod för Neopixels och lysdioder
Neopixel kod
#include
#define stift 1
Adafruit_NeoPixel strip = Adafruit_NeoPixel (7, PIN, NEO_GRB + NEO_KHZ800).
void setup() {
Strip.BEGIN();
Strip.show();
}
void loop() {
colorWipe (remsa. Color(255,255,0), 50); Gul
colorWipe (remsa. Color(255, 0, 0), 50); Röd
colorWipe (remsa. Color(255,165,0), 50); Orange
colorWipe (remsa. Color(0, 0, 255), 50); Blå
colorWipe (remsa. Color(255,255,255), 50); Vit
}
void colorWipe (uint32_t c, uint8_t vänta) {
för (uint16_t jag = 0; jag
strip.setPixelColor (i, c);
Strip.show();
Delay(Wait);
}
}
LEDDE kodning
int OrangeOne = 9;
int OrangeTwo = A2;
int OrangeThree = A5;
int YellowOne = 6;
int YellowTwo = A3;
int RedOne = 5;
int RedTwo = 11;
int WhiteOne = 10;
int WhiteTwo = A4;
int ledPins [] = {OrangeOne, OrangeTwo, OrangeThree, YellowOne, YellowTwo, WhiteOne, WhiteTwo, RedOne, RedTwo}; LED stift
int ledCnt = 9;
Ogiltiga inställningar () {
pinMode (RedOne, OUTPUT);
pinMode (RedTwo, OUTPUT);
pinMode (OrangeOne, OUTPUT);
pinMode (OrangeTwo, OUTPUT);
pinMode (OrangeThree, OUTPUT);
pinMode (YellowOne, OUTPUT);
pinMode (YellowTwo, OUTPUT);
pinMode (WhiteOne, OUTPUT);
pinMode (WhiteTwo, OUTPUT);
Serial.BEGIN(9600);
}
void loop() {
int rand1 = random(0,ledCnt);
int rand2 = random(0,ledCnt);
int rand3 = random(0,ledCnt);
digitalWrite(RedOne,LOW);
digitalWrite (RedTwo, låg);
digitalWrite (OrangeOne, låg);
digitalWrite (OrangeTwo, låg);
digitalWrite (OrangeThree, låg);
digitalWrite (YellowOne, låg);
digitalWrite (YellowTwo, låg);
digitalWrite (WhiteOne, låg);
digitalWrite (WhiteTwo, låg);
digitalWrite(ledPins[rand1],HIGH);
digitalWrite(ledPins[rand2],HIGH);
digitalWrite(ledPins[rand3],HIGH);
}