Goggle project…

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
plingboot
 
Posts: 12
Joined: Thu Sep 30, 2010 8:00 am

Goggle project…

Post by plingboot »

Just wondering if anyone could help me better understand what's going on in the code I've borrowed for my goggle project?

This is the sample code used in one or two other adafruit guides, but i've cobbled it about a bit to just have spinning circles and i'm using the Gemma board.

I do understand: the brightness setting, how to change the number of leds used, the speed of rotation and the duration of each 'case'.

I can see/change the hexadecimal value for the initial colour, but… i'm not grasping how that can be changed on the fly (what code i need) to achieve either a steady/smooth graduation across the colour spectrum or how to simply change to a specific colour value - as the leds spin.

Any help/pointers would be much appreciated.

As an aside, i had tremendous trouble getting the arduino IDE set-up to work with either the Gemma or Flora boards. I tried both ways - the simple way and the manual, moving/changing files in an existing install. I tried it on both my MacPro and MacBookPro - without success. Everything appeared to be set-up correctly, but when it came to writing files to the device I continually had avrdude errors.

Still not been able to fix the issue, but came across the codebender site, after which I was quickly able to connect and write code to the Gemma. So no idea what is going on with the arduino application… has anyone else has similar problems?

Code: Select all

// Low power NeoPixel goggles example.  Makes a nice blinky display
// with just a few LEDs on at any time...uses MUCH less juice than
// rainbow display!
 
#include <Adafruit_NeoPixel.h>
 
#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  = 0x00f0ff; // Start red
uint32_t prevTime;
 
void setup() {
  pixels.begin();
  pixels.setBrightness(85); // 1/3 brightness
  prevTime = millis();
}
 
void loop() {
  uint8_t  i;
  uint32_t t;
 
  switch(mode) {
 
   case 0: // Spinny wheels (8 LEDs on at a time)
    for(i=0; i<16; i++) {
      uint32_t c = 0;
      if(((offset + i) & 7) < 2) c = color; // 4 pixels on...
      pixels.setPixelColor(   i, c); // First eye
      pixels.setPixelColor(31-i, c); // Second eye (flipped)
    }
    pixels.show();
    offset++;
    delay(30);
    break;
    
    case 1: // Spinny wheels (8 LEDs on at a time)
    for(i=0; i<16; i++) {
      uint32_t c = 0;
      if(((offset + i) & 7) < 2) c = color; // 4 pixels on...
      pixels.setPixelColor(   i, c); // First eye
      pixels.setPixelColor(31-i, c); // Second eye (flipped)
    }
    pixels.show();
    offset++;
    delay(30);
    break;
 
 

  }
 
  t = millis();
  if((t - prevTime) > 3000) {      // Every 8 seconds...
    mode++;                        // Next mode
    if(mode > 1) {                 // End of modes?
      mode = 0;                    // Start modes over
      color >>= 8;                 // Next color R->G->B
      if(!color) color = 0x00f0ff; // Reset to red
    }
    for(i=0; i<32; i++) pixels.setPixelColor(i, 0);
    prevTime = t;
  }
}

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Goggle project…

Post by adafruit_support_bill »

The general formula for fading from one RGB color to another is:

Code: Select all

for(int i = 0; i <= n; i++) // larger values of 'n' will give a smoother/slower transition.
{
   Rnew = Rstart + (Rend - Rstart) * i / n;
   Gnew = Gstart + (Gend - Gstart) * i / n;
   Bnew = Bstart + (Bend - Bstart) * i / n;
 // set pixel color here
}

plingboot
 
Posts: 12
Joined: Thu Sep 30, 2010 8:00 am

Re: Goggle project…

Post by plingboot »

thanks bill, i managed to cobble together bits of various example code to produce something which works, though some of it doesn't make complete sense to me yet.

I've attached the code, should anyone wish to use it.

I do have a couple more code related questions. I saw THIS goggle project an would really like to emulate some of the effects. The code is supplied, but it goes way over my head.

Could anyone give me some help with code for selecting (ie) showing and hiding groups of pixels around the ring? I would for example like to have the upper half flash one colour while the lower half remains on in another colour.

And, continuing the half and half theme, have one half of the ring in one colour, the other in another colour, but have it rotating.

Code: Select all

#include <Adafruit_NeoPixel.h>

#define PIN 0

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(32, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  //Effect loops in their run order
  
  //colorWipe

  	colorWipeOn(30);
  	rainbow(1);
  	pixelsOff(30);
	colorWipeOn(30);
	rainbowCycle(1);
	pixelsOff(30);
	colorWipeOn(25);
	spinnyEyes(25);
	colorWipeOnRed(10);
	pixelsOff(30);
  //theaterChaseRainbow(50);
}

//	colorWipeOn
//	Fill the dots one after the other with spectrum colours
void colorWipeOn(uint8_t wait) {
  for(uint16_t i=0; i<16; i++) {
      strip.setPixelColor(i, Wheel((i * 256 / 16) & 255));
      strip.setPixelColor(31-i, Wheel((i * 256 / 16) & 255));
      strip.show();
      delay(wait);
  }
}


//	pixelsOff
void pixelsOff(uint8_t wait) {
	uint16_t j;
  for(uint16_t i=0; i<16; i++) {
      strip.setPixelColor(i, (0, 0, 0));
      strip.setPixelColor(31-i, (0, 0, 0));
      strip.show();
      delay(wait);
  }
}

// all on rainbow pulse
void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) {
    for(i=0; i<16; i++) {
      strip.setPixelColor(i, Wheel((i-j) & 255));
      strip.setPixelColor(31-i, Wheel((i-j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// all on rainbow cycle
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< 16; i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / 16) - j) & 255));
      strip.setPixelColor(31-i, Wheel(((i * 256 / 16) - j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

//spinning eyes with spectrum change
void spinnyEyes(uint8_t wait) {
	uint8_t	offset = 0;
	uint8_t  i;
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
        for(i=0; i<16; i++) {
        uint32_t c = 0;
        if(((offset + i) & 7) < 2) c = Wheel((i-j)&255);
          strip.setPixelColor(15-i, c);    //turn every third pixel on
          strip.setPixelColor(i+16, c); // Second eye (flipped)
        strip.show();
        }
        offset++;
    delay(wait);
  }
}

//spinning eyes with spectrum change
void colorWipeOnRed(uint8_t wait) {
	uint8_t	offset = 0;
	uint8_t  i;
for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(255, 0, 0));
      strip.setPixelColor(32-i, strip.Color(255, 0, 0));
      strip.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 strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else if(WheelPos < 170) {
    WheelPos -= 85;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  }
}

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Goggle project…

Post by adafruit_support_bill »

This will do a 2-color wipe. Half-color1 and half color2.

Code: Select all

void twoColorWipe(uint32_t color1, uint32_t color2, uint8_t wait) 
{
  for(uint16_t i=0; i<8; i++) 
  {
      strip.setPixelColor(i, color1);
      strip.setPixelColor(31-i, color1);
 
      strip.show();
      delay(wait);
  }
  for(uint16_t i=8; i<16; i++) 
  {
      strip.setPixelColor(i, color2);
      strip.setPixelColor(31-i, color2);
 
      strip.show();
      delay(wait);
  }
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”