Ok im sorry for my original attempt at this because i posted the wrong sketch to begin with which kind of shot me in the foot from the start. what i am trying to do is to upgrade a TRON legacy deluxe disc to add the ability to change colours by pushing a second button and leaving the existing button to transition through the ignition, blade spin and extinguish animations. my "perfect" scenario is that it will change colour without interrupting the blade spin/theater chase animation, but i am fine with it turning all the LED in the neopixel strip off before resuming the theater chase in the new color. the code i am using for the blade ring is:
#include <Adafruit_DotStar.h> //Comment out if using NeoPixels
// This is a demonstration on how to use an input device to trigger changes on your neo pixels.
// You should wire a momentary push button to connect from ground to a digital IO pin. When you
// press the button it will change to a new pixel animation. Note that you need to press the
// button once to start the first animation!
//#include <Adafruit_NeoPixel.h> //commnt out if using DotStar
#ifdef __AVR__
#include <avr/power.h>
#endif
#define BUTTON_PIN 5 // Digital IO pin connected to the button. This will be
// driven with a pull-up resistor so the switch should
// pull the pin to ground momentarily. On a high -> low
// transition the button press logic will execute.
#define PIXEL_PIN 0 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 60
#define NUMPIXELS 60
// set both of the above to the number of pixels in your strip
// Parameter 1 = number of pixels in strip, neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
//Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
// Here's how to control the LEDs from any two pins:
#define DATAPIN 4
#define CLOCKPIN 3
Adafruit_DotStar strip = Adafruit_DotStar(
NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);
bool oldState = HIGH;
int showType = 0;
void setup() {
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
int mode = 0; // Start in the "Off" mode
void loop() {
// check for a button press
if (digitalRead(5) == LOW) // button pressed
{
mode++; // advance to the next mode
if (mode == 3)
{
mode = 0; // go back to Off
}
}
}
switch (mode) // execute code for one of the 3 modes:
{
{
case 0: colorWipe(strip.Color(0, 0, 0), 10);
break; // mode == OFF
// add code for the "Off" mode here
break;
}
{
case 1: colorWipe(strip.Color(0, 0, 255), 5);
// add code for the "Ignition" mode here
break;
}
{
case 2: theaterChase(0xff, 0, 0, 50); // mode == Spinning
// add code for the "Spinning" mode here
break;
}
}
}
// 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);
}
void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
for (int q = 0; q < 3; q++) {
for (int i = 0; i < NUM_LEDS; i = i + 3) {
setPixel(i + q, red, green, blue); //turn every third pixel on
}
showStrip();
delay(SpeedDelay);
for (int i = 0; i < NUM_LEDS; i = i + 3) {
setPixel(i + q, 0, 0, 0); //turn every third pixel off
}
iam using a seconf pro trinket for the "C" ring and i have the proper sketch for that because all i need is a set of color wipe cases and i have that sketch working fine and can merely wire the color select switch into the second board and be ready to go. i have put together at least the start of a new sketch that looks like i have at least gotten to the point of it has both tactile switches in and ready to go, but i really dont know what the next step is. i have no real code experience and up to this point i have been able to identify existing code that i need for my projects and copy and paste it where it needs to go. any help i can get on how o write the code i need is greatly appreciated, but this is the new sketch i am building for the blade ring:
//#include <Adafruit_DotStar.h> //Comment out if using NeoPixels
#include <Adafruit_NeoPixel.h> //commnt out if using DotStar
#ifdef __AVR__
#include <avr/power.h>
#endif
//This sketch is to let the TRON legacy disc cycle through a selection of colours each time the colour select button is pressed
//while simultaneously allowing it to cycle through the "ignition" "blade spin" and "extinguish" animations
//when the mode select button is pressed
#define PIXEL_PIN 0 // Digital IO pin connected to the NeoPixels.
int head = 0, tail = -10; // Index of first 'on' and 'off' pixels
uint32_t color = 0xFF0000; // 'On' color (starts red)
//this sets he number of pixels in the strip
#define PIXEL_COUNT 45
#define NUMPIXELS 45
//chooses which strip is being used, comment out the one you are not using
//Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG)Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
pinMode(7, INPUT_PULLUP); // Set pin 7 to be in input mode
pinMode(8, INPUT_PULLUP); // Set pin 8 to be in input mode
strip.begin();
strip.show(); // Initialize all pixels to 'off'
startAnimation(); //we use () because we are not passing any parameters
}
int mode = 0; // Start in the "Off" mode
void loop() {
// put your main code here, to run repeatedly:
}
void startAnimation() {
for (int x = 0; x < NUMPIXELS * 3; x++) {
strip.setPixelColor(head, color); // 'On' pixel at head
strip.setPixelColor(tail, 0); // 'Off' pixel at tail
strip.show(); // Refresh strip
delay(20); // Pause 20 milliseconds (~50 FPS)
if (++head >= NUMPIXELS) { // Increment head index. Off end of strip?
head = 0; // Yes, reset head index to start
if ((color >>= 8) == 0) // Next color (R->G->B) ... past blue now?
color = 0xFF0000; // Yes, reset to red
}
if (++tail >= NUMPIXELS) tail = 0; // Increment, reset tail index
}
}