#include const int led = 2; //red led on RGB shield const int accel = 1; //Accelerometer sensor pin //power pin for accelerometer const int accelONOFF = 0; int accelV = 0; //accelerometer Value int previous_accelV = 0; int previous_accelV_high = 0; int previous_accelV_low = 0; void setup() { pinMode(led, OUTPUT); pinMode(accelONOFF, OUTPUT); //Accelerometer pinMode(accel, INPUT); //Accelerometer RFduinoBLE.deviceName = "RFdu"; RFduinoBLE.txPowerLevel = -20; //lowest BLE power // this is the data we want to //appear in the advertisement // (the deviceName length plus the //advertisement length must be <= 18 bytes RFduinoBLE.advertisementData = "motion"; // start the BLE stack RFduinoBLE.begin(); } void loop() { digitalWrite(accelONOFF, HIGH); //turn accelerometer on delay(10); previous_accelV = analogRead(accel); //read sensor digitalWrite(accelONOFF, LOW); //turn accelerometer off RFduino_ULPDelay(1000); //let the RFduino //sleep for 1000ms delay(5); digitalWrite(accelONOFF, HIGH); //turn accelerometer on delay(10); accelV = analogRead(accel); //read sensor digitalWrite(accelONOFF, LOW); //turn accelerometer off //leave some play for inaccuracy previous_accelV_low = previous_accelV - 8; previous_accelV_high = previous_accelV + 8; //compare the previous value to the current if (accelV < previous_accelV_low || accelV > previous_accelV_high) { while(1) { digitalWrite(led, HIGH); RFduinoBLE.send(1); delay(50); digitalWrite(led, LOW); RFduinoBLE.send(0); delay(50); } } } void RFduinoBLE_onDisconnect() { // don't leave the led on if they disconnect digitalWrite(led, LOW); }