Sorry, I am using a gemma m0 with the neopixel strip attached to A0 and a button to trigger it attached to A2.
my code is mostly from the neopixel buttoncycler example from the library.
here is my full code:
#include <Adafruit_DotStar.h> // Dot Star Library to control local led
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define BUTTON_PIN A2 // Trigger
#define PIXEL_PIN A0 // Digital IO pin connected to the Pixels.
#define PIXEL_COUNT 42 // Number of Pixels
// Define colors
#define pink 255,80,80
#define blue 50,80,255
#define yellow 255,120,25
#define purple 120,50,255
#define green 50,255,70
#define orange 255,25,5
char chosenColor[6];
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800); //Pixel Strip
Adafruit_DotStar DotStar_strip(DOTSTAR_NUM, PIN_DOTSTAR_DATA, PIN_DOTSTAR_CLK, DOTSTAR_BRG);//Dot star (local LED)
boolean oldState = HIGH;
int mode = 0; // Currently-active animation mode, 0-9
int FadeTime = 5;
void setup() {
Serial.begin(9600);
Serial.println("Starting");
//(disable local LED)
delay (1000);
randomSeed(analogRead(0));
DotStar_strip.begin(); // Initialize pin for output
DotStar_strip.setBrightness(80);
DotStar_strip.show(); // Turn all LEDs off ASAP
//normal startup code
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin(); // Initialize NeoPixel strip object (REQUIRED)
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
boolean newState = digitalRead(BUTTON_PIN); // Get current button state.
if((newState == LOW) && (oldState == HIGH)) { // Check if state changed from high to low (button press).
delay(5); // Short delay to debounce button.
newState = digitalRead(BUTTON_PIN); // Check if button is still low after debounce.
if(newState == LOW) {
randomColors();
}
}
// Set the last-read button state to the old state.
oldState = newState;
}
// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {
int IncrementPixels = PIXEL_COUNT /2;
for(int i=0; i<IncrementPixels; i++) { // For each pixel in strip... //strip.numPixels()
int j = map (i,0,PIXEL_COUNT,PIXEL_COUNT,0);
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.setPixelColor(j-1, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}
void randomColors(){
int IncrementPixels = PIXEL_COUNT /2;
for(int i=0; i<IncrementPixels; i++) {
int j = map (i,0,PIXEL_COUNT,PIXEL_COUNT,0);
colorPicker();
strip.setPixelColor(i, chosenColor);
colorPicker();
strip.setPixelColor(j-1, chosenColor);
strip.show(); // Update strip to match
delay(FadeTime);
}
colorWipe(strip.Color( 0, 0, 0), FadeTime);
}
void colorPicker(){
int Choice=random(0,5);
Serial.print("Choice ");
Serial.print(Choice);
switch(Choice) {
case 0:
chosenColor = pink;
break;
case 1:
chosenColor = blue;
break;
case 2:
chosenColor = yellow;
break;
case 3:
chosenColor = purple;
break;
case 4:
chosenColor = green;
break;
case 5:
chosenColor = orange;
break;
}
Serial.print("chosenColor ");
Serial.println(chosenColor);
}
thanks for trying to help, I appreciate it.
The colorwipe line is because it's supposed to flash the colors than black out after.