Xbox Live Traffic Lights code for Arduino
This file contains 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
/* | |
*** Xbox Live online users to traffic lights *** | |
created 26 July 2012 | |
by Andrew D. Farquharson | |
- Every 5 mins program will check who is online, and turn a red, orange or green light | |
depending on how meany people are online. | |
- This uses the Text Finder Librarys @ http://www.arduino.cc/playground/Code/TextFinder | |
- This users the http://www.xboxleaders.com/ API @ http://www.xboxleaders.com/api/profile/***GamerTag Here***.json to get online status | |
*Note: this will not work if user has online status set to "Friends Only" or "Blocked" | |
Circuit: | |
* Ethernet shield attached to pins 10, 11, 12, 13 | |
*/ | |
#include <SPI.h> | |
#include <Ethernet.h> | |
#include <TextFinder.h> | |
// Enter a MAC address for your controller below. | |
// Newer Ethernet shields have a MAC address printed on a sticker on the shield | |
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; | |
char serverName[] = "xboxleaders.com"; | |
// Initialize the Ethernet client library | |
EthernetClient client; | |
TextFinder finder( client); | |
//gamertags | |
int GamerTag1; | |
int GamerTag2; | |
//gamertags end | |
int usersOnline = 0; | |
int Green = 4; | |
int Orange = 7; | |
int Red = 8; | |
void setup() { | |
pinMode(Green, OUTPUT); | |
pinMode(Orange, OUTPUT); | |
pinMode(Red, OUTPUT); | |
pinMode(meter, OUTPUT); | |
// Open serial communications and wait for port to open: | |
Serial.begin(9600); | |
// start the Ethernet connection: | |
if (Ethernet.begin(mac) == 0) { | |
Serial.println("Failed to configure Ethernet using DHCP"); | |
// no point in carrying on, so do nothing forevermore: | |
while(true); | |
} | |
// give the Ethernet shield a second to initialize: | |
delay(1000); | |
Serial.println("connecting..."); | |
} | |
void loop() | |
{ | |
Serial.println("****** Checking.... ******"); // tell serial user whats going on... | |
client.connect(serverName, 80); | |
Serial.println("Connecting..."); | |
delay(10000); | |
int usersOnline = 0; // reset user count for next pass | |
//=============================user 1 ==================== | |
client.connect(serverName, 80); | |
client.print("GET /api/profile/GamerTag1.json"); | |
client.println(" HTTP/1.1"); | |
client.println("host: xboxleaders.com"); | |
client.println("user-agent: arduino/somethingorother"); | |
client.println(); | |
delay(1500); | |
if (client.connected()) { | |
if(finder.find("IsOnline")){ | |
GamerTag1 = finder.getValue('": '); | |
delay(200); | |
Serial.print("api_check_GamerTag1="); | |
Serial.println(GamerTag1); | |
if (GamerTag1 == 1){ | |
(usersOnline += 1); | |
} | |
} | |
} | |
delay(1000); | |
//===============user 1 end======================= | |
//=============user 2 start=================== | |
client.connect(serverName, 80); | |
client.print("GET /api/profile/GamerTag2.json"); | |
client.println(" HTTP/1.1"); | |
client.println("host: xboxleaders.com"); | |
client.println("user-agent: arduino/somethingorother"); | |
client.println(); | |
delay(1500); | |
if (client.connected()) { | |
if(finder.find("IsOnline")){ | |
GamerTag2 = finder.getValue('": '); | |
delay(200); | |
Serial.print("api_check_GamerTag2="); | |
Serial.println(GamerTag2); | |
if (GamerTag2 == 1){ | |
(usersOnline += 1); | |
} | |
} | |
} | |
delay(1000); | |
///================= end of user 2================== | |
Serial.println(); | |
// ============turn lights on=============== | |
if (usersOnline == 0){ // red light on (no users online) | |
digitalWrite(Green, LOW); | |
digitalWrite(Orange, LOW); | |
digitalWrite(Red, HIGH); | |
Serial.println("******no users online :(******** "); | |
} | |
if (usersOnline == 1){ // Orange light on (One user online) | |
digitalWrite(Red, LOW); | |
digitalWrite(Green, LOW); | |
digitalWrite(Orange, HIGH); | |
Serial.println(" ******Orange light one user online******"); | |
} | |
if (usersOnline >= 2){ // Green on ( if 2 or more users are online - GAME ON!!!) | |
digitalWrite(Red, LOW); | |
digitalWrite(Orange, LOW); | |
digitalWrite(Green, HIGH); | |
Serial.println("******Green light GAME ON!!*******"); | |
Serial.print(" NO. of users Onine: "); | |
Serial.println(usersOnline); | |
} | |
//=================== send user status to serial========== | |
Serial.println(); | |
Serial.print("GamerTag1: "); | |
Serial.println(GamerTag1); | |
Serial.print("GamerTag2: "); | |
Serial.println(GamerTag2); | |
Serial.println(); | |
Serial.print("usersOnine="); | |
Serial.println(usersOnline); | |
Serial.println(); | |
Serial.println("disconnecting..."); | |
Serial.println(); | |
client.stop(); | |
delay(300000); //5 min delay @ 300,000 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment