Conditional compilation goes spectacularly wrong in my script, below. If I #define PLUGNPLAY it works, and if I undefine PLUGNPLAY and comment out the #ifdef PLUGNPLAY at line 90, the following code up to and including the #else, end the #endif it works. But if I rely on the #ifdef to do the same job, the IDE inserts all the function defs in the bit which is not compiled!, as shown in the .cpp file following.
#include <Adafruit_NeoPixel.h>
#define MPU9150addr 0x68
#define Mine
//#define StG_1
//#define StG_2
//#define StG_3
//#define StG_4
// Magetometer offsets:
//Uncomment the next line for static offsets
//#define STATICOFFSETS
#ifdef Mine
#define MPU9150addr 0x69
#define MXOFFSET 1
#define MYOFFSET 60
#define MZOFFSET -96
#endif
#ifdef StG_1
// StG #1:
#define MPU9150addr 0x68
#define MXOFFSET 10
#define MYOFFSET -9
#define MZOFFSET -74
#endif
#ifdef StG_2
// StG #2:
#define MPU9150addr 0x68
#define MXOFFSET -36
#define MYOFFSET 68
#define MZOFFSET -30
#endif
#ifdef StG_3
// StG #3:
#define MPU9150addr 0x68
#define MXOFFSET -62
#define MYOFFSET -13
#define MZOFFSET -7
#endif
#ifdef StG_4
// StG #4:
#define MPU9150addr 0x68
#define MXOFFSET -45
#define MYOFFSET 5
#define MZOFFSET 19
#endif
//General configuration parameters:
#define PIN 8 // Neopixel data pin
#define BRILL 30 // Normal brilliance
#define BRILL1 100 // Brilliance for single flashes
//#define PLUGNPLAY // Dynmic ring size determination
#ifdef PLUGNPLAY
#define MAXPIXELS 60
#else
#define PIXELS 12
#endif
// Parameters for disco badge function:
#define SMOOTHING 10 // Smoothing factor
#define JUMP 5
#define ROCK 2.0
#define TWIST 5.0
#define MINACCEL 0.10 // Min accel, less than which taken as stationary
#define MINGYRO 0.10 // Min gyro, less than which taken as stationary
#define INACTIVITY 5000 // Millisecs of inactivity to count as stationary
#define REVERSED // Indicates Neopix and Accel have components on opposite sides
// Constants for particles:
#define MAXNUMPARTCLS 4 // Don't let NUMPARTCLS exceed this!
#define NUMPARTCLS (pixels >= 24? 3: 2)
#define G 50
#define FRICTION 0.05
#define MINMASS 0.5
#define MAXMASS 4
#define MAXSPD (pixels * 3) // Max initial speed
#define MINENERGY 20 // Energy at which particles die
#define CR 0.8
#define DARKMATTERENERGY 12000 // Energy needed to create dark matter
// 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)
#ifdef PLUGNPLAY
int pixels = MAXPIXELS;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(MAXPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#else
int pixels = PIXELS;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELS, PIN, NEO_GRB + NEO_KHZ800);
#endif
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"
(There's another 60 lines of stuff before we get to setup() )
This is the corresponding section of the resulting cpp file:
#line 1 "NeopixAccel.ino"
#include <Adafruit_NeoPixel.h>
#define MPU9150addr 0x68
#define Mine
#ifdef Mine
#define MPU9150addr 0x69
#define MXOFFSET 1
#define MYOFFSET 60
#define MZOFFSET -96
#endif
#ifdef StG_1
#define MPU9150addr 0x68
#define MXOFFSET 10
#define MYOFFSET -9
#define MZOFFSET -74
#endif
#ifdef StG_2
#define MPU9150addr 0x68
#define MXOFFSET -36
#define MYOFFSET 68
#define MZOFFSET -30
#endif
#ifdef StG_3
#define MPU9150addr 0x68
#define MXOFFSET -62
#define MYOFFSET -13
#define MZOFFSET -7
#endif
#ifdef StG_4
#define MPU9150addr 0x68
#define MXOFFSET -45
#define MYOFFSET 5
#define MZOFFSET 19
#endif
#define PIN 8
#define BRILL 30
#define BRILL1 100
#ifdef PLUGNPLAY
#define MAXPIXELS 60
#else
#define PIXELS 12
#endif
#define SMOOTHING 10
#define JUMP 5
#define ROCK 2.0
#define TWIST 5.0
#define MINACCEL 0.10
#define MINGYRO 0.10
#define INACTIVITY 5000
#define REVERSED
#define MAXNUMPARTCLS 4
#define NUMPARTCLS (pixels >= 24? 3: 2)
#define G 50
#define FRICTION 0.05
#define MINMASS 0.5
#define MAXMASS 4
#define MAXSPD (pixels * 3)
#define MINENERGY 20
#define CR 0.8
#define DARKMATTERENERGY 12000
#ifdef PLUGNPLAY
#include "Arduino.h"
void setup();
void loop();
void calibrate();
boolean displayCal();
void discoBadge();
void readAccel();
void readMag();
uint32_t Wheel(int WheelPos, byte brill);
uint32_t colorAdd(uint32_t rgb1, uint32_t rgb2);
uint32_t colorMultiply(uint32_t rgb, float x);
void eepromStore();
boolean eepromLoad();
void particles();
void patterns();
void myDelay(unsigned long time);
void testall(uint16_t time);
void colorWipe(uint32_t c, uint16_t time);
void rainbowWipe(uint8_t n, uint16_t time);
void rainbowCycle(uint8_t n, uint16_t time);
void theaterChase(uint32_t c, uint16_t n, uint16_t time);
void theaterChaseChange(uint16_t n, uint16_t time);
void theaterChaseRainbow(uint16_t n, uint16_t time);
void RandomFlash(int n, int time);
#line 91
int pixels = MAXPIXELS;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(MAXPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#else
int pixels = PIXELS;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELS, PIN, NEO_GRB + NEO_KHZ800);
#endif
#include "Wire.h"
:o
So what made it think that was a good place to stick its stuff?
Regards - Philip