-
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()
- sendIRDongleCode()
- readIRDongleCode()
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.
-
txPower is the IR transmission power. Valid values are 1 to 120 for about 1-300cm.
Nothing
#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."));
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() {
delay(3000);
uint8_t detectedMiP = 0x00;
// Spend about 10 seconds broadcasting MiP's ID while looking for another MiP.
for (int i = 0; i < 3; i++) {
if (mip.readDetectedMiP(detectedMiP)) {
Serial.print(F("I detected MiP with ID number ")); Serial.println(detectedMiP, HEX);
}
delay(3333);
}
// MiP doesn't want to be found anymore.
mip.disableMiPDetectionMode();
// Verify it and keep looking for other MiPs.
if (mip.isMiPDetectionModeEnabled())
Serial.println(F("Now I can be discovered."));
else
Serial.println(F("I am not discoverable."));
if (mip.readDetectedMiP(detectedMiP)) {
Serial.print(F("I detected MiP with ID number ")); Serial.println(detectedMiP, HEX);
}
}void disableMiPDetectionMode();
Prevents MiP from being discovered by another MiP using IR.
None
Nothing
#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."));
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() {
delay(3000);
uint8_t detectedMiP = 0x00;
// Spend about 10 seconds broadcasting MiP's ID while looking for another MiP.
for (int i = 0; i < 3; i++) {
if (mip.readDetectedMiP(detectedMiP)) {
Serial.print(F("I detected MiP with ID number ")); Serial.println(detectedMiP, HEX);
}
delay(3333);
}
// MiP doesn't want to be found anymore.
mip.disableMiPDetectionMode();
// Verify it and keep looking for other MiPs.
if (mip.isMiPDetectionModeEnabled())
Serial.println(F("Now I can be discovered."));
else
Serial.println(F("I am not discoverable."));
if (mip.readDetectedMiP(detectedMiP)) {
Serial.print(F("I detected MiP with ID number ")); Serial.println(detectedMiP, 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."));
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() {
delay(3000);
uint8_t detectedMiP = 0x00;
// Spend about 10 seconds broadcasting MiP's ID while looking for another MiP.
for (int i = 0; i < 3; i++) {
if (mip.readDetectedMiP(detectedMiP)) {
Serial.print(F("I detected MiP with ID number ")); Serial.println(detectedMiP, HEX);
}
delay(3333);
}
// MiP doesn't want to be found anymore.
mip.disableMiPDetectionMode();
// Verify it and keep looking for other MiPs.
if (mip.isMiPDetectionModeEnabled())
Serial.println(F("Now I can be discovered."));
else
Serial.println(F("I am not discoverable."));
if (mip.readDetectedMiP(detectedMiP)) {
Serial.print(F("I detected MiP with ID number ")); Serial.println(detectedMiP, HEX);
}
}int8_t readDetectedMiP(uint8_t& detectedMiP)
Reads the identification number of a detected MiP.
- detectedMiP contains the identification number of a detected MiP after calling the function.
- 0 if no MiP was detected.
- 1 if a MiP was detected.
#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."));
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() {
delay(3000);
uint8_t detectedMiP = 0x00;
// Spend about 10 seconds broadcasting MiP's ID while looking for another MiP.
for (int i = 0; i < 3; i++) {
if (mip.readDetectedMiP(detectedMiP)) {
Serial.print(F("I detected MiP with ID number ")); Serial.println(detectedMiP, HEX);
}
delay(3333);
}
// MiP doesn't want to be found anymore.
mip.disableMiPDetectionMode();
// Verify it and keep looking for other MiPs.
if (mip.isMiPDetectionModeEnabled())
Serial.println(F("Now I can be discovered."));
else
Serial.println(F("I am not discoverable."));
if (mip.readDetectedMiP(detectedMiP)) {
Serial.print(F("I detected MiP with ID number ")); Serial.println(detectedMiP, HEX);
}
}void sendIRDongleCode(uint8_t sendCode[], uint8_t dataNumbers, uint8_t transmitPower)
Sends code to another MiP using IR. The code to send may be of two, three or four bytes in length.
For two-byte codes any value may be sent, i.e. { 0xNN, 0xNN }.
For three-byte codes the following formats are valid: { 0x00-0x03, 0xNN, 0xNN } or { 0xNN, 0xNN, 0xFF }.
For four-byte codes the following formats are valid: { 0xNN, 0xNN, 0xFF, 0xFF } or { 0x00-0x03, 0x00-0x03, !0xFF, !0xFF }.
- sendCode is a four-byte array containing code to send to another MiP. sendCode[3] is the most significant byte. In sends of two significant bytes, sendCode[2] and sendCode[3] are sent. In sends of three significant bytes, sendCode[1], sendCode[2] and sendCode[3] are sent.
- dataNumbers is the number of bytes to send. Allowable values are 2, 3 or 4.
- txPower is the IR transmission power. Valid values are 1 to 120 for about 1-300cm.
Nothing
#include <mip.h>
// Try different values for VALID_DATA_BYTES (2, 3 or 4)
#define VALID_DATA_BYTES 4
// Try different values for transmission power (0x01 - 0x78)
#define MIP_IR_TX_POWER 0x78
#define MAX_DATA_BYTES 4
MiP mip;
bool connectResult;
// Try different codes for dongleCode[].
const uint8_t dongleCode[4] = { 0xBB, 0x0AB, 0xFF, 0xFF };
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() {
Serial.print(F("Sending "));
for (int i = MAX_DATA_BYTES - VALID_DATA_BYTES; i < MAX_DATA_BYTES; i++) {
Serial.print(dongleCode[i], HEX); Serial.print(F(" "));
}
Serial.println();
mip.sendIRDongleCode(dongleCode, VALID_DATA_BYTES, MIP_IR_TX_POWER);
delay(1000);
}int8_t readIRDongleCode(MiPIRCode& codeEvent)
Reads code sent by another MiP using IR.
- codeEvent is the MiPIRCode object containing the received code after a call to the function.
- MIP_ERROR_NO_EVENT if no transmitted data was found.
- 0 if the data was received.
#include <mip.h>
MiP mip;
uint8_t dongleCode[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
MiPIRCode receiveCode;
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() {
mip.readIRDongleCode(receiveCode);
if (receiveCode.dataNumbers) {
Serial.print(F("Receiving ")); Serial.print(receiveCode.dataNumbers); Serial.println(F(" data numbers."));
for (int i = 0; i < receiveCode.dataNumbers ; i++)
{
Serial.print(receiveCode.code[i], HEX); Serial.print(F(" "));
}
Serial.println();
}
receiveCode.clear();
delay(500);
}🔗 Quick Links: Main Repository • Report an Issue • Wiki Home
An open-source API for the WowWee MiP Robot. Licensed under Apache-2.0.
- MiP
- MiPChestLED
- MiPClapSettings
- MiPDebug
- MiPHardwareInfo
- MiPHeadLEDs
- MiPIRDongleCode
- MiPSoftwareVersion
- MiPStatus
- MiP_Battery
- MiP_ChestLED
- MiP_Clap
- MiP_EEPROM
- MiP_Gesture
- MiP_HeadLEDs
- MiP_Infrared
- MiP_Mode
- MiP_Motion
- MiP_Odometer
- MiP_Position
- MiP_Radar
- MiP_Serial
- MiP_Shake
- MiP_Sound
- MiP_Version
- MiP_Weight
- MiP_WiFi