Skip to content

Instantly share code, notes, and snippets.

@amcjen
Last active August 29, 2015 14:02
Show Gist options
  • Save amcjen/430f513e1392659c312b to your computer and use it in GitHub Desktop.
Save amcjen/430f513e1392659c312b to your computer and use it in GitHub Desktop.
#include <SPI.h>
#include <Wire.h>
#include <Scout.h>
#include <GS.h>
#include <bitlash.h>
#include <lwm.h>
#include <js0n.h>
extern "C" {
#include "key/key.h"
}
// To change the LED on this Scout, send it a message via HQ or another Scout's Serial Monitor, like the following:
//
// make it green
//
// message.group(2, "0", "255", "0");
//
// make it red
//
// message.group(2, "255", "0", "0")
//
// turn it off
//
// message.group(2, "0", "0", "0")
static numvar handleRGBMessage(void) {
Serial.print("Sent to group ");
Serial.println(getarg(1));
Serial.print("From Scout ID ");
Serial.println(getarg(2));
for (int i=3; i<=getarg(0); i++) {
Serial.print("Argument ");
Serial.print(i);
Serial.print(": ");
Serial.println(keyGet(getarg(i)));
}
uint8_t r, g, b;
r = atoi(keyGet(getarg(3)));
g = atoi(keyGet(getarg(4)));
b = atoi(keyGet(getarg(5)));
Led.setColor(r, g, b);
}
void setup() {
addBitlashFunction("handle.message", (bitlash_function)handleRGBMessage);
doCommand("function on.message.group { handle.message(arg(1), arg(2), arg(3), arg(4), arg(5)) }");
Scout.setup();
}
void loop() {
Scout.loop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment