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;
}
}
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);
}
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).
// 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);
}
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.