hi, im trying to add a colour cycle to my tron legacy disc. i have the animation cycle working so it does a proper ignition, blade spin and extinguish animation but i want to add the ability to change colour on the fly so i can change colour while the blade spin is going on but also make the "C" ring change colour to match. i know how to add in a second button, and im pretty sure i can write the colour cycle in as a mode change, but how do i get the animation cycle to read the colour selection and display accordingly. the code is for the blade ring, the "C" ring uses a separate board and only a colour wipe animation so it will be easy for me to modify the code for it once i have learned how to modify this.
{deleted code because i posted the wrong sketch to begin with the proper sketch is listed in post number 12}
" if ((color >>= 8) == 0) " Cool!
how do i do this? i can deal with having to extinguish thew blade for colour changes but the fact is i even got into arduino so i can learn how to code but i havent been able to find any examples of aything close to what imn trying to do so i dont even know where to start trying
Hi,
Welcome to the forum.
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Thanks.. Tom... 
ok let me se if i have this right
#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 45
#define NUMPIXELS 45
// 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);
int head = 0, tail = -10; // Index of first 'on' and 'off' pixels
uint32_t color = 0xFF0000; // 'On' color (starts red)
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'
startAnimation(); //we use () because we are not passing any parameters
}
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 == 5)
{
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(255, 0, 0), 1); // color order is GRB // mode == Ignition
// add code for the "Ignition" mode here
break;
case 2:
colorWipe(strip.Color(0, 255, 0), 15); // color order is GRB
// add code for the "Spinning" mode here
break;
case 3:
colorWipe(strip.Color(0, 0, 255), 1); // color order is GRB // mode == Ignition
// add code for the "Ignition" mode here
break;
case 4:
colorWipe(strip.Color(255, 255, 255), 1); // color order is GRB // mode == Ignition
// add code for the "Ignition" 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);
}
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
for (int q = 0; q < 3; q++) {
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, 0); //turn every third pixel off
}
}
}
}
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
}
}
i was actually trying out how to post my code to make sure i had it right. so far all ive been able to get is the few things that i actually understand about how to write code. i can read code well enough to be able to get at least the general idea of what its supposed to be doing but im a long way off from being able to write it yet. so far this is what i have written
//#include <Adafruit_DotStar.h> //Comment out if using NeoPixels
#include <Adafruit_NeoPixel.h> //commnt out if using DotStar
//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
//this sets he number of pixels in the strip
#define PIXEL_COUNT 45
#define NUMPIXELS 45
#define BUTTON1
void setup() {
// put your setup code here, to run once:
}
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
}
}
the animation code at the end is what makes it do a "boot up" animation of sending a pulse of red, green and blue along the strip so i can see that its on and do a quick visual inspection to make sure all the pixels work, and its kind of impressive when i show off the disc. i still have to add the second button into the code. this is for the blade ring, the "C" ring strip will only have colour change because it will stay lit as a solid unit the whole time and i know i can do a colour cycle as a case step like i did with the baton i built since im using a second pro trinket for that and just need to wire the colour change button to the second board and use the baton sketch that just has colour wipe in each "case" with a different colour value for each colour step
ok i THINK i have the first issue figured out. i found a dimmer sketch that actually clearly demonstrates how to clearly state there are two physical buttons
int brightness = 100;
void setup() {
pinMode(13,OUTPUT); // Set pin 13 to be in output mode
pinMode(7,INPUT_PULLUP); // Set pin 7 to be in input mode
pinMode(8,INPUT_PULLUP); // Set pin 8 to be in input mode
}
void loop() {
if(digitalRead(7) == LOW) brightness--; // If button on pin 7 is pressed, reduce brightness
if(brightness < 0) brightness = 0; // Don't let brightness drop below zero
if(digitalRead(8) == LOW) brightness++; // If button on pin 8 is pressed, increase brightness
if(brightness > 255) brightness = 255; // Don't let brightness get above 255
analogWrite(13, brightness); // Set pin 13 to the new brightness level
delay(10); // Wait a short time, just to slow things down a little
}
now what i need to do, to at least have SOMETHING figured out is how to code it to do what im actually wanting. my issue is that i dont know HOW to code and so far i have been able to find at least something that does what im looking for that i can easily modify, this is the first time ive ever had to actually coder from scratch.
i guess what i need to figure out is how to make it do this
void setup() {
pinMode(13,OUTPUT); // Set pin 13 to be in output mode
pinMode(7,INPUT_PULLUP); // Set pin 7 to be in input mode
pinMode(8,INPUT_PULLUP); // Set pin 8 to be in input mode
}
void loop() {
if(digitalRead(7) == LOW) next colour; // If button on pin 7 is pressed, go to next colour in the cycle
if(colour < the last colour in the cycle list) colour = back to the first colour; // continue cycling colours
if(digitalRead(8) == LOW) animation++; // If button on pin 8 is pressed, begin next animation
if(animation > last animation in cycle) animation = first animation; // cycle through the animations
after that i can figure out how to make each animation look for the colour currently active in the cycle instead of having to enter the values. i dont care if the leds turn off and then turn on again in the new colour or if they just switch colours while the animation is running without interrupting the animation
ok so far ive managed to cludge THIS together and it passes the verify check
//#include <Adafruit_DotStar.h> //Comment out if using NeoPixels
#include <Adafruit_NeoPixel.h> //commnt out if using DotStar
//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() {
// put your setup code here, to run once:
pinMode(13, OUTPUT); // Set pin 13 to be in output mode
pinMode(7, INPUT_PULLUP); // Set pin 7 to be in input mode
pinMode(8, INPUT_PULLUP); // Set pin 8 to be in input 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
}
}
ok, after some back and forth looking at my previous disc code, i have found a few things which i can see are important even if i have no clue what they are doing and so far ive been able to get THIS going and it passes verification so i think im on the right track so far
//#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
}
}
oh crap, i realized that i had posted the code from my baton rather than from my disc THIS is the code for the disc and what im basically wanting the blade to do
#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
}
admins, please delete this thread, i realize i kind of screwd myself by posting the wrong sketch in the beginning and will be starting a new topic so i can try to more effectively convey the info and what im trying to do.