Skip to content

Instantly share code, notes, and snippets.

@jonmarkgo
Created October 4, 2012 18:19
Show Gist options
  • Save jonmarkgo/3835418 to your computer and use it in GitHub Desktop.
Save jonmarkgo/3835418 to your computer and use it in GitHub Desktop.
#include <WiFlyHQ.h>
#include <SoftwareSerial.h>
#include <PusherClient.h>
#include <ColorLCDShield.h>
const char mySSID[] = "myssid"; //use $ to represent spaces in your ssid or passphrase
const char myPassword[] = "a123";
const char pusherKey[] = "mykey";
PusherClient client;
SoftwareSerial wifiSerial(10,12); //we will use these pins for debug output
WiFly wifly;
LCDShield lcd;
void setup() {
wifiSerial.begin(57600);
Serial.begin(9600);
if (!wifly.begin(&Serial, &wifiSerial)) { //start up the serial connection to our wifi, tell the WiFlyHQ lib to use our softwareserial for debug
wifiSerial.println(F("Failed to start wifly"));
wifly.terminal(); //if the wifly fails to start, give us access to a direct serial terminal to the RN-XV
}
if (!wifly.isAssociated()) { //check to see if we are already associated with the network before connecting
wifiSerial.println(F("Joining network"));
if (wifly.join(mySSID, myPassword, true)) { //using the true flag at the end of wifly.join indicates that we are using WPA
wifly.save();
wifiSerial.println(F("Joined wifi network"));
}
else {
wifiSerial.println(F("Failed to join wifi network"));
wifly.terminal();
}
}
else { //if we are already associated with the network
wifiSerial.println(F("Already joined network"));
}
client.setClient(wifly); //initialize the pusher client with our
if(client.connect(pusherKey)) { //connect to our pusher account
client.bind("msg", recMsg); //bind the powersms event to the powerSwitch callback function
client.subscribe("robot_channel"); //subscribe to our pusher channel
}
else { //if we fail to connect, just loop
while(1) {
}
}
lcd.init(PHILLIPS); // Initializes lcd, using an EPSON driver
lcd.contrast(40); // 40's usually a good contrast value
lcd.clear(WHITE); // clear the screen
lcd.setStr("Just say no", 2, 20, SLATE, WHITE);
lcd.setStr("to addition", 110, 20, SLATE, WHITE);
lcd.clear(WHITE); // clear the screen
lcd.setCircle(66, 66, 45, RED); // Circle in the mid, 55 radius
lcd.setCircle(66, 66, 44, RED); // Circle in the mid, 54 radius
lcd.setRect(55, 34, 77, 98, 1, BLACK);
lcd.setRect(34, 55, 98, 77, 1, BLACK);
lcd.setLine(34, 34, 98, 98, RED);
lcd.setLine(33, 34, 97, 98, RED);
lcd.setLine(35, 34, 99, 98, RED);
}
void loop() {
if (client.connected()) {
client.monitor();
}
}
void recMsg(String data) {
String text = client.parseMessageMember("text", data);
char __text[sizeof(text)];
text.toCharArray(__text, sizeof(__text));
//lcd.clear(BLACK);
//lcd.setStr(__text, 0, 0, RED, BLACK);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment