Last active
December 28, 2015 15:56
-
-
Save bmidgley/29747406d0d03b851a1e to your computer and use it in GitHub Desktop.
lightblue bean mouse trap watcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Activate an ibeacon when activity appears on d0 above a threshold | |
I use this to monitor when a mouse enters the live catch trap | |
"iBeacon Locate" app on iOS can alert when an iBeacon comes into range which is how the alert appears | |
https://twitter.com/bmidgley/status/681491360650637314 | |
Major ID is voltage of battery | |
Minor ID is temperature | |
*/ | |
#include <PinChangeInt.h> | |
uint8_t jingles = 0; | |
void setup() | |
{ | |
pinMode( 0, INPUT_PULLUP); | |
Serial.begin(); | |
Bean.enableConfigSave(false); | |
Bean.setBeanName("A100"); | |
attachPinChangeInterrupt(0,startStopAdvertising, CHANGE); | |
} | |
void startStopAdvertising() | |
{ | |
jingles += 1; | |
} | |
void loop() { | |
int temperature; | |
int voltage; | |
int brightness; | |
if(jingles > 64) { | |
temperature = Bean.getTemperature(); | |
voltage = Bean.getBatteryVoltage(); | |
Bean.setBeaconParameters(0xA100, voltage, temperature); | |
Serial.print("Temperature: "); | |
Serial.print(temperature); | |
Serial.println(" C"); | |
Serial.print("Voltage: "); | |
Serial.print(voltage); | |
Serial.println(" v"); | |
Serial.print("bumped: "); | |
Serial.println(jingles); | |
brightness = jingles / 2; | |
if(brightness >= 255) brightness = 255; | |
Bean.setLed(brightness, brightness, brightness); | |
Bean.setBeaconEnable(true); | |
Bean.sleep(10000); | |
} | |
jingles = 0; | |
Bean.sleep(5000); | |
Bean.setLed(0,0,0); | |
Bean.setBeaconEnable(false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment