-
Notifications
You must be signed in to change notification settings - Fork 0
Clap
Interact with and control MiP using claps.
- enableClapEvents()
- disableClapEvents()
- areClapEventsEnabled()
- writeClapDelay()
- readClapDelay()
- availableClapEvents()
- readClapEvent()
void enableClapEvents()
Enable MiP to detect user claps. Once this is enabled, your code can call availableClapEvents() and readClapEvent() to determine when clap events have been detected by MiP.
None
Nothing
- MiP defaults to having the clap detection feature disabled after the ESP8266 attaches.
#include <mip_esp8266.h>
MiP mip;
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("Clap.ino - Use clap related functions."));
Serial.println(F("Calling disableClapEvents()"));
mip.disableClapEvents();
bool isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - fail"));
} else {
Serial.println(F("false - pass"));
}
Serial.println(F("Calling writeClapDelay(501)"));
mip.writeClapDelay(501);
uint16_t delay = mip.readClapDelay();
Serial.print(F("readClapDelay() returns "));
Serial.println(delay);
Serial.println(F("Calling enableClapEvents()"));
mip.enableClapEvents();
isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - pass"));
} else {
Serial.println(F("false - fail"));
}
Serial.println();
Serial.println(F("Waiting for clap events!"));
}
void loop() {
while (mip.availableClapEvents() > 0) {
uint8_t clapCount = mip.readClapEvent();
Serial.print(F("Detected "));
Serial.print(clapCount);
Serial.println(F(" claps"));
}
}
void disableClapEvents()
Disables MiP's ability to detect user claps.
None
Nothing
- MiP defaults to having the clap detection feature disabled after the ESP8266 attaches.
#include <mip.h>
MiP mip;
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("Clap.ino - Use clap related functions."));
Serial.println(F("Calling disableClapEvents()"));
mip.disableClapEvents();
bool isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - fail"));
} else {
Serial.println(F("false - pass"));
}
Serial.println(F("Calling writeClapDelay(501)"));
mip.writeClapDelay(501);
uint16_t delay = mip.readClapDelay();
Serial.print(F("readClapDelay() returns "));
Serial.println(delay);
Serial.println(F("Calling enableClapEvents()"));
mip.enableClapEvents();
isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - pass"));
} else {
Serial.println(F("false - fail"));
}
Serial.println();
Serial.println(F("Waiting for clap events!"));
}
void loop() {
while (mip.availableClapEvents() > 0) {
uint8_t clapCount = mip.readClapEvent();
Serial.print(F("Detected "));
Serial.print(clapCount);
Serial.println(F(" claps"));
}
}
bool areClapEventsEnabled()
Returns whether MiP's clap detection feature is currently enabled.
None
- true if MiP was successfully placed in clap detection mode with a previous call to enableClapEvents().
- false if it is not in clap detection mode.
#include <mip_esp8266.h>
MiP mip;
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("Clap.ino - Use clap related functions."));
Serial.println(F("Calling disableClapEvents()"));
mip.disableClapEvents();
bool isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - fail"));
} else {
Serial.println(F("false - pass"));
}
Serial.println(F("Calling writeClapDelay(501)"));
mip.writeClapDelay(501);
uint16_t delay = mip.readClapDelay();
Serial.print(F("readClapDelay() returns "));
Serial.println(delay);
Serial.println(F("Calling enableClapEvents()"));
mip.enableClapEvents();
isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - pass"));
} else {
Serial.println(F("false - fail"));
}
Serial.println();
Serial.println(F("Waiting for clap events!"));
}
void loop() {
while (mip.availableClapEvents() > 0) {
uint8_t clapCount = mip.readClapEvent();
Serial.print(F("Detected "));
Serial.print(clapCount);
Serial.println(F(" claps"));
}
}
void writeClapDelay(uint16_t delay)
Sets the expected delay between user claps.
- delay is the new delay to be used for clap detection.
Nothing
- I don't know what the units are for this setting. Maybe milliseconds?
- MiP defaults to having the clap delay set to 500 after the application first connects.
#include <mip_esp8266.h>
MiP mip;
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("Clap.ino - Use clap related functions."));
Serial.println(F("Calling disableClapEvents()"));
mip.disableClapEvents();
bool isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - fail"));
} else {
Serial.println(F("false - pass"));
}
Serial.println(F("Calling writeClapDelay(501)"));
mip.writeClapDelay(501);
uint16_t delay = mip.readClapDelay();
Serial.print(F("readClapDelay() returns "));
Serial.println(delay);
Serial.println(F("Calling enableClapEvents()"));
mip.enableClapEvents();
isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - pass"));
} else {
Serial.println(F("false - fail"));
}
Serial.println();
Serial.println(F("Waiting for clap events!"));
}
void loop() {
while (mip.availableClapEvents() > 0) {
uint8_t clapCount = mip.readClapEvent();
Serial.print(F("Detected "));
Serial.print(clapCount);
Serial.println(F(" claps"));
}
}
uint16_t readClapDelay()
Read MiP’s current clap delay.
None
The current setting of the delay expected between claps. It defaults to 500.
#include <mip_esp8266.h>
MiP mip;
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("Clap.ino - Use clap related functions."));
Serial.println(F("Calling disableClapEvents()"));
mip.disableClapEvents();
bool isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - fail"));
} else {
Serial.println(F("false - pass"));
}
Serial.println(F("Calling writeClapDelay(501)"));
mip.writeClapDelay(501);
uint16_t delay = mip.readClapDelay();
Serial.print(F("readClapDelay() returns "));
Serial.println(delay);
Serial.println(F("Calling enableClapEvents()"));
mip.enableClapEvents();
isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - pass"));
} else {
Serial.println(F("false - fail"));
}
Serial.println();
Serial.println(F("Waiting for clap events!"));
}
void loop() {
while (mip.availableClapEvents() > 0) {
uint8_t clapCount = mip.readClapEvent();
Serial.print(F("Detected "));
Serial.print(clapCount);
Serial.println(F(" claps"));
}
}
uint8_t availableClapEvents()
Returns the number of clap detection events that the library currently has sitting in its queue, ready to be read by calling readClapEvent(). MiP must have already been placed in clap detection mode via a call to enableClapEvents() for new clap detection events to be added to this queue.
None
- 0 if there are currently no clap detection events ready for reading. Calling readClapEvent() now would retun 0.
- Non-zero value indicates the number of readClapEvent() calls that can be made and successfully return a valid clap detection event.
- The maximum number of clap detection events that can be queued up between calls to readClapEvent() is 8. If this count is exceeded, the oldest events will be overwritten.
#include <mip_esp8266.h>
MiP mip;
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("Clap.ino - Use clap related functions."));
Serial.println(F("Calling disableClapEvents()"));
mip.disableClapEvents();
bool isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - fail"));
} else {
Serial.println(F("false - pass"));
}
Serial.println(F("Calling writeClapDelay(501)"));
mip.writeClapDelay(501);
uint16_t delay = mip.readClapDelay();
Serial.print(F("readClapDelay() returns "));
Serial.println(delay);
Serial.println(F("Calling enableClapEvents()"));
mip.enableClapEvents();
isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - pass"));
} else {
Serial.println(F("false - fail"));
}
Serial.println();
Serial.println(F("Waiting for clap events!"));
}
void loop() {
while (mip.availableClapEvents() > 0) {
uint8_t clapCount = mip.readClapEvent();
Serial.print(F("Detected "));
Serial.print(clapCount);
Serial.println(F(" claps"));
}
}
uint8_t readClapEvent()
Returns a clap detection event from the library's queue. They will be returned in the order that MiP detected them. MiP must have already been placed in clap detection mode via a call to enableClapEvents() for new clap detection events to be added to this queue.
None
- 0 if the clap detection event queue is empty. availableClapEvents() would return 0 in this scenario.
- The number of claps detected in this event (ie. 2 for a double clap).
- The maximum number of clap detection events that can be queued up between calls to readClapEvent() is 8. If this count is exceeded, the oldest events will be overwritten.
#include <mip_esp8266.h>
MiP mip;
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("Clap.ino - Use clap related functions."));
Serial.println(F("Calling disableClapEvents()"));
mip.disableClapEvents();
bool isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - fail"));
} else {
Serial.println(F("false - pass"));
}
Serial.println(F("Calling writeClapDelay(501)"));
mip.writeClapDelay(501);
uint16_t delay = mip.readClapDelay();
Serial.print(F("readClapDelay() returns "));
Serial.println(delay);
Serial.println(F("Calling enableClapEvents()"));
mip.enableClapEvents();
isEnabled = mip.areClapEventsEnabled();
Serial.print(F("areClapEventsEnabled() returns "));
if (isEnabled) {
Serial.println(F("true - pass"));
} else {
Serial.println(F("false - fail"));
}
Serial.println();
Serial.println(F("Waiting for clap events!"));
}
void loop() {
while (mip.availableClapEvents() > 0) {
uint8_t clapCount = mip.readClapEvent();
Serial.print(F("Detected "));
Serial.print(clapCount);
Serial.println(F(" claps"));
}
}