0

Help with basic rainbow cycle
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Help with basic rainbow cycle

by jaxdesign on Sun Jul 16, 2017 5:18 pm

Hello! This is my third project, after creating a led coat and the florabrella. This time I'm making a simple hat similar to this one: https://learn.adafruit.com/guggenhat-bl ... at-display

However, my hat doesn't need to spell anything. I have one 4m / 30led strand wrapping around the hat. All I want to do is have the individual LEDs fade randomly in color and fade in and out in brightness from 0 to 200. There should be 120 leds total.

Unfortunately I'm really bad at the coding aspect of this project. I tried using snippets of code found on this tutorial, but I am getting errors when compiling.

https://learn.adafruit.com/multi-taskin ... ommon-bits

Here is my code, which I copied and pasted from the above tutorial, and I'm sure is incomplete. It won't compile, so I included the error message as well:

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>

// Pattern types supported:
enum  pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, SCANNER, FADE };
// Patern directions supported:
enum  direction { FORWARD, REVERSE };

// NeoPattern Class - derived from the Adafruit_NeoPixel class
class NeoPatterns : public Adafruit_NeoPixel
{
    public:

    // Member Variables: 
    pattern  ActivePattern;  // which pattern is running
    direction Direction;     // direction to run the pattern
   
    unsigned long Interval;   // milliseconds between updates
    unsigned long lastUpdate; // last update of position
   
    uint32_t Color1, Color2;  // What colors are in use
    uint16_t TotalSteps;  // total number of steps in the pattern
    uint16_t Index;  // current step within the pattern
   
    void (*OnComplete)();  // Callback on completion of pattern

   
    // Initialize for a RainbowCycle
    void RainbowCycle(uint8_t interval, direction dir = FORWARD)
    {
        ActivePattern = RAINBOW_CYCLE;
        Interval = interval;
        TotalSteps = 120;
        Index = 0;
        Direction = dir;
    }

    // Update the Rainbow Cycle Pattern
    void RainbowCycleUpdate()
    {
        for(int i=0; i< numPixels(); i++)
        {
            setPixelColor(i, Wheel(((i * 256 / numPixels()) + Index) & 255));
        }
        show();
        Increment();
    }
}



Error:

Code: Select all | TOGGLE FULL SIZE
Arduino: 1.8.0 (Mac OS X), Board: "Adafruit Flora"

hat:47: error: expected ';' after class definition
 }
 ^
/Users/jacksonwalker/Documents/Arduino/hat/hat.ino: In member function 'void NeoPatterns::RainbowCycleUpdate()':
hat:42: error: 'Wheel' was not declared in this scope
             setPixelColor(i, Wheel(((i * 256 / numPixels()) + Index) & 255));
                                                                           ^
hat:45: error: 'Increment' was not declared in this scope
         Increment();
                   ^
exit status 1
expected ';' after class definition

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


Thanks for the help, you guys are the best.

jaxdesign
 
Posts: 24
Joined: Tue Sep 20, 2016 10:29 pm

Re: Help with basic rainbow cycle

by kcl1s on Sun Jul 16, 2017 6:38 pm

You have several errors in that code. One of the big ones is it uses the 'wheel' function which you have not included.
Here is the rainbow cycle code from strandtest. It will give you a starting point.
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>

#define PIN 6
#define NUMPIXELS 120
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

  pixels.begin();
  pixels.show(); // Initialize all pixels to 'off'
}

void loop() {

  rainbowCycle(20);
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
    for (i = 0; i < pixels.numPixels(); i++) {
      pixels.setPixelColor(i, Wheel(((i * 256 / pixels.numPixels()) + j) & 255));
    }
    pixels.show();
    delay(wait);
  }
}


// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}


Keith

kcl1s
 
Posts: 222
Joined: Tue Aug 30, 2016 12:06 pm

Re: Help with basic rainbow cycle

by jaxdesign on Tue Jul 18, 2017 3:10 pm

Thank you so much!

jaxdesign
 
Posts: 24
Joined: Tue Sep 20, 2016 10:29 pm

Re: Help with basic rainbow cycle

by jaxdesign on Thu Jul 20, 2017 9:37 pm

Sorry to bother you again, would you mind looking at my code? I altered RainbowCycle to randomly have white lights appear. But there's an error I cant seem to figure out when I try to compile:

The error: https://www.screencast.com/t/UbIXlIeBO

Seems like wheel isnt defined on the line, but I see it below. I tried moving the rainbowcycle function below the wheel function, but that didn't work.

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>

#define PIN 6
#define NUMPIXELS 120
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

  pixels.begin();
  pixels.show(); // Initialize all pixels to 'off'
}

void loop() {

  rainbowCycle(20);
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;
  long randNumber;


  for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
    for (i = 0; i < pixels.numPixels(); i++) {
      // get a random number from 0 to 99
      randNumber = random(100);
      // pick how often you want random white pixels.  i picked 10, meaning pixels will be white approx 10% of the time.
      if(randNumber < 10){
        // set pixel color to pure white.  you might wanna lower these values if pure white is too intense.
        pixels.setPixelColor(i, pixels.Color(255,255,255));
      }else{
        // normal code to continue rendering the rainbow
  for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
    for (i = 0; i < pixels.numPixels(); i++) {
      pixels.setPixelColor(i, Wheel(((i * 256 / pixels.numPixels()) + j) & 255));
    }
    pixels.show();
    delay(wait);
  }
}


// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}



Thank you!
Last edited by jaxdesign on Sat Jul 22, 2017 6:11 pm, edited 1 time in total.

jaxdesign
 
Posts: 24
Joined: Tue Sep 20, 2016 10:29 pm

Re: Help with basic rainbow cycle

by kcl1s on Fri Jul 21, 2017 8:30 am

First please use the code button above the text editor to create code tags and place code between them. It makes reading the code so much easier.

OK your code was missing 3 closing curly brackets. Each open bracket '{' needs a corresponding close bracket '}'. If you click tools/Auto format it will indent your code and help you see where you need them.
Here is the fixed code it compiles but I did not test it.
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>

#define PIN 6
#define NUMPIXELS 120
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

  pixels.begin();
  pixels.show(); // Initialize all pixels to 'off'
}

void loop() {

  rainbowCycle(20);
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;
  long randNumber;


  for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
    for (i = 0; i < pixels.numPixels(); i++) {
      // get a random number from 0 to 99
      randNumber = random(100);
      // pick how often you want random white pixels. i picked 10, meaning pixels will be white approx 10% of the time.
      if (randNumber < 10) {
        // set pixel color to pure white. you might wanna lower these values if pure white is too intense.
        pixels.setPixelColor(i, pixels.Color(255, 255, 255));
      }
      else {
        // normal code to continue rendering the rainbow
        for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
          for (i = 0; i < pixels.numPixels(); i++) {
            pixels.setPixelColor(i, Wheel(((i * 256 / pixels.numPixels()) + j) & 255));
          }
          pixels.show();
          delay(wait);
        }
      }
    }     //3 missing brackets
  }
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}


Keith

kcl1s
 
Posts: 222
Joined: Tue Aug 30, 2016 12:06 pm

Re: Help with basic rainbow cycle

by jaxdesign on Fri Jul 21, 2017 9:02 pm

Keith, so sorry I forgot to put the code tag. I complied the code you posted above and it verifies. However when I try to upload to my Flora, I get this error:
avrdude: butterfly_recv(): programmer is not responding

Do you or anyone else know what would cause that? Thank you again,

jaxdesign
 
Posts: 24
Joined: Tue Sep 20, 2016 10:29 pm

Re: Help with basic rainbow cycle

by jaxdesign on Sat Jul 22, 2017 7:32 pm

Here's the errors I am getting, by the way:

Code was uploading without issue before, and I tried uploading the old code and the latest code (both found in this thread), but got the same error messages. I'm on a mac. The board is correctly set as the Adafruit Flora, the port is Bluetooth Incoming Port. When I try to obtain board info, it says "Native serial port, cant obtain info." Any ideas why it wont upload? Thanks kindly, and no hurry on this of course. You guys offer the best support here, I am truly thankful.

Code: Select all | TOGGLE FULL SIZE
Arduino: 1.8.0 (Mac OS X), Board: "Adafruit Flora"

Sketch uses 6968 bytes (24%) of program storage space. Maximum is 28672 bytes.
Global variables use 184 bytes of dynamic memory.

avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
Found programmer: Id = "��"; type = a
    Software Version = .; Hardware Version = �.
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: leave prog mode
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: exit bootloader
the selected serial port avrdude: butterfly_recv(): programmer is not responding
 does not exist or your board is not connected

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


Now, I loaded this FAQ for troubleshooting, and figured my problem might have to do with the wrong port being selected. I was connected to Bluetooth-incoming-port rather than USB port. I restarted Arduino IDE and was able to see the correct port briefly. But even then when I was connected to the USB port and tried to upload, I got this error:

Code: Select all | TOGGLE FULL SIZE
Arduino: 1.8.0 (Mac OS X), Board: "Adafruit Flora"

Sketch uses 6968 bytes (24%) of program storage space. Maximum is 28672 bytes.
Global variables use 184 bytes of dynamic memory.
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_send(): write error: Device not configured
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_send(): write error: Device not configured
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
Found programmer: Id = "CATERIN"; type = }
    Software Version = .; Hardware Version = �.
the selected serial port Found programmer: Id = "CATERIN"; type = }
 does not exist or your board is not connected
avrdude: ser_send(): write error: Device not configured
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_send(): write error: Device not configured
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: ser_send(): write error: Device not configured
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: leave prog mode
avrdude: ser_send(): write error: Device not configured
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: exit bootloader
avrdude: ser_close(): can't reset attributes for device: Device not configured

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


At this point I'm at a loss. Any idea what I should do? Thanks,

jaxdesign
 
Posts: 24
Joined: Tue Sep 20, 2016 10:29 pm

Re: Help with basic rainbow cycle

by jaxdesign on Sat Jul 22, 2017 10:12 pm

I think the issue is relating to the port... I have no USB option, only bluetooth, and it seems like the board is not being connected to my mac. Is it drawing too much power somehow? When I plug in the flora, all the LEDs turn on, and then turn red. I'm not sure if the microUSB cable is the issue or if there's something else going on. The USB ports work for thumbdrives, but my flora wont connect.

I also tried two separate floras with different code, seemed to make no difference. The usbport option isnt available under Tools/Port.

jaxdesign
 
Posts: 24
Joined: Tue Sep 20, 2016 10:29 pm

Please be positive and constructive with your questions and comments.