Teensy Prop Shield : Motion activated Light This demo shows a basic gesture controlled light sequence using NXP motion sensors available in the Teensy Prop Shield LED lights can be found on the following link: https://www.adafruit.com/product/2238 <script src="https://players.brightcove.net/6153537070001/default_default/index.min.js"></script>(view in My Videos) Features The Teensy Prop Shield is an add-on sensor shield board for the Teensy 3.1 which is an USB based microcontroller development platform. The Teensy 3.1 has a 32 bit ARM Cortex M4 processor from NXP -MK20DX256. The board can be programmed using Arduino IDE + Teensyduino plugin. The prop shield consists of the following devices: Motion Sensors - Allows motion interactive light & sound. Audio Amplifier - Clear quality audio output to a small speaker. Fast LED Driver - Drive APA102 / Dotstar LEDs for colorful lighting with rapid response. Flash Memory - 8 Mbyte storage for images, sound clips, and data logging\ Featured NXP products FXOS8700CQ - 6 Axis Linear Accelerometer & Magnetometer FXAS21002C - 3 Axis Digital Angular Rate Gyroscope MPL3115A2 - Precision Pressure/Altitude & Temperature sensor MK20DX256 - 32 bit ARM Cortex M4 processor Demo Setup: Wiring[1] : Software: After setup, Download Arduino IDE and Teensyduino add on and follow the instructions as defined in the page below http://www.pjrc.com/teensy/td_download.html Note: Arduino version used for this demo: 1.6.8. Run the “Teensy_RGB_Led_Strip.ino” sketch attached. Sample Code: // Full orientation sensing using NXP's advanced sensor fusion algorithm. // // You *must* perform a magnetic calibration before this code will work. // // To view this data, use the Arduino Serial Monitor to watch the // scrolling angles, or run the OrientationVisualiser example in Processing. #include <NXPMotionSense.h> #include <Wire.h> #include <EEPROM.h> #include <FastLED.h> #define NUM_LEDS 60 CRGB leds[NUM_LEDS]; NXPMotionSense imu; NXPSensorFusion filter; int a; int acc_rms; void setup() { Serial.begin(9600); imu.begin(); filter.begin(100); delay(2000); FastLED.addLeds<APA102,11,13,BGR,DATA_RATE_MHZ(1)>(leds, NUM_LEDS); pinMode(7, OUTPUT); digitalWrite(7, HIGH); // enable access to LEDs } void loop() { float ax, ay, az; float gx, gy, gz; float mx, my, mz; float roll, pitch, heading; if (imu.available()) { // Read the motion sensors imu.readMotionSensor(ax, ay, az, gx, gy, gz, mx, my, mz); // Update the SensorFusion filter filter.update(gx, gy, gz, ax, ay, az, mx, my, mz); // print the heading, pitch and roll roll = filter.getRoll(); pitch = filter.getPitch(); heading = filter.getYaw(); Serial.print("Orientation: "); Serial.print(heading); Serial.print(" "); Serial.print(pitch); Serial.print(" "); Serial.println(roll); a=abs(roll/3); Serial.print(" "); acc_rms=sqrt(ax*ax+ay*ay+az*az)/3; Serial.println(acc_rms); //flash red if a violent shake event is detected if(acc_rms==1) { for(int n = 0; n < NUM_LEDS; n++) { leds[n] = CRGB::Red; FastLED.show(); delay(8); leds[n] = CRGB::Black; } } // Move a single white led as per rotation for(int n = 0; n < NUM_LEDS; n++) { if(a==n) { leds[n] = CRGB::White; FastLED.show(); delay(8); } else { leds[n] = CRGB::Black; } } } } PJRC Store Sample Code: // Full orientation sensing using NXP's advanced sensor fusion algorithm. // // You *must* perform a magnetic calibration before this code will work. // // To view this data, use the Arduino Serial Monitor to watch the // scrolling angles, or run the OrientationVisualiser example in Processing. #include <NXPMotionSense.h> #include <Wire.h> #include <EEPROM.h> #include <FastLED.h> #define NUM_LEDS 60 CRGB leds[NUM_LEDS]; NXPMotionSense imu; NXPSensorFusion filter; int a; int acc_rms; void setup() { Serial.begin(9600); imu.begin(); filter.begin(100); delay(2000); FastLED.addLeds<APA102,11,13,BGR,DATA_RATE_MHZ(1)>(leds, NUM_LEDS); pinMode(7, OUTPUT); digitalWrite(7, HIGH); // enable access to LEDs } void loop() { float ax, ay, az; float gx, gy, gz; float mx, my, mz; float roll, pitch, heading; if (imu.available()) { // Read the motion sensors imu.readMotionSensor(ax, ay, az, gx, gy, gz, mx, my, mz); // Update the SensorFusion filter filter.update(gx, gy, gz, ax, ay, az, mx, my, mz); // print the heading, pitch and roll roll = filter.getRoll(); pitch = filter.getPitch(); heading = filter.getYaw(); Serial.print("Orientation: "); Serial.print(heading); Serial.print(" "); Serial.print(pitch); Serial.print(" "); Serial.println(roll); a=abs(roll/3); Serial.print(" "); acc_rms=sqrt(ax*ax+ay*ay+az*az)/3; Serial.println(acc_rms); //flash red if a violent shake event is detected if(acc_rms==1) { for(int n = 0; n < NUM_LEDS; n++) { leds[n] = CRGB::Red; FastLED.show(); delay(8); leds[n] = CRGB::Black; } } // Move a single white led as per rotation for(int n = 0; n < NUM_LEDS; n++) { if(a==n) { leds[n] = CRGB::White; FastLED.show(); delay(8); } else { leds[n] = CRGB::Black; } } } }
記事全体を表示