#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <Adafruit_NeoPixel.h>
/* Set the delay between fresh samples */
#define BNO055_SAMPLERATE_DELAY_MS (10)
Adafruit_BNO055 bno = Adafruit_BNO055();
Adafruit_NeoPixel ring = Adafruit_NeoPixel(12, 6, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, 9, NEO_GRB + NEO_KHZ800);
int z;
int bright = 255;
unsigned long time;
void setup(void) {
Serial.begin(9600);
Serial.println("Orientation Sensor Raw Data Test"); Serial.println("");
/* Initialise the sensor */
if(!bno.begin())
{
/* There was a problem detecting the BNO055 ... check your connections */
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
while(1);
}
delay(1000);
bno.setExtCrystalUse(true);
Serial.println("Calibration status values: 0=uncalibrated, 3=fully calibrated");
ring.begin();
strip.begin();
ring.show(); // Initialize all pixels to 'off'
strip.show(); // Initialize all pixels to 'off'
ring.setBrightness(bright);
strip.setBrightness(bright);
}
/**************************************************************************/
/*
Arduino loop function, called once 'setup' is complete (your own code
should go here)
*/
/**************************************************************************/
void loop(void) {
/* Get a new sensor event */
sensors_event_t event;
bno.getEvent(&event);
z = event.orientation.z;
/* Display the floating point data Z*/
Serial.print("\tZ: ");
Serial.println(z);
if(abs(z) > 130){
time = millis();
strip.clear();
strip.show();
for(uint16_t i=0; i<ring.numPixels(); i++) {
ring.setPixelColor(i, ring.Color(255, 0, 0));
}
ring.show();
//手のひら赤く点灯
while(millis() - time < 4000){
Serial.println("RED Light");
bno.getEvent(&event);
z = event.orientation.z;
if(abs(z) < 130){
break;
}
}
//手のひら赤く点滅
while(abs(z) > 130){
Serial.println("RED Flash");
for(uint16_t i=0; i<ring.numPixels(); i++) {
ring.setPixelColor(i, ring.Color(255, 0, 0));
}
ring.show();
delay(50);
ring.clear();
ring.show();
delay(50);
bno.getEvent(&event);
z = event.orientation.z;
}
}else{
ring.clear();
ring.show();
//指先 緑点灯
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(0, 255, 0));
}
strip.show();
}
delay(BNO055_SAMPLERATE_DELAY_MS);
}