-
Notifications
You must be signed in to change notification settings - Fork 0
Head LEDs
Take control of MiP's head LEDs.
void writeHeadLEDs(MiPHeadLED led1, MiPHeadLED led2, MiPHeadLED led3, MiPHeadLED led4)
void writeHeadLEDs(const MiPHeadLEDs& headLEDs)
Sets the state of the four eye LEDs on MiP's head.
- led1 sets the state of led1 on MiP's head. Valid states are MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST.
- led2 sets the state of led2 on MiP's head. Valid states are MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST.
- led3 sets the state of led3 on MiP's head. Valid states are MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST.
- led4 sets the state of led4 on MiP's head. Valid states are MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST.
- headLEDs is an object which contains led1, led2, led3, and led4 fields for setting the state of all 4 LEDs.
class MiPHeadLEDs
{
public:
// ...
MiPHeadLED led1;
MiPHeadLED led2;
MiPHeadLED led3;
MiPHeadLED led4;
};
Nothing
- The four head LEDs are numbered from left to right, with led1 being the leftmost and led4 being the rightmost.
#include <mip_esp8266.h>
MiP mip;
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial1.println(F("Failed connecting to MiP!"));
return;
}
Serial1.println(F("HeadLEDs.ino - Use head LED functions. Should set each head LED to different state."));
mip.writeHeadLEDs(MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST);
MiPHeadLEDs headLEDs;
mip.readHeadLEDs(headLEDs);
Serial1.println(F("Head LEDs"));
Serial1.print(F(" led1: "));
printLEDString(headLEDs.led1);
Serial1.print(F(" led2: "));
printLEDString(headLEDs.led2);
Serial1.print(F(" led3: "));
printLEDString(headLEDs.led3);
Serial1.print(F(" led4: "));
printLEDString(headLEDs.led4);
delay(4000);
// Turn all the LEDs back on now.
Serial1.println(F("Turning all eye LEDs back on now."));
headLEDs.led1 = headLEDs.led2 = headLEDs.led3 = headLEDs.led4 = MIP_HEAD_LED_ON;
mip.writeHeadLEDs(headLEDs);
// Attempt to run through the same sequence of head LED changes using the
// unverifiedWriteHeadLEDs() functions which don't always get accepted by MiP.
Serial1.println(F("Trying to set each head LED to a different state."));
mip.unverifiedWriteHeadLEDs(MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST);
delay(4000);
Serial1.println(F("Trying to set all eye LEDs back on now."));
headLEDs.led1 = headLEDs.led2 = headLEDs.led3 = headLEDs.led4 = MIP_HEAD_LED_ON;
mip.unverifiedWriteHeadLEDs(headLEDs);
Serial1.println();
Serial1.println(F("Sample done."));
}
static void printLEDString(MiPHeadLED led) {
switch (led) {
case MIP_HEAD_LED_OFF:
Serial1.println(F("Off"));
break;
case MIP_HEAD_LED_ON:
Serial1.println(F("On"));
break;
case MIP_HEAD_LED_BLINK_SLOW:
Serial1.println(F("Blink Slow"));
break;
case MIP_HEAD_LED_BLINK_FAST:
Serial1.println(F("Blink Fast"));
break;
default:
Serial1.println();
break;
}
}
void loop() {
}
void unverifiedWriteHeadLEDs(MiPHeadLED led1, MiPHeadLED led2, MiPHeadLED led3, MiPHeadLED led4)
void unverifiedWriteHeadLEDs(const MiPHeadLEDs& headLEDs)
Sets the state of the four eye LEDs on MiP's head. These functions operate similarly to the writeHeadLEDs() functions except that these are faster since they don't bother to verify that MiP actually sets the LED state as requested. Typically you would want to use the writeHeadLEDs() functions but these unverified ones can be useful when you are calling them several times per second so that a missed LED state update won't be noticed by the user.
- led1 sets the state of led1 on MiP's head. Valid states are MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST.
- led2 sets the state of led2 on the MiP robot's head. Valid states are MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST.
- led3 sets the state of led3 on the MiP robot's head. Valid states are MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST.
- led4 sets the state of led4 on the MiP robot's head. Valid states are MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST.
- headLEDs is an object which contains led1, led2, led3, and led4 fields for setting the state of all 4 LEDs.
class MiPHeadLEDs
{
public:
// ...
MiPHeadLED led1;
MiPHeadLED led2;
MiPHeadLED led3;
MiPHeadLED led4;
};
Nothing
- The 4 head LEDs are numbered from left to right, with led1 being the leftmost and led4 being the rightmost.
#include <mip_esp8266.h>
MiP mip;
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial1.println(F("Failed connecting to MiP!"));
return;
}
Serial1.println(F("HeadLEDs.ino - Use head LED functions. Should set each head LED to different state."));
mip.writeHeadLEDs(MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST);
MiPHeadLEDs headLEDs;
mip.readHeadLEDs(headLEDs);
Serial1.println(F("Head LEDs"));
Serial1.print(F(" led1: "));
printLEDString(headLEDs.led1);
Serial1.print(F(" led2: "));
printLEDString(headLEDs.led2);
Serial1.print(F(" led3: "));
printLEDString(headLEDs.led3);
Serial1.print(F(" led4: "));
printLEDString(headLEDs.led4);
delay(4000);
// Turn all the LEDs back on now.
Serial1.println(F("Turning all eye LEDs back on now."));
headLEDs.led1 = headLEDs.led2 = headLEDs.led3 = headLEDs.led4 = MIP_HEAD_LED_ON;
mip.writeHeadLEDs(headLEDs);
delay(1000);
// Attempt to run through the same sequence of head LED changes using the
// unverifiedWriteHeadLEDs() functions which don't always get accepted by MiP.
Serial1.println(F("Trying to set each head LED to a different state."));
mip.unverifiedWriteHeadLEDs(MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST);
delay(4000);
Serial1.println(F("Trying to set all eye LEDs back on now."));
headLEDs.led1 = headLEDs.led2 = headLEDs.led3 = headLEDs.led4 = MIP_HEAD_LED_ON;
mip.unverifiedWriteHeadLEDs(headLEDs);
Serial1.println();
Serial1.println(F("Sample done."));
}
static void printLEDString(MiPHeadLED led) {
switch (led) {
case MIP_HEAD_LED_OFF:
Serial1.println(F("Off"));
break;
case MIP_HEAD_LED_ON:
Serial1.println(F("On"));
break;
case MIP_HEAD_LED_BLINK_SLOW:
Serial1.println(F("Blink Slow"));
break;
case MIP_HEAD_LED_BLINK_FAST:
Serial1.println(F("Blink Fast"));
break;
default:
Serial1.println();
break;
}
}
void loop() {
}
void readHeadLEDs(MiPHeadLEDs& headLEDs)
Reads the current setting for MiP's four head LEDs.
- headLEDs is an object which contains led1, led2, led3, and led4 fields to be filled in with the current state of all 4 LEDs.
class MiPHeadLEDs
{
public:
// ...
MiPHeadLED led1;
MiPHeadLED led2;
MiPHeadLED led3;
MiPHeadLED led4;
};
Nothing
- The 4 head LEDs are numbered from left to right, with led1 being the leftmost and led4 being the rightmost.
#include <mip_esp8266.h>
MiP mip;
void setup() {
bool connectResult = mip.begin();
if (!connectResult) {
Serial1.println(F("Failed connecting to MiP!"));
return;
}
Serial1.println(F("HeadLEDs.ino - Use head LED functions. Should set each head LED to different state."));
mip.writeHeadLEDs(MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST);
MiPHeadLEDs headLEDs;
mip.readHeadLEDs(headLEDs);
Serial1.println(F("Head LEDs"));
Serial1.print(F(" led1: "));
printLEDString(headLEDs.led1);
Serial1.print(F(" led2: "));
printLEDString(headLEDs.led2);
Serial1.print(F(" led3: "));
printLEDString(headLEDs.led3);
Serial1.print(F(" led4: "));
printLEDString(headLEDs.led4);
delay(4000);
// Turn all the LEDs back on now.
Serial1.println(F("Turning all eye LEDs back on now."));
headLEDs.led1 = headLEDs.led2 = headLEDs.led3 = headLEDs.led4 = MIP_HEAD_LED_ON;
mip.writeHeadLEDs(headLEDs);
// Attempt to run through the same sequence of head LED changes using the
// unverifiedWriteHeadLEDs() functions which don't always get accepted by MiP.
Serial1.println(F("Trying to set each head LED to a different state."));
mip.unverifiedWriteHeadLEDs(MIP_HEAD_LED_OFF, MIP_HEAD_LED_ON, MIP_HEAD_LED_BLINK_SLOW, MIP_HEAD_LED_BLINK_FAST);
delay(4000);
Serial1.println(F("Trying to set all eye LEDs back on now."));
headLEDs.led1 = headLEDs.led2 = headLEDs.led3 = headLEDs.led4 = MIP_HEAD_LED_ON;
mip.unverifiedWriteHeadLEDs(headLEDs);
Serial1.println();
Serial1.println(F("Sample done."));
}
static void printLEDString(MiPHeadLED led) {
switch (led) {
case MIP_HEAD_LED_OFF:
Serial1.println(F("Off"));
break;
case MIP_HEAD_LED_ON:
Serial1.println(F("On"));
break;
case MIP_HEAD_LED_BLINK_SLOW:
Serial1.println(F("Blink Slow"));
break;
case MIP_HEAD_LED_BLINK_FAST:
Serial1.println(F("Blink Fast"));
break;
default:
Serial1.println();
break;
}
}
void loop() {
}