Skip to content

Instantly share code, notes, and snippets.

@futureshocked
Last active January 16, 2017 20:01
Show Gist options
  • Save futureshocked/04843dae638cb91d3b11a1d01c447ac3 to your computer and use it in GitHub Desktop.
Save futureshocked/04843dae638cb91d3b11a1d01c447ac3 to your computer and use it in GitHub Desktop.
// In this file I want to show how to create an array of a struct for the Arduino.
// I create a struct that contains ints for RGB color components.
// Then, I create an array of this struct, and use it to display a color
// show on an Adafruit 40 RGB LED shield array.
// Check out my Arduino blog at txplore.com, and my video courses at txplore.tv!
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(40, PIN, NEO_GRB + NEO_KHZ800);
struct ledRGBComponents {
int red;
int green;
int blue;
};
ledRGBComponents ledRGBSequence[] = {
{255,0,0},
{0,255,0},
{0,0,255},
{127,127,127},
{100,50,150},
{50,150,250}
};
int counter;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Some example procedures showing how to display to the pixels:
for (counter = 0; counter < sizeof(ledRGBSequence) - 1; counter++){
colorWipe(strip.Color(ledRGBSequence[counter].red, ledRGBSequence[counter].green, ledRGBSequence[counter].blue), 50);
}
}
// Fill the dots one after the other with a color
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment