0

Party Neopixel App Glasses Trinklet M0 version Need Help
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Party Neopixel App Glasses Trinklet M0 version Need Help

by Blueshark on Tue Jan 22, 2019 10:20 pm

I'm still learning Arduino (not the basics) I need help in code see below....

Story about project:

I saw this tutorial and decided to make my own pair of Party Eye Glasses...
https://learn.adafruit.com/celebration-spectacles/overview

The Animations were not that great and the tutorial uses a Basic Trinket 5V.

I updated the Trinket to the Trinket M0 and Added Bluetooth LE (UART version).
see pictures....

https://drive.google.com/file/d/1qliOc3aZOSm1tyU75ODf5FHXmUgfttWb/view?usp=sharing
https://drive.google.com/file/d/1OKp-wGK6tM1UnArFOzbJsTUZkhP05Lcu/view?usp=sharing

Later I'm going to add a microphone to make the Neopixel lights light up when they detect noise; music, talking, etc...
I got the idea from this tutorial....

https://learn.adafruit.com/ledshades/overview

I think I can handle the Mic. code on my own, but will post if I need help...

End Of Story....

The code I'm currently using is from one of Adafruits tutorials.... Cant find it at the moment...

The code works as is... no problems; I have even changed the button #s on the code for diffirent buttons on the Bluefruit App. (Android Version)

The Problem I'm having is when I try to use the Other Neopixel code: "theaterChaseRainbow", and "rainbow" I get an error compiling...

Heres the code and I place comments where I added the new code
Code: Select all | TOGGLE FULL SIZE
          /*********************************************************************
 This is an example for our nRF51822 based Bluefruit LE modules

 Pick one up today in the adafruit shop!

 Adafruit invests time and resources providing this open source code,
 please support Adafruit and open-source hardware by purchasing
 products from Adafruit!

 MIT license, check LICENSE for more information
 All text above, and the splash screen below must be included in
 any redistribution
*********************************************************************/

#include <string.h>
#include <Arduino.h>
#include <SPI.h>
#if not defined (_VARIANT_ARDUINO_DUE_X_) && not defined (_VARIANT_ARDUINO_ZERO_)
  #include <SoftwareSerial.h>
#endif

#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "Adafruit_BluefruitLE_UART.h"
#if SOFTWARE_SERIAL_AVAILABLE
  #include <SoftwareSerial.h>
#endif



#include "BluefruitConfig.h"

#include <Adafruit_NeoPixel.h>

#define BLUEFRUIT_HWSERIAL_NAME  Serial1
#define BLUEFRUIT_UART_MODE_PIN  (0)

/*=========================================================================
    APPLICATION SETTINGS

    FACTORYRESET_ENABLE       Perform a factory reset when running this sketch
   
                              Enabling this will put your Bluefruit LE module
                              in a 'known good' state and clear any config
                              data set in previous sketches or projects, so
                              running this at least once is a good idea.
   
                              When deploying your project, however, you will
                              want to disable factory reset by setting this
                              value to 0.  If you are making changes to your
                              Bluefruit LE device via AT commands, and those
                              changes aren't persisting across resets, this
                              is the reason why.  Factory reset will erase
                              the non-volatile memory where config data is
                              stored, setting it back to factory default
                              values.
       
                              Some sketches that require you to bond to a
                              central device (HID mouse, keyboard, etc.)
                              won't work at all with this feature enabled
                              since the factory reset will clear all of the
                              bonding data stored on the chip, meaning the
                              central device won't be able to reconnect.
    PIN                       Which pin on the Arduino is connected to the NeoPixels?
    NUMPIXELS                 How many NeoPixels are attached to the Arduino?
    -----------------------------------------------------------------------*/
    #define FACTORYRESET_ENABLE     1

    #define PIN                     6
    #define NUMPIXELS               32
/*=========================================================================*/

Adafruit_NeoPixel pixel = Adafruit_NeoPixel(NUMPIXELS, PIN);

// Create the bluefruit object, either software serial...uncomment these lines
/*
SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);

Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,
                      BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);
*/

/* ...or hardware serial, which does not need the RTS/CTS pins. Uncomment this line */
//Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);

/* ...hardware SPI, using SCK/MOSI/MISO hardware SPI pins and then user selected CS/IRQ/RST */
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);

/* ...software SPI, using SCK/MOSI/MISO user-defined SPI pins and then user selected CS/IRQ/RST */
//Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_SCK, BLUEFRUIT_SPI_MISO,
//                             BLUEFRUIT_SPI_MOSI, BLUEFRUIT_SPI_CS,
//                             BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);


// A small helper
void error(const __FlashStringHelper*err) {
  Serial.println(err);
  while (1);
}

// function prototypes over in packetparser.cpp
uint8_t readPacket(Adafruit_BLE *ble, uint16_t timeout);
float parsefloat(uint8_t *buffer);
void printHex(const uint8_t * data, const uint32_t numBytes);

// the packet buffer
extern uint8_t packetbuffer[];


/**************************************************************************/
/*!
    @brief  Sets up the HW an the BLE module (this function is called
            automatically on startup)
*/
/**************************************************************************/
//additional variables

//Color
    uint8_t red = 100;
    uint8_t green = 100;
    uint8_t blue = 100;
uint8_t animationState = 6;

    int pos = 0, dir = 1; // Position, direction of "eye" for larson scanner animation

void setup(void)
{
  //while (!Serial);  // required for Flora & Micro
  delay(500);

  // turn off neopixel
  pixel.begin(); // This initializes the NeoPixel library.
  for(uint8_t i=0; i<NUMPIXELS; i++) {
    pixel.setPixelColor(i, pixel.Color(0,0,0)); // off
  }
  colorWipe(pixel.Color(100, 100, 100), 20); // do a quick colorWipe to show that the pixels are all working, even before Bluefruit connection established
  colorWipe(pixel.Color(0, 0, 0), 20);
  pixel.show();

  Serial.begin(115200);
  Serial.println(F("Adafruit Bluefruit Neopixel Color Picker Example"));
  Serial.println(F("------------------------------------------------"));

  /* Initialise the module */
  Serial.print(F("Initialising the Bluefruit LE module: "));

  if ( !ble.begin(VERBOSE_MODE) )
  {
    error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
  }
  Serial.println( F("OK!") );

  if ( FACTORYRESET_ENABLE )
  {
    /* Perform a factory reset to make sure everything is in a known state */
    Serial.println(F("Performing a factory reset: "));
    if ( ! ble.factoryReset() ){
      error(F("Couldn't factory reset"));
    }
  }

  /* Disable command echo from Bluefruit */
  ble.echo(false);

  Serial.println("Requesting Bluefruit info:");
  /* Print Bluefruit information */
  ble.info();

  Serial.println(F("Please use Adafruit Bluefruit LE app to connect in Controller mode"));
  Serial.println(F("Then activate/use the sensors, color picker, game controller, etc!"));
  Serial.println();

  ble.verbose(false);  // debug info is a little annoying after this point!

  /* Wait for connection */
  while (! ble.isConnected()) {
      delay(500);
  }

  Serial.println(F("***********************"));

  // Set Bluefruit to DATA mode
  Serial.println( F("Switching to DATA mode!") );
  ble.setMode(BLUEFRUIT_MODE_DATA);

  Serial.println(F("***********************"));

}

/**************************************************************************/
/*!
    @brief  Constantly poll for new command or response data
*/
/**************************************************************************/
void loop(void)
{
  /* Wait for new data to arrive */
  uint8_t len = readPacket(&ble, BLE_READPACKET_TIMEOUT);
  //if (len == 0) return;

  /* Got a packet! */
  // printHex(packetbuffer, len);

  // Color
  if (packetbuffer[1] == 'C') {
    red = packetbuffer[2];
    green = packetbuffer[3];
    blue = packetbuffer[4];
    Serial.print ("RGB #");
    if (red < 0x10) Serial.print("0");
    Serial.print(red, HEX);
    if (green < 0x10) Serial.print("0");
    Serial.print(green, HEX);
    if (blue < 0x10) Serial.print("0");
    Serial.println(blue, HEX);

// this part colors ALL the pixels according to the app's color picker:
//    for(uint8_t i=0; i<NUMPIXELS; i++) {
//      pixel.setPixelColor(i, pixel.Color(red,green,blue));
//   }
//    pixel.show(); // This sends the updated pixel color to the hardware.
  }

  // Buttons
  if (packetbuffer[1] == 'B') {
 
    uint8_t buttnum = packetbuffer[2] - '0';
    boolean pressed = packetbuffer[3] - '0';
    Serial.print ("Button "); Serial.print(buttnum);
    animationState = buttnum;
    if (pressed) {
      Serial.println(" pressed");
    } else {
      Serial.println(" released");
    }
  }
   
  if (animationState == 1){ // button labeled "1" in control pad
    for(uint16_t i=0; i<pixel.numPixels(); i++) { //clear all pixels before displaying new animation
          pixel.setPixelColor(i, pixel.Color(0,0,0));
        }
     flashRandom(5,random(10,30));
     pixel.show(); // This sends the updated pixel color to the hardware.
   }
 
  if (animationState == 2){ // button labeled "2" in control pad
    for(uint16_t i=0; i<pixel.numPixels(); i++) { //clear all pixels before displaying new animation
          pixel.setPixelColor(i, pixel.Color(0,0,0));
        }
    colorWipe(pixel.Color(red, green, blue), 20);
    pixel.show(); // This sends the updated pixel color to the hardware.
    colorWipe(pixel.Color(0, 0, 0), 20);
    pixel.show();
  }

  if (animationState == 3){ // button labeled "3" in control pad
    for(uint16_t i=0; i<pixel.numPixels(); i++) { //clear all pixels before displaying new animation
          pixel.setPixelColor(i, pixel.Color(0,0,0));
        }
    larsonScanner(30); // larsonScanner is set to red and does not take color input.
    pixel.show(); // This sends the updated pixel color to the hardware.
  }
 
  if (animationState == 4){ // button labeled "4" in control pad
    for(uint16_t i=0; i<pixel.numPixels(); i++) { //clear all pixels before displaying new animation
          pixel.setPixelColor(i, pixel.Color(0,0,0));
        }
    rainbowCycle(20);
    pixel.show(); // This sends the updated pixel color to the hardware.
  }


// I added this code button 5 & 6, NOT PART Of Original code
//--------------------------------------------------------------------------------------

  if (animationState == 5){ // button labeled "5" in control pad
    for(uint16_t i=0; i<pixel.numPixels(); i++) { //clear all pixels before displaying new animation
          pixel.setPixelColor(i, pixel.Color(0,0,0));
        }
    rainbow(20);
    pixel.show(); // This sends the updated pixel color to the hardware.

    if (animationState == 6){ // button labeled "6" in control pad
    for(uint16_t i=0; i<pixel.numPixels(); i++) { //clear all pixels before displaying new animation
          pixel.setPixelColor(i, pixel.Color(0,0,0));
        }
    theaterChaseRainbow(20);
    pixel.show(); // This sends the updated pixel color to the hardware.

//--------------------------------------------------------------------------------------
   
}


// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<pixel.numPixels(); i++) {
      pixel.setPixelColor(i, c);
      pixel.show();
      delay(wait);
  }
}

void larsonScanner(uint8_t wait){
   int j;
   
 for(uint16_t i=0; i<pixel.numPixels()+5; i++) {
  // Draw 5 pixels centered on pos.  setPixelColor() will clip any
  // pixels off the ends of the strip, we don't need to watch for that.
  pixel.setPixelColor(pos - 2, 0x100000); // Dark red
  pixel.setPixelColor(pos - 1, 0x800000); // Medium red
  pixel.setPixelColor(pos    , 0xFF3000); // Center pixel is brightest
  pixel.setPixelColor(pos + 1, 0x800000); // Medium red
  pixel.setPixelColor(pos + 2, 0x100000); // Dark red
 
  pixel.show();
  delay(wait);
 
  // Rather than being sneaky and erasing just the tail pixel,
  // it's easier to erase it all and draw a new one next time.
  for(j=-2; j<= 2; j++) pixel.setPixelColor(pos+j, 0);
 
  // Bounce off ends of strip
  pos += dir;
  if(pos < 0) {
    pos = 1;
    dir = -dir;
  } else if(pos >= pixel.numPixels()) {
    pos = pixel.numPixels() - 2;
    dir = -dir;
  }
 }
}

void flashRandom(int wait, uint8_t howmany) {
 randomSeed(analogRead(0));
  for(uint16_t i=0; i<howmany; i++) {
    // get a random pixel from the list
    int j = random(pixel.numPixels());
   
    // now we will 'fade' it in 5 steps
    for (int x=0; x < 5; x++) {
      int r = red * (x+1); r /= 5;
      int g = green * (x+1); g /= 5;
      int b = blue * (x+1); b /= 5;
     
      pixel.setPixelColor(j, pixel.Color(r, g, b));
      pixel.show();
      delay(wait);
    }
    // & fade out in 5 steps
    for (int x=5; x >= 0; x--) {
      int r = red * x; r /= 5;
      int g = green * x; g /= 5;
      int b = blue * x; b /= 5;
     
      pixel.setPixelColor(j, pixel.Color(r, g, b));
      pixel.show();
      delay(wait);
    }
  }
  // LEDs will be off when done (they are faded to 0)
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<pixel.numPixels(); i++) {
      pixel.setPixelColor(i, Wheel((i+j) & 255));
    }
    pixel.show();
    delay(wait);
  }
}

// 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< pixel.numPixels(); i++) {
      pixel.setPixelColor(i, Wheel(((i * 256 / pixel.numPixels()) + j) & 255));
    }
    pixel.show();
    delay(wait);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < pixel.numPixels(); i=i+3) {
        pixel.setPixelColor(i+q, c);    //turn every third pixel on
      }
      pixel.show();

      delay(wait);

      for (int i=0; i < pixel.numPixels(); i=i+3) {
        pixel.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
      for (int i=0; i < pixel.numPixels(); i=i+3) {
        pixel.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
      }
      pixel.show();

      delay(wait);

      for (int i=0; i < pixel.numPixels(); i=i+3) {
        pixel.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

// 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 pixel.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return pixel.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return pixel.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
         


Here's the Error messages I get...

Code: Select all | TOGGLE FULL SIZE
      Arduino: 1.8.5 (Windows 10), Board: "Adafruit Metro"

C:\Users\alex2\OneDrive\Documents\My_programs\Feather_M0_bluefruitLE_neopixel_animation_controller_2\Feather_M0_bluefruitLE_neopixel_animation_controller_2.ino: In function 'void setup()':

Feather_M0_bluefruitLE_neopixel_animation_controller_2:136: error: 'colorWipe' was not declared in this scope

   colorWipe(pixel.Color(100, 100, 100), 20); // do a quick colorWipe to show that the pixels are all working, even before Bluefruit connection established

                                           ^

C:\Users\alex2\OneDrive\Documents\My_programs\Feather_M0_bluefruitLE_neopixel_animation_controller_2\Feather_M0_bluefruitLE_neopixel_animation_controller_2.ino: In function 'void loop()':

Feather_M0_bluefruitLE_neopixel_animation_controller_2:242: error: 'flashRandom' was not declared in this scope

      flashRandom(5,random(10,30));

                                 ^

Feather_M0_bluefruitLE_neopixel_animation_controller_2:250: error: 'colorWipe' was not declared in this scope

     colorWipe(pixel.Color(red, green, blue), 20);

                                                ^

Feather_M0_bluefruitLE_neopixel_animation_controller_2:260: error: 'larsonScanner' was not declared in this scope

     larsonScanner(30); // larsonScanner is set to red and does not take color input.

                     ^

Feather_M0_bluefruitLE_neopixel_animation_controller_2:268: error: 'rainbowCycle' was not declared in this scope

     rainbowCycle(20);

                    ^

Feather_M0_bluefruitLE_neopixel_animation_controller_2:280: error: 'rainbow' was not declared in this scope

     rainbow(20);

               ^

Feather_M0_bluefruitLE_neopixel_animation_controller_2:287: error: 'theaterChaseRainbow' was not declared in this scope

     theaterChaseRainbow(20);

                           ^

Feather_M0_bluefruitLE_neopixel_animation_controller_2:296: error: a function-definition is not allowed here before '{' token

 void colorWipe(uint32_t c, uint8_t wait) {

                                          ^

Feather_M0_bluefruitLE_neopixel_animation_controller_2:439: error: expected '}' at end of input

 }

 ^

Feather_M0_bluefruitLE_neopixel_animation_controller_2:439: error: expected '}' at end of input

exit status 1
'colorWipe' was not declared in this scope

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


The Problem is not the "colorwipe" part; when I comment out the code that I added the Sketch Compiles just fine....

Can some one explain what is going on....


Thanks
Cheers...

Blueshark
 
Posts: 100
Joined: Thu Dec 21, 2017 7:19 pm

Re: Party Neopixel App Glasses Trinklet M0 version Need Help

by Blueshark on Tue Jan 22, 2019 10:42 pm

Sorry guys... I found my mistake..... it was the Curly Brackets that were missing in my added code. Everything works..... so far....

Blueshark
 
Posts: 100
Joined: Thu Dec 21, 2017 7:19 pm

Re: Party Neopixel App Glasses Trinklet M0 version Need Help

by Blueshark on Fri Jan 25, 2019 11:33 pm

I have a Trinket M0 / Neopixel powering Question, regarding this project.


I'm using these Neopixel Rings, 2 of them...
https://www.adafruit.com/product/1586

Q. If I power the Neopixel Rings with the Trinket M0 USB pin, isn't there going to be a problem since the Neopixels are being powered by the 5V of the USB port, but the Data pin is a 3V singnal from the Trinket M0 pin...


Cheers..

Blueshark
 
Posts: 100
Joined: Thu Dec 21, 2017 7:19 pm

Re: Party Neopixel App Glasses Trinklet M0 version Need Help

by adafruit_support_mike on Sun Jan 27, 2019 6:35 am

In theory there could be a problem, but in practice it almost always works.

Most 5V CMOS devices use a signal protocol that requires them to accept signals 3.5V or higher as HIGH input. These days, with chips being designed for mixed-voltage systems, the limit is usually defined as 70% of VCC, whatever voltage VCC happens to be.

To guarantee a chip obeys that protocol, manufacturers usually design chips that accept anything over 60% to 65% of VCC as HIGH input. That puts the real high-input threshold down around 3V, where it will accept input from 3.3V devices.

It's an off-spec use of the device, so you can't blame the manufacturer if it doesn't work, but you're free to take advantage of it if experience shows that it does work.

adafruit_support_mike
 
Posts: 55956
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.