0

Trinket + Neopixel 16 Ring
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Trinket + Neopixel 16 Ring

by Ronanb87 on Tue Mar 19, 2019 10:36 pm

I attached the code. It doesn't seem to quite work... main issue is orange (or any variation) = yellow. If i change to green or blue or even white, it works perfectly fine.

What am i doing wrong? The line i'm changing is: uint32_t color = 0xFFA500, // Current color... start orange

Code: Select all | TOGGLE FULL SIZE
// Low power NeoPixel goggles example.  Makes a nice blinky display
// with just a few LEDs on at any time.
 
#include <Adafruit_NeoPixel.h>
#ifdef __AVR_ATtiny85__ // Trinket, Gemma, etc.
 #include <avr/power.h>
#endif
 
#define PIN 0
#define default_brightness 85 // Brightness modes other than throb use
#define throb_min 20 // Minimum brightness level of throb, must be 0-255
#define throb_max 180 // Maxmimum brightness level of throb, must be 0-255
#define throb_delay 7 // Milliseconds between brightness levels in throb,
                          // turn it up slightly as max-min gets smaller
#define blink_rate 500 // Delay in milliseconds
 
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(32, PIN);
 
uint8_t  mode   = 2, // Current animation effect
         offset = 0; // Current position of spinner
uint32_t color  = 0xFFA500, // Current color... start orange
         throb_brightness = 85, // Current throb brightness
         mode_wait = 16000; // Current millseconds before switching to next mode
uint32_t prevTime;

// Color table:
// 0xFF0000 = red                  0x00FF00 = green          0x0000FF = blue
// 0xFFA500 = light yellow orange  0xFF8000 = orange         0xFF9933 = white orange
// 0xCC6600 = more orange          0x994C00 = darker orange
 
void setup() {
#ifdef __AVR_ATtiny85__ // Trinket, Gemma, etc.
  if(F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  pixels.begin();
  pixels.setBrightness(default_brightness); // Set to standard brightness
  prevTime = millis();
}
 
void loop() {
  uint8_t  i;
  uint32_t t;
 
  switch(mode) {
 
   case 0: // Random sparks - just one LED on at a time!
    pixels.setBrightness(default_brightness); // Set to standard brightness
    i = random(16);
    pixels.setPixelColor(i, color);
    pixels.show();
    delay(10);
    pixels.setPixelColor(i, 0);
    break;
 
   case 1: // Spinny wheels (8 LEDs on at a time)
    pixels.setBrightness(default_brightness); // Set to standard brightness
    for(i=0; i<16; i++) {
      uint32_t c = 0;
      if(((offset + i) & 7) < 2) c = color; // 4 pixels on...
      pixels.setPixelColor(   i, c); // Set pixel
    }
    pixels.show();
    offset++;
    delay(50);
    break;
   
    case 2: // Throb (16 LEDs on at a time)
    for(i=0; i<16; i++) {
      pixels.setPixelColor(   i, color); // Set pixels on
    }
    if (throb_brightness > (throb_max + (throb_max - throb_min))) {
      throb_brightness = throb_min;
    } else if (throb_brightness > throb_max) {
      pixels.setBrightness(throb_max - (throb_brightness - throb_max));
    } else {
      pixels.setBrightness(throb_brightness);
    }
    pixels.show();
    throb_brightness++;
    delay(throb_delay); // Delay in milliseconds
    break;
   
    case 3: // Blink on-off
    for(i=0; i<16; i++) pixels.setPixelColor(i, color); // Set pixels on
    pixels.show();
    delay(blink_rate);
    for(i=0; i<16; i++) pixels.setPixelColor(i, 0); // Set pixels off
    pixels.show();
    delay(blink_rate / 3);
    break;
  }
 
  t = millis();
  if((t - prevTime) > mode_wait) {      // Every several seconds...
    mode = random(0, 50);  // (Min, Max), excludes the upper bound number
    if (mode > 3) mode = 2; // Makes modes other than throb unlikely
    switch(mode) {
 
      case 0: // "Receive transmission..."
      color = 0x00FF00;  // Green
      mode_wait = 3000;
      break;
     
      case 1: // Spin
      color = 0x994C00;  // Orange
      mode_wait = 3000;
      break;
     
      case 2: // Throb
      color = 0x994C00;  // Orange
      mode_wait = 6000;
      break;
     
      case 3: // "Go rogue..."
      color = 0xFF0000;  // Red
      mode_wait = 5000;
      break;
     
    //mode++;                        // Next mode
    //if(mode > 3) {                 // End of modes?
    //  mode = 0;                    // Start modes over
    //  color >>= 8;                 // Next color R->G->B
      if(!color) color = 0x994C00; // Reset to orange
    }
    for(i=0; i<16; i++) pixels.setPixelColor(i, 0); // Wipe all pixels clean after mode change
    prevTime = t;
  }
}
Attachments
ShoulderBeacon.ino
(4.12 KiB) Downloaded 26 times
Last edited by Ronanb87 on Wed Mar 20, 2019 12:05 am, edited 1 time in total.

Ronanb87
 
Posts: 6
Joined: Mon Mar 18, 2019 11:44 pm

Re: Trinket + Neopixel

by franklin97355 on Tue Mar 19, 2019 11:25 pm

Have you tried the strand test code? What do you get when you do?

franklin97355
 
Posts: 21212
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Trinket + Neopixel

by Ronanb87 on Wed Mar 20, 2019 12:04 am

I have not, could you share please?

Ronanb87
 
Posts: 6
Joined: Mon Mar 18, 2019 11:44 pm

Re: Trinket + Neopixel 16 Ring

by franklin97355 on Wed Mar 20, 2019 12:13 am

It's an example in the Neopixel library. You would access it by going to the examples > Adafruit_neopixel > strandtest

franklin97355
 
Posts: 21212
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Trinket + Neopixel 16 Ring

by Ronanb87 on Wed Mar 20, 2019 12:16 am

Tried it, the 16 neopixel ring stays dark.

Ronanb87
 
Posts: 6
Joined: Mon Mar 18, 2019 11:44 pm

Re: Trinket + Neopixel 16 Ring

by Ronanb87 on Wed Mar 20, 2019 12:38 am

Got it to work thanks to a wonderful contributor on the adafruit discord.

I used a different color code and it worked... so weird!

Ronanb87
 
Posts: 6
Joined: Mon Mar 18, 2019 11:44 pm

Re: Trinket + Neopixel 16 Ring

by XRAD on Thu Mar 21, 2019 8:54 pm

Which Trinket do you have? Just tried the code above on an TM0 and all colors/patterns were fine....

XRAD
 
Posts: 532
Joined: Sat Nov 19, 2016 3:28 pm

Please be positive and constructive with your questions and comments.