Hallo.
ich möchte für einen Eiskunstläufer eine Jacke mit LED Beleuchtung basteln.
Ein NeopixelStrip soll am Arm befestigtwerden und über einen Beschleugigungssensor/Gyro/Magnetometer angesteuert werden.
Wenn der Eisläufer den arm mit einen bestimmten Geschwindigkeit bewegt(Wurfbewegung) soll ein Effekt ausgeführt
werden.
Die Farbe des Effekts soll je nach Wurfrichtung(oben,waagerecht,unten) geändert werden.
Habe ein Program geschrieben und das Funktioniert auch (so lala).
Vielleich kann mir jemand ein paar Tips geben oder hat ein Beispielprogram für mich.
Danke im vorraus
Micha
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS0.h>
#include <Adafruit_Sensor.h> // not used in this demo but required!
#include <Adafruit_NeoPixel.h>
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(70, 6, NEO_GRB + NEO_KHZ800);
// i2c
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0();
void setupSensor()
{
// 1.) Set the accelerometer range
lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G);
//lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_4G);
//lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_6G);
//lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_8G);
//lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_16G);
// 2.) Set the magnetometer sensitivity
lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS);
//lsm.setupMag(lsm.LSM9DS0_MAGGAIN_4GAUSS);
//lsm.setupMag(lsm.LSM9DS0_MAGGAIN_8GAUSS);
//lsm.setupMag(lsm.LSM9DS0_MAGGAIN_12GAUSS);
// 3.) Setup the gyroscope
lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS);
//lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_500DPS);
//lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_2000DPS);
}
// lower number = more sensitive
#define MOVE_THRESHOLD 12000
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);
}
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop()
{
// Take a reading of accellerometer data
lsm.read();
// Serial.print("Accel X: "); Serial.print(lsm.accelData.x); Serial.print(" ");
// Serial.print("Y: "); Serial.print(lsm.accelData.y); Serial.print(" ");
// Serial.print("Z: "); Serial.print(lsm.accelData.z); Serial.print(" ");
// Get the magnitude (length) of the 3 axis vector
// http://en.wikipedia.org/wiki/Euclidean_vector#Length
double storedVector = lsm.accelData.x*lsm.accelData.x;
storedVector += lsm.accelData.y*lsm.accelData.y;
storedVector += lsm.accelData.z*lsm.accelData.z;
storedVector = sqrt(storedVector);
//Serial.print("Len: "); Serial.println(storedVector);
// wait a bit
delay(100);
// get new data!
lsm.read();
double newVector = lsm.accelData.x*lsm.accelData.x;
newVector += lsm.accelData.y*lsm.accelData.y;
newVector += lsm.accelData.z*lsm.accelData.z;
newVector = sqrt(newVector);
//Serial.print("New Len: "); Serial.println(newVector);
// are we moving
if (abs(newVector - storedVector) > MOVE_THRESHOLD) {
Serial.println("throw!");
Serial.print("Accel X: "); Serial.print(lsm.accelData.x); Serial.print(" ");
Serial.print("Y: "); Serial.print(lsm.accelData.y); Serial.print(" ");
Serial.print("Z: "); Serial.print(lsm.accelData.z); Serial.print(" ");
Serial.print("New Len: "); Serial.println(newVector);
// colorWipe(strip.Color(0, 0, 255), 50); // Blue
lauflicht(strip.Color(0,0, 255), 20); // Blue
}
}
// Lauflicht in eine Richtung
void lauflicht(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<14; i++) {
strip.setPixelColor(i, c);
strip.setPixelColor(27-i, c);
strip.setPixelColor(28+i, c);
strip.setPixelColor(55-i, c);
strip.setPixelColor(56+i, c);
strip.show();
delay(wait);
strip.setPixelColor(i, 0);
strip.setPixelColor(27-i, 0);
strip.setPixelColor(28+i, 0);
strip.setPixelColor(55-i, 0);
strip.setPixelColor(56+i, 0);
strip.show();
delay(wait);
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
strip.setPixelColor(i, 0);
strip.show();
delay(wait);
}
}