#include "pitches.h" #include #include #include #include //Servo setup Servo myservo; // create servo object to control a servo int pos = 70; // variable to store the servo position int speakerpin = 3; int servopin = 9; //Ethernet setup // 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 }; // if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: IPAddress server(74,208,26,243); //char server[] = "twitter.com"; // name address for Google (using DNS) char TweetID[64]; String TweetNumber = ""; // Initialize the Ethernet client library // with the IP address and port of the server EthernetClient client; TextFinder finder( client ); void setup() { myservo.attach(servopin); // attaches the servo on pin 11 to the servo object Serial.begin(9600); } void loop() { if(parse_feed()){ Serial.println("Found a homerun!"); //trigger the apple Homerun(); } Serial.println("Waiting 30 seconds..."); delay (30000); } boolean parse_feed(){ // 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: Ethernet.begin(mac); } // give the Ethernet shield a second to initialize: delay(1000); Serial.println("connecting..."); // if you get a connection, report back via serial: if (client.connect(server, 80)) { Serial.println("connected"); // Make a HTTP request: if(TweetNumber==""){ //Use the alt ?User=TEAMNAME to enable this for another team. client.println("GET /index.php HTTP/1.1"); //client.println("GET /index.php?User=Brewers HTTP/1.1"); }else{ String command = "GET /index.php"; command += "?ID="; command += TweetNumber; ////Uncomment the following line to make this work for another team //command += "&User=Brewers"; command += " HTTP/1.1"; client.println(command); } client.println("Host: scores.modhotspot.com"); // client.println("Connection: close"); client.println(); while (client.connected()) { if (client.available()) { if (finder.getString( "
", "
", TweetID, 64)>0){ // Serial.print("\r\nFound tweet \r\n"); TweetNumber = TweetID; Serial.print(TweetID); Serial.print("\r\n"); return true; }else{ //Serial.print("\r\nReturning false \r\n"); return false; } } } } else { // if you didn't get a connection to the server: // Serial.println("connection failed"); } client.stop(); client.flush(); } void Homerun(){ int Meet_the_Mets[] = { NOTE_F4, NOTE_D4, NOTE_F4, REST, NOTE_C4, NOTE_B3, NOTE_AS3, REST, NOTE_F3, NOTE_G3, NOTE_AS3, NOTE_D4, NOTE_F4, NOTE_E4, NOTE_F4, REST, NOTE_D4, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_D4, NOTE_C4, NOTE_AS3, REST, NOTE_G4, NOTE_F4, NOTE_G4, NOTE_D4, NOTE_C4, NOTE_AS3, NOTE_G4, NOTE_F4, NOTE_G4, NOTE_F4 }; int Mets_Notes[] = { 2, 4, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 4, 2, 4, 4, 4, 4, 2, 4, 2 }; const int num_elements_in_arr = sizeof(Mets_Notes)/sizeof(Mets_Notes[0]); // iterate over the notes of the melody: for (int thisNote = 0; thisNote < num_elements_in_arr; thisNote++) { // to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 500/Mets_Notes[thisNote]; tone(speakerpin, Meet_the_Mets[thisNote],noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(speakerpin); if(thisNote % 4 == 0){ ToggleApple(); } } delay(1000); } void ToggleApple(){ if ( pos == 170) { pos = 70; }else{ pos = 170; } myservo.write(pos); }