Created
January 15, 2012 05:03
-
-
Save patrickdevivo/1614424 to your computer and use it in GitHub Desktop.
Turns an LED on whenever I receive a Facebook notification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int ledPin = 9; // the pin that the LED is attached to | |
void setup() | |
{ | |
// initialize the serial communication: | |
Serial.begin(9600); | |
// initialize the ledPin as an output: | |
pinMode(ledPin, OUTPUT); | |
} | |
void loop() { | |
byte led; | |
// check if data has been sent from the computer: | |
if (Serial.available()) { | |
// read the most recent byte (which will be from 0 to 255): | |
led = Serial.read(); | |
// set the brightness of the LED: | |
analogWrite(ledPin, led); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.serial.*; | |
import com.francisli.processing.http.*; | |
//import org.json.*; | |
Serial port; | |
HttpClient client; | |
String fb_id = "625620074"; | |
String fb_access_token = ""; | |
String fb_path = "/" + fb_id + "/notifications/?access_token=" + fb_access_token; | |
void setup() { | |
client = new HttpClient(this, "graph.facebook.com"); | |
client.useSSL = true; | |
println("Available serial ports:"); | |
println(Serial.list()); | |
// Uses the first port in this list (number 0). Change this to | |
// select the port corresponding to your Arduino board. The last | |
// parameter (e.g. 9600) is the speed of the communication. It | |
// has to correspond to the value passed to Serial.begin() in your | |
// Arduino sketch. | |
port = new Serial(this, Serial.list()[0], 9600); | |
// If you know the name of the port used by the Arduino board, you | |
// can specify it directly like this. | |
//port = new Serial(this, "COM1", 9600); | |
loop(); | |
} | |
void responseReceived(HttpRequest request, HttpResponse response) { | |
//// check for HTTP 200 success code | |
if (response.statusCode == 200) { | |
JSONObject results = response.getContentAsJSONObject().get("data"); | |
if (results.size() >= 1) { | |
port.write(255); | |
} | |
else { | |
port.write(0); | |
} | |
} | |
else { | |
//// output the entire response | |
println(response.getContentAsString()); | |
} | |
} | |
void draw() { | |
client.GET(fb_path); | |
delay(5*1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment