Étape 2: Le code!!
#include
#ifdef __AVR__ #include #endif
#define PIN 6
Bande de Adafruit_NeoPixel = Adafruit_NeoPixel (29, 6, NEO_GRB + NEO_KHZ800) ;
void setup() {/ / This is pour bijou 5V 16MHz, vous pouvez supprimer ces trois lignes si vous n’utilisez pas un bibelot #if défini (__AVR_ATtiny85__) si (F_CPU == 16000000) clock_prescale_set(clock_div_1) ; #endif / / fin de bijou spécial code strip.setBrightness(50) ;
Strip.Begin() ; Strip.Show() ; Initialiser tous les pixels sur "arrêt"}
void loop() {/ / quelques procédures d’exemple montrant comment afficher les pixels : colorWipe (bande. Color(255, 0, 0), 50) ; ColorWipe rouge (bande. Color(0, 255, 0), 50) ; ColorWipe vert (bande. Color(0, 0, 255), 50) ; Bleu
Envoyer une poursuite de pixel de théâtre en... theaterChase (bande. Color(127, 127, 127), 50) ; TheaterChase blanc (bande. Color(127, 0, 0), 50) ; TheaterChase rouge (bande. Color(0, 0, 127), 50) ; TheaterChase bleu (bande. Color(128,0,128), 50) ; Purple
Rainbow(20) ; rainbowCycle(20) ; theaterChaseRainbow(40) ; }
Remplir les points un après l’autre avec une colorWipe Sub de couleur (uint32_t c, uint8_t attente) {pour (uint16_t j’ai = 0; i
Sub arc-en-ciel (attente uint8_t) {uint16_t i, j ;
pour (j = 0; j < 256; j ++) {pour (i = 0; i
void rainbowCycle (attente uint8_t) {uint16_t i, j ;
pour (j = 0; j < 256 * 5; j ++) {/ / 5 cycles de toutes les couleurs sur la roue pour (i = 0; j’ai < strip.numPixels(); i ++) {strip.setPixelColor (i, roue (((i * 256/strip.numPixels()) + j) & 255));} strip.show() ; delay(wait);}}
void theaterChase (uint32_t c, uint8_t attente) {pour (int j = 0; j < 10; j ++) {//do 10 cycles de chasse pour (q int = 0; q < 3; q ++) {pour (uint16_t j’ai = 0; j’ai < strip.numPixels(); i = i + 3) {strip.setPixelColor (i + q, c); //turn chaque pixel troisième sur} strip.show() ;
Delay(Wait) ;
pour (uint16_t j’ai = 0; i < strip.numPixels(); i = i + 3) {strip.setPixelColor (i + q, 0); //turn chaque pixel troisième arrêt}}}}
Style théâtre rampant s’allume avec arc-en-ciel effet Sub theaterChaseRainbow (uint8_t attente) {pour (int j = 0; j < 256; j ++) {/ / cycle tous les 256 couleurs dans la roue de (q int = 0; q < 3; q ++) {pour (uint16_t j’ai = 0; j’ai < strip.numPixels(); i = i + 3) {strip.setPixelColor (i + q, roue ((i + j) % 255)); //turn chaque pixel troisième sur} strip.show() ;
Delay(Wait) ;
pour (uint16_t j’ai = 0; i < strip.numPixels(); i = i + 3) {strip.setPixelColor (i + q, 0); //turn chaque pixel troisième arrêt}}}}
Roue d’uint32_t (WheelPos octets) {WheelPos = 255 - WheelPos ; if(WheelPos < 85) {bande de retour. Couleur (255 - WheelPos * 3, 0, WheelPos * 3) ; } if(WheelPos < 170) {WheelPos-= 85 ; bande de retour. Couleur (0, WheelPos * 3, 255 - WheelPos * 3) ; } WheelPos-= 170 ; retourner la bande. Couleur (WheelPos * 3, 255 - WheelPos * 3, 0) ; }