diff --git a/Adafruit_LSM303DLHC b/Adafruit_LSM303DLHC new file mode 160000 index 0000000..3adbf0e --- /dev/null +++ b/Adafruit_LSM303DLHC @@ -0,0 +1 @@ +Subproject commit 3adbf0e579498c4caa23ed8562e09d2cc89d7fde diff --git a/Adafruit_LSM303_Old/Adafruit_LSM303_Old.cpp b/Adafruit_LSM303_Old/Adafruit_LSM303_Old.cpp deleted file mode 100644 index 40da296..0000000 --- a/Adafruit_LSM303_Old/Adafruit_LSM303_Old.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/*************************************************************************** - This is a library for the LSM303 Accelerometer and magnentometer/compass - - Designed specifically to work with the Adafruit LSM303DLHC Breakout - - These displays use I2C to communicate, 2 pins are required to interface. - - Adafruit invests time and resources providing this open source code, - please support Adafruit andopen-source hardware by purchasing products - from Adafruit! - - Written by Kevin Townsend for Adafruit Industries. - BSD license, all text above must be included in any redistribution - ***************************************************************************/ -#include - -/*************************************************************************** - CONSTRUCTOR - ***************************************************************************/ -bool Adafruit_LSM303_Old::begin() -{ - Wire.begin(); -Serial.println("Wire"); - - // Enable the accelerometer - write8(LSM303_ADDRESS_ACCEL, LSM303_REGISTER_ACCEL_CTRL_REG1_A, 0x27); - - // Enable the magnetometer - write8(LSM303_ADDRESS_MAG, LSM303_REGISTER_MAG_MR_REG_M, 0x00); - - return true; -} - -/*************************************************************************** - PUBLIC FUNCTIONS - ***************************************************************************/ -void Adafruit_LSM303_Old::read() -{ - // Read the accelerometer - Wire.beginTransmission((byte)LSM303_ADDRESS_ACCEL); - Wire.write(LSM303_REGISTER_ACCEL_OUT_X_L_A | 0x80); - Wire.endTransmission(); - Wire.requestFrom((byte)LSM303_ADDRESS_ACCEL, (byte)6); - - // Wait around until enough data is available - while (Wire.available() < 6); - - uint8_t xlo = Wire.read(); - uint8_t xhi = Wire.read(); - uint8_t ylo = Wire.read(); - uint8_t yhi = Wire.read(); - uint8_t zlo = Wire.read(); - uint8_t zhi = Wire.read(); - - // Shift values to create properly formed integer (low byte first) - accelData.x = (xlo | (xhi << 8)) >> 4; - accelData.y = (ylo | (yhi << 8)) >> 4; - accelData.z = (zlo | (zhi << 8)) >> 4; - - // Read the magnetometer - Wire.beginTransmission((byte)LSM303_ADDRESS_MAG); - Wire.write(LSM303_REGISTER_MAG_OUT_X_H_M); - Wire.endTransmission(); - Wire.requestFrom((byte)LSM303_ADDRESS_MAG, (byte)6); - - // Wait around until enough data is available - while (Wire.available() < 6); - - // Note high before low (different than accel) - xhi = Wire.read(); - xlo = Wire.read(); - zhi = Wire.read(); - zlo = Wire.read(); - yhi = Wire.read(); - ylo = Wire.read(); - - // Shift values to create properly formed integer (low byte first) - magData.x = (xlo | (xhi << 8)); - magData.y = (ylo | (yhi << 8)); - magData.z = (zlo | (zhi << 8)); - - // ToDo: Calculate orientation - magData.orientation = 0.0; -} - -void Adafruit_LSM303_Old::setMagGain(lsm303MagGain gain) -{ - write8(LSM303_ADDRESS_MAG, LSM303_REGISTER_MAG_CRB_REG_M, (byte)gain); -} - -/*************************************************************************** - PRIVATE FUNCTIONS - ***************************************************************************/ -void Adafruit_LSM303_Old::write8(byte address, byte reg, byte value) -{ - Wire.beginTransmission(address); - Wire.write(reg); - Wire.write(value); - Wire.endTransmission(); -} - -byte Adafruit_LSM303_Old::read8(byte address, byte reg) -{ - byte value; - - Wire.beginTransmission(address); - Wire.write(reg); - Wire.endTransmission(); - Wire.requestFrom(address, (byte)1); - value = Wire.read(); - Wire.endTransmission(); - - return value; -} diff --git a/Adafruit_LSM303_Old/Adafruit_LSM303_Old.h b/Adafruit_LSM303_Old/Adafruit_LSM303_Old.h deleted file mode 100644 index 3f5b111..0000000 --- a/Adafruit_LSM303_Old/Adafruit_LSM303_Old.h +++ /dev/null @@ -1,124 +0,0 @@ -/*************************************************************************** - This is a library for the LSM303 Accelerometer and magnentometer/compass - - Designed specifically to work with the Adafruit LSM303DLHC Breakout - - These displays use I2C to communicate, 2 pins are required to interface. - - Adafruit invests time and resources providing this open source code, - please support Adafruit andopen-source hardware by purchasing products - from Adafruit! - - Written by Kevin Townsend for Adafruit Industries. - BSD license, all text above must be included in any redistribution - ***************************************************************************/ -#ifndef __LSM303_H__ -#define __LSM303_H__ - -#if (ARDUINO >= 100) - #include "Arduino.h" -#else - #include "WProgram.h" -#endif -#include "Wire.h" - -#define LSM303_ADDRESS_ACCEL (0x32 >> 1) // 0011001x -#define LSM303_ADDRESS_MAG (0x3C >> 1) // 0011110x -#define LSM303_ID (0b11010100) - -class Adafruit_LSM303_Old -{ - public: - typedef enum - { // DEFAULT TYPE - LSM303_REGISTER_ACCEL_CTRL_REG1_A = 0x20, // 00000111 rw - LSM303_REGISTER_ACCEL_CTRL_REG2_A = 0x21, // 00000000 rw - LSM303_REGISTER_ACCEL_CTRL_REG3_A = 0x22, // 00000000 rw - LSM303_REGISTER_ACCEL_CTRL_REG4_A = 0x23, // 00000000 rw - LSM303_REGISTER_ACCEL_CTRL_REG5_A = 0x24, // 00000000 rw - LSM303_REGISTER_ACCEL_CTRL_REG6_A = 0x25, // 00000000 rw - LSM303_REGISTER_ACCEL_REFERENCE_A = 0x26, // 00000000 r - LSM303_REGISTER_ACCEL_STATUS_REG_A = 0x27, // 00000000 r - LSM303_REGISTER_ACCEL_OUT_X_L_A = 0x28, - LSM303_REGISTER_ACCEL_OUT_X_H_A = 0x29, - LSM303_REGISTER_ACCEL_OUT_Y_L_A = 0x2A, - LSM303_REGISTER_ACCEL_OUT_Y_H_A = 0x2B, - LSM303_REGISTER_ACCEL_OUT_Z_L_A = 0x2C, - LSM303_REGISTER_ACCEL_OUT_Z_H_A = 0x2D, - LSM303_REGISTER_ACCEL_FIFO_CTRL_REG_A = 0x2E, - LSM303_REGISTER_ACCEL_FIFO_SRC_REG_A = 0x2F, - LSM303_REGISTER_ACCEL_INT1_CFG_A = 0x30, - LSM303_REGISTER_ACCEL_INT1_SOURCE_A = 0x31, - LSM303_REGISTER_ACCEL_INT1_THS_A = 0x32, - LSM303_REGISTER_ACCEL_INT1_DURATION_A = 0x33, - LSM303_REGISTER_ACCEL_INT2_CFG_A = 0x34, - LSM303_REGISTER_ACCEL_INT2_SOURCE_A = 0x35, - LSM303_REGISTER_ACCEL_INT2_THS_A = 0x36, - LSM303_REGISTER_ACCEL_INT2_DURATION_A = 0x37, - LSM303_REGISTER_ACCEL_CLICK_CFG_A = 0x38, - LSM303_REGISTER_ACCEL_CLICK_SRC_A = 0x39, - LSM303_REGISTER_ACCEL_CLICK_THS_A = 0x3A, - LSM303_REGISTER_ACCEL_TIME_LIMIT_A = 0x3B, - LSM303_REGISTER_ACCEL_TIME_LATENCY_A = 0x3C, - LSM303_REGISTER_ACCEL_TIME_WINDOW_A = 0x3D - } lsm303AccelRegisters_t; - - typedef enum - { - LSM303_REGISTER_MAG_CRA_REG_M = 0x00, - LSM303_REGISTER_MAG_CRB_REG_M = 0x01, - LSM303_REGISTER_MAG_MR_REG_M = 0x02, - LSM303_REGISTER_MAG_OUT_X_H_M = 0x03, - LSM303_REGISTER_MAG_OUT_X_L_M = 0x04, - LSM303_REGISTER_MAG_OUT_Z_H_M = 0x05, - LSM303_REGISTER_MAG_OUT_Z_L_M = 0x06, - LSM303_REGISTER_MAG_OUT_Y_H_M = 0x07, - LSM303_REGISTER_MAG_OUT_Y_L_M = 0x08, - LSM303_REGISTER_MAG_SR_REG_Mg = 0x09, - LSM303_REGISTER_MAG_IRA_REG_M = 0x0A, - LSM303_REGISTER_MAG_IRB_REG_M = 0x0B, - LSM303_REGISTER_MAG_IRC_REG_M = 0x0C, - LSM303_REGISTER_MAG_TEMP_OUT_H_M = 0x31, - LSM303_REGISTER_MAG_TEMP_OUT_L_M = 0x32 - } lsm303MagRegisters_t; - - typedef enum - { - LSM303_MAGGAIN_1_3 = 0x20, // +/- 1.3 - LSM303_MAGGAIN_1_9 = 0x40, // +/- 1.9 - LSM303_MAGGAIN_2_5 = 0x60, // +/- 2.5 - LSM303_MAGGAIN_4_0 = 0x80, // +/- 4.0 - LSM303_MAGGAIN_4_7 = 0xA0, // +/- 4.7 - LSM303_MAGGAIN_5_6 = 0xC0, // +/- 5.6 - LSM303_MAGGAIN_8_1 = 0xE0 // +/- 8.1 - } lsm303MagGain; - - typedef struct lsm303AccelData_s - { - float x; - float y; - float z; - } lsm303AccelData; - - typedef struct lsm303MagData_s - { - float x; - float y; - float z; - float orientation; - } lsm303MagData; - - bool begin(void); - void read(void); - void setMagGain(lsm303MagGain gain); - - lsm303AccelData accelData; // Last read accelerometer data will be available here - lsm303MagData magData; // Last read magnetometer data will be available here - - void write8(byte address, byte reg, byte value); - byte read8(byte address, byte reg); - - private: -}; - -#endif diff --git a/Adafruit_LSM303_Old/README.md b/Adafruit_LSM303_Old/README.md deleted file mode 100644 index e07bbd5..0000000 --- a/Adafruit_LSM303_Old/README.md +++ /dev/null @@ -1,21 +0,0 @@ -Adafruit_LSM303 -=============== - -This is a library for the Adafruit triple-axis accelerometer/magnetometer LSM303DLHC breakout - -Designed specifically to work with the Adafruit LSM303 Breakout - ----> https://www.adafruit.com/products/1120 - -These displays use I2C to communicate, 2 pins are required to interface -Adafruit invests time and resources providing this open source code, -please support Adafruit and open-source hardware by purchasing -products from Adafruit! - -Check out the links above for our tutorials and wiring diagrams - -Written by Kevin Townsend for Adafruit Industries. -BSD license, all text above must be included in any redistribution - -To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_LSM303. Check that the Adafruit_LSM303 folder contains Adafruit_LSM303.cpp and Adafruit_LSM303.h - -Place the Adafruit_LSM303 library folder your *arduinosketchfolder*/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. diff --git a/Adafruit_LSM303_Old/examples/Test/Test.ino b/Adafruit_LSM303_Old/examples/Test/Test.ino deleted file mode 100644 index 2fe0914..0000000 --- a/Adafruit_LSM303_Old/examples/Test/Test.ino +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -Adafruit_LSM303 lsm; - -void setup() -{ - Serial.begin(9600); - - // Try to initialise and warn if we couldn't detect the chip - if (!lsm.begin()) - { - Serial.println("Oops ... unable to initialize the LSM303. Check your wiring!"); - while (1); - } -} - -void loop() -{ - lsm.read(); - Serial.print("Accel X: "); Serial.print((int)lsm.accelData.x); Serial.print(" "); - Serial.print("Y: "); Serial.print((int)lsm.accelData.y); Serial.print(" "); - Serial.print("Z: "); Serial.println((int)lsm.accelData.z); Serial.print(" "); - Serial.print("Mag X: "); Serial.print((int)lsm.magData.x); Serial.print(" "); - Serial.print("Y: "); Serial.print((int)lsm.magData.y); Serial.print(" "); - Serial.print("Z: "); Serial.println((int)lsm.magData.z); Serial.print(" "); - delay(1000); -} diff --git a/Adafruit_Sensor b/Adafruit_Sensor new file mode 160000 index 0000000..e985f22 --- /dev/null +++ b/Adafruit_Sensor @@ -0,0 +1 @@ +Subproject commit e985f2253a687ef377cde3dcfb1f788830d1bc09 diff --git a/hermes/hermes.ino b/hermes/hermes.ino index 5476444..5a6789c 100644 --- a/hermes/hermes.ino +++ b/hermes/hermes.ino @@ -21,7 +21,7 @@ // Raising this raises the vector magnitude needed to reach max (purple), // and thus lowers sensitivity. // Eg: 800 = more sensitive, 1600 = less sensitive -#define HERMES_SENSITIVITY 1600.0 +#define HERMES_SENSITIVITY 3200.0 // Emulate two strips by starting the crawl in the // middle of the strip and crawling both ways. #define ENABLE_SPLIT_STRIP 1 @@ -48,8 +48,6 @@ // Accel imports. #include #include - -// Our custom data type. #include "AccelReading.h" void setup() { @@ -147,9 +145,12 @@ unsigned long lastSignificantMovementTime; // Initialization. void accelSetup() { Serial.println("BEGIN"); + - lsm.begin(); - + // Try to initialise and warn if we couldn't detect the chip + if (!lsm.begin()) { + Serial.println("Unable to initialize the LSM303. Check your wiring!"); + } bufferPosition = 0; // Initialize the full buffer to zero. @@ -351,7 +352,7 @@ bool equalReadings(AccelReading a, AccelReading b) { // color // /////////// -int COLOR_RANGE = 384; +int COLOR_RANGE = 383; uint32_t lastColor; unsigned long lastCrawl; uint32_t lightArray[LED_COUNT]; @@ -386,7 +387,7 @@ void updateLED() { //showColor(scale); if (sleep()) { - breathe(strip); + breathe(); } else { crawlColor(pixelColor); } @@ -481,6 +482,7 @@ void showColor(float scale) { // Takes a scale, from 0.0 to 1.0, indicating progression // through the color rainbow. uint32_t pixelColorForScale(double scale) { + scale = max(min(scale, 1), 0); float brightness = MAX_BRIGHTNESS * (scale + MIN_BRIGHTNESS); int c = COLOR_RANGE * scale; // Intentionally round to an int. @@ -636,7 +638,7 @@ void resetBreathe() { keyframePointer = 0; } -void breathe(Adafruit_NeoPixel strip) { +void breathe() { int numKeyframes = sizeof(KEYFRAMES) - 1; float period = SLEEP_CYCLE_MS / numKeyframes; unsigned long now = millis();