pingpong2.cpp
Here's a variation on pingpong.cpp. It's nearly the same sketch, except for two changes: When we send
pong, we also light an LED, and, when our button is pushed, we
ping all our neighbors.
const int ledPin = BODY_RGB_GREEN_PIN;
void doPingPong(u8 * packet) {
if (packetScanf(packet,"ping\n") != 5)
return;
facePrintln(packetSource(packet),"pong");
ledOn(ledPin);
}
void setup() {
Body.reflex('p', doPingPong);
}
void loop() {
if (buttonDown()) {
println("ping");
while (buttonDown()) {
delay(10);
}
}
delay(100);
ledOff(ledPin);
}