Editing Codes for Pixel ring goggles

Ok so making these goggles for my sons halloween costume. Ive tried editing the code and havent had any luck. He wants them to spin constantly and stay red. Heres the code im using.

// 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
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(32, PIN);

uint8_t mode = 0, // Current animation effect
 offset = 0; // Position of spinny eyes
uint32_t color = 0xFF0000; //  red
uint32_t prevTime;
void setup() {
#ifdef __AVR_ATtiny85__ // Trinket, Gemma, etc.
 if(F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
 pixels.begin();
 pixels.setBrightness(50); // 1/3 brightness
 prevTime = millis();
}
void loop() {
 uint8_t i;
 uint32_t t;
 switch(mode) {
 case 1: // Spinny wheels (8 LEDs on at a time)
 for(i=0; i<16; i++) {
 uint32_t c = 0;
 }
 pixels.show();
 offset++;
 delay(50);
 break;
 }
 t = millis();
 if((t - prevTime) > 8000) { // Every 8 seconds...
 mode++; // Next mode
 if(mode > 1) { // End of modes?
 mode = 0; // Start modes over
 color >>= 8; //  color R
 if(!color) color = 0xFF0000; // Reset to red
 }
 for(i=0; i<32; i++) pixels.setPixelColor(i, 0);
 prevTime = t;
 }
}

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project.

Luck does not create any working project in this field.
You want spinning red.... What do You get?

Did you start with this sketch ? https://learn.adafruit.com/kaleidoscope-eyes-neopixel-led-goggles-trinket-gemma/arduino-code
That is a single pin to both ring-ledstrips of 16 leds each ?

Which Arduino board do you use ?

Two opposite rotating red leds is not so hard when I don't look at the example code and just type in the code:

// For: https://forum.arduino.cc/t/editing-codes-for-pixel-ring-goggles/1032937
//
// Example used as a starting point:
//   https://learn.adafruit.com/kaleidoscope-eyes-neopixel-led-goggles-trinket-gemma/arduino-code
//


#include <Adafruit_NeoPixel.h>

#define PIN 2
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(32, PIN);
// Adafruit_NeoPixel pixels( 32, PIN, NEO_GRB + NEO_KHZ800);  // alternative

int offset;                         // the position of the red leds, 0...15

void setup()
{
  pixels.begin();
}

void loop()
{
  for( int i = 0; i < 16; i++) 
  {
    int brightness = 0;             // default off
    if( i == offset)
      brightness = 255;

    if( i == (offset + 8)%16)       // opposite side
      brightness = 255;

    // set left ring
    pixels.setPixelColor(i, pixels.Color(brightness, 0, 0)); 

    // set right ring
    pixels.setPixelColor(i + 16, pixels.Color(brightness, 0, 0)); 
  }
  pixels.show();

  offset++;
  if( offset >= 16)
    offset = 0;

  delay( 100);
}

This sketch in Wokwi:

spin

Well at least you are working on this with what should be plenty of time.

We usually see Hallowe'en projects in late October. :expressionless:

a7

1 Like

Nice. Now make one go clockwise and the other anticlockwise.

Never mind. Just replace i + 16 with 31 - i in the second for loop…

a7

Then they are not mirrored.
I had this:

    // set right ring
    int j = 32 - i;
    if( j == 32)
      j = 16;
    pixels.setPixelColor(j, pixels.Color(brightness, 0, 0)); 

Yes I tried that code also. I’m using adafruit trinket mo board with the rings

True. And though I always argue for software solutions, here I would prolly cheat and just rotate one physical ring.

a7

1 Like

awesome man thanks about to try it

Appreciate this. It helped me learn that I need to learn a lot. Everything I tried only made it worse :joy:

this is best i can do. lol would like more leds to light up

GogglesNeopixel.ino - Wokwi Arduino and ESP32 Simulator

Could you make a photo of the goggles ? How far does the light of a single led spread ?
It is possible to have two leds at full brightness, or have a fading trail behind each led. Any pattern that you can think off is possible, that is what code is for.

By the way, my sketch can be improved. The loop has 'i' counting from 0 to 15, but it only needs to count to 7.

If you want to make changes to a Wokwi project, then you have to log in and make a copy. Wokwi is free to use, only a few things are for paid users (such as using a server to allow the ESP32 to connect to the internet).

Here they are with me two beers In

Be careful with those beers, they warp your face :rofl:

The single led is indeed too much visible. If I have time today, then I try a table with brightness that moves around.

With a table:

// For: https://forum.arduino.cc/t/editing-codes-for-pixel-ring-goggles/1032937
//
// Example used as a starting point:
//   https://learn.adafruit.com/kaleidoscope-eyes-neopixel-led-goggles-trinket-gemma/arduino-code
//
// First version: https://wokwi.com/projects/343127669674607186
// Version 2.
//   A single led was too much visible, now a table with brightness.
//   The loop with variable 'i' does no longer walk along the leds,
//   it walks along the table.
//   Next version should alow layers upon layers of led effects.
//

#include <Adafruit_NeoPixel.h>

#define PIN 2
Adafruit_NeoPixel pixels( 32, PIN, NEO_GRB + NEO_KHZ800);

int offset;                         // the position of the red leds, 0...7

// A table with the values.
// Keep the size below 8.
// The leds turn right and the ledIndex is incremented,
// therefor the front led is the last one in the table.
const int sizeTable = 6;
const int table[] = { 100, 180, 255, 255, 180, 100};   // soft blob
// const int table[] = { 80, 100, 120, 160, 200, 255};   // only a trail 


void setup()
{
  pixels.begin();
}

void loop()
{
  pixels.clear();                           // all leds off

  // lay the table on the leds, according to the position
  for( int i = 0; i < sizeTable; i++)       // walk along the table
  {
    int ledIndex = offset + i;
    ledIndex = ledIndex % 8;                // clip the ledIndex to 0...7

    // Set left ring
    // The table is put twice on the leds.
    pixels.setPixelColor( ledIndex, pixels.Color( table[i], 0, 0));
    pixels.setPixelColor( ledIndex + 8, pixels.Color( table[i], 0, 0));

    // Set right ring
    // The table is put twice on the leds.
    pixels.setPixelColor( ledIndex + 16, pixels.Color( table[i], 0, 0)); 
    pixels.setPixelColor( ledIndex + 24, pixels.Color( table[i], 0, 0)); 
  }
  
  pixels.show();        // update the new values to the ledstrip

  offset++;
  if( offset >= 8)
    offset = 0;

  delay( 100);
}

This sketch with Wokwi: GogglesNeopixelV2.ino - Wokwi Arduino and ESP32 Simulator

afbeelding

The leds in the real world might still be very bright with low values. You can adjust the values in the table. The Neopixel library can also set the overall brightness to save batteries.

Have you told which Arduino board you use ?

@Koepel nice. And as always, thanks for using and promoting the use of wokwi. Life changer. :expressionless:

Of course I hadda try the right eye surgery

  pixels.setPixelColor(31 - ledIndex, pixels.Color( table[i], 0, 0)); 
  pixels.setPixelColor(23 - ledIndex , pixels.Color( table[i], 0, 0)); 

If you can tell they aren't mirror images, go ahead and add the lines that fixed it last time.

a7

Yep and this project I’m using the adafruit trinket mo. And appreciate that I’ll try it tonight after work

where do i insert this or should i say which part do i replace