-
Notifications
You must be signed in to change notification settings - Fork 0
Infrared
MiP's infrared sensors can not only detect obstructions and gestures, they can be used for interacting with other MiPs.
- enableMiPDetectionMode()
- disableMiPDetectionMode()
- isMiPDetectionModeEnabled()
- readDetectedMiP()
- availableDetectedMiPEvents()
- sendIRDongleCode()
- readIRDongleCode()
- availableIRCodeEvents()
void enableMiPDetectionMode(uint8_t id, uint8_t txPower);
Allows MiP to be discovered by another MiP using IR. MiP broadcasts a user-defined identification number for another MiP to read.
- id is the user-defined identification number to send to another MiP. A user-defined value cannot be zero.
- txPower is the IR transmission power. Valid values are 1 to 120 for about 1-300cm.
Nothing
#include <mip_esp8266.h>
MiP mip;
// Load this sketch on a pair of MiPs facing each other and use a different MIP_ID_NO for each.
#define MIP_ID_NO 0x10
#define MIP_IR_TX_POWER 0x78
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("EnableMiPDetectionMode.ino - Enable your MiP to be discovered by another using IR."));
mip.disableMiPDetectionMode();
if (!mip.isMiPDetectionModeEnabled()) {
Serial.println(F("I am not discoverable."));
}
mip.enableMiPDetectionMode(MIP_ID_NO, MIP_IR_TX_POWER);
if (mip.isMiPDetectionModeEnabled()) {
Serial.println(F("Now I can be discovered."));
}
}
void loop() {
if (mip.availableDetectedMiPEvents()) {
Serial.print(F("I detected MiP with ID number ")); Serial.println(mip.readDetectedMiP(), HEX);
}
}
void disableMiPDetectionMode();
Prevents MiP from being discovered by another MiP using IR.
None
Nothing
#include <mip_esp8266.h>
MiP mip;
// Load this sketch on a pair of MiPs facing each other and use a different MIP_ID_NO for each.
#define MIP_ID_NO 0x10
#define MIP_IR_TX_POWER 0x78
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("EnableMiPDetectionMode.ino - Enable your MiP to be discovered by another using IR."));
mip.disableMiPDetectionMode();
if (!mip.isMiPDetectionModeEnabled()) {
Serial.println(F("I am not discoverable."));
}
mip.enableMiPDetectionMode(MIP_ID_NO, MIP_IR_TX_POWER);
if (mip.isMiPDetectionModeEnabled()) {
Serial.println(F("Now I can be discovered."));
}
}
void loop() {
if (mip.availableDetectedMiPEvents()) {
Serial.print(F("I detected MiP with ID number ")); Serial.println(mip.readDetectedMiP(), HEX);
}
}
bool isMiPDetectionModeEnabled()
Checks whether MiP is broadcasting an identification number using IR.
None
- true if MiP is broadcasting its identification number.
#include <mip.h>
MiP mip;
// Load this sketch on a pair of MiPs facing each other and use a different MIP_ID_NO for each.
#define MIP_ID_NO 0x10
#define MIP_IR_TX_POWER 0x78
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("EnableMiPDetectionMode.ino - Enable your MiP to be discovered by another using IR."));
mip.disableMiPDetectionMode();
if (!mip.isMiPDetectionModeEnabled()) {
Serial.println(F("I am not discoverable."));
}
mip.enableMiPDetectionMode(MIP_ID_NO, MIP_IR_TX_POWER);
if (mip.isMiPDetectionModeEnabled()) {
Serial.println(F("Now I can be discovered."));
}
}
void loop() {
if (mip.availableDetectedMiPEvents()) {
Serial.print(F("I detected MiP with ID number ")); Serial.println(mip.readDetectedMiP(), HEX);
}
}
uint8_t readDetectedMiP()
Reads the identification number of a detected MiP.
None
- The identification number of the detected MiP.
Zero is a valid identifier. Call availableIRCodeEvents() before calling readDetectedMiP() to prevent interpreting an empty answer with a MiP with an identification number of zero.
#include <mip_esp8266.h>
MiP mip;
// Load this sketch on a pair of MiPs facing each other and use a different MIP_ID_NO for each.
#define MIP_ID_NO 0x10
#define MIP_IR_TX_POWER 0x78
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("EnableMiPDetectionMode.ino - Enable your MiP to be discovered by another using IR."));
mip.disableMiPDetectionMode();
if (!mip.isMiPDetectionModeEnabled()) {
Serial.println(F("I am not discoverable."));
}
mip.enableMiPDetectionMode(MIP_ID_NO, MIP_IR_TX_POWER);
if (mip.isMiPDetectionModeEnabled()) {
Serial.println(F("Now I can be discovered."));
}
}
void loop() {
if (mip.availableDetectedMiPEvents()) {
Serial.print(F("I detected MiP with ID number ")); Serial.println(mip.readDetectedMiP(), HEX);
}
}
uint8_t availableDetectedMiPEvents()
Provides the number of other MiPs that MiP has detected.
None
- The number of MiPs that MiP has detected.
#include <mip_esp8266.h>
MiP mip;
// Load this sketch on a pair of MiPs facing each other and use a different MIP_ID_NO for each.
#define MIP_ID_NO 0x10
#define MIP_IR_TX_POWER 0x78
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("EnableMiPDetectionMode.ino - Enable your MiP to be discovered by another using IR."));
mip.disableMiPDetectionMode();
if (!mip.isMiPDetectionModeEnabled()) {
Serial.println(F("I am not discoverable."));
}
mip.enableMiPDetectionMode(MIP_ID_NO, MIP_IR_TX_POWER);
if (mip.isMiPDetectionModeEnabled()) {
Serial.println(F("Now I can be discovered."));
}
}
void loop() {
if (mip.availableDetectedMiPEvents()) {
Serial.print(F("I detected MiP with ID number ")); Serial.println(mip.readDetectedMiP(), HEX);
}
}
void sendIRDongleCode(uint16_t sendCode, uint8_t transmitPower)
Sends a two-byte code to another MiP using IR.
- sendCode contains a two-byte code to send to another MiP.
- txPower is the IR transmission power. Valid values are 1 to 120 for about 1-300cm.
Nothing
#include <mip_esp8266.h>
// Try different values for transmission power (0x01 - 0x78)
#define MIP_IR_TX_POWER 0x78
MiP mip;
bool connectResult;
void setup() {
connectResult = mip.begin();
if (!connectResult)
{
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("SendIRDongleCode.ino - Send code to another MiP using IR."));
}
void loop() {
uint16_t dongleCode;
char formattedOutput[14];
// Try different codes for dongleCode.
dongleCode = 0x45;
dongleCode <<= 8;
dongleCode |= 0x67;
sprintf(formattedOutput, "Sending 0x%04X", dongleCode);
Serial.println(formattedOutput);
mip.sendIRDongleCode(dongleCode, MIP_IR_TX_POWER);
delay(1000);
}
uint32_t readIRDongleCode()
Reads code sent by another MiP using IR.
None
- A 32-bit value containing the data received via IR.
- 0 if no data was received.
#include <mip_esp8266.h>
MiP mip;
bool connectResult;
void setup() {
connectResult = mip.begin();
if (!connectResult)
{
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("ReadIRDongleCode.ino - Receive code from another MiP using IR."));
}
void loop() {
uint32_t receiveCode;
if (mip.availableIRCodeEvents()) {
receiveCode = mip.readIRDongleCode();
Serial.print(F("Received "));
Serial.print(((receiveCode >> 28) & 0xFF), HEX);
Serial.print(F(" "));
Serial.print(((receiveCode >> 16) & 0xFF), HEX);
Serial.print(F(" "));
Serial.print(((receiveCode >> 8) & 0xFF), HEX);
Serial.print(F(" "));
Serial.print((receiveCode & 0xFF), HEX);
Serial.println();
}
}
uint8_t availableIRCodeEvents()
Returns the number of IR code events that the library currently has sitting in its queue, ready to be read by calling readIRCodeEvent().
None
- The number of available code events that MiP has detected.
#include <mip_esp8266.h>
MiP mip;
bool connectResult;
void setup() {
connectResult = mip.begin();
if (!connectResult)
{
Serial.println(F("Failed connecting to MiP!"));
return;
}
Serial.println(F("ReadIRDongleCode.ino - Receive code from another MiP using IR."));
}
void loop() {
uint32_t receiveCode;
if (mip.availableIRCodeEvents()) {
receiveCode = mip.readIRDongleCode();
Serial.print(F("Received "));
Serial.print(((receiveCode >> 28) & 0xFF), HEX);
Serial.print(F(" "));
Serial.print(((receiveCode >> 16) & 0xFF), HEX);
Serial.print(F(" "));
Serial.print(((receiveCode >> 8) & 0xFF), HEX);
Serial.print(F(" "));
Serial.print((receiveCode & 0xFF), HEX);
Serial.println();
}
}