// CowJam's Physical Counter // 22 May 2010 #include #include Servo myservo; int foo; //counter //network setup byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = { 192, 168, 1, 177 }; byte gateway[] = { 192, 168, 1, 1 }; byte subnet[] = { 255, 255, 255, 0 }; byte server[] = { 192, 168, 1, 100 }; //server IP where hazHit.php is found Client client(server, 80); void clickIt() { for (int i = 0; i <= 160; i = i + 10) { myservo.write(i); delay(100); } for (int i = 160; i >= 0; i = i - 10) { myservo.write(i); delay(100); } } boolean getConx() { Ethernet.begin(mac, ip, gateway, subnet); delay(1000); return client.connect(); } boolean hazHit() { while (getConx()==false) { } client.println("GET /hazHit.php HTTP/1.0"); client.println(); foo=0; while (foo<8) { //dump unwanted lines while (client.read() != '\n') { } foo++; } if (client.read() == 'Y') { client.flush(); client.stop(); return true; } else { client.flush(); client.stop(); return false; } } void setup() { myservo.attach(8); myservo.write(0); } void loop() { if (hazHit()==true) { //if there's a hit outstanding clickIt(); //click the counter delay(1000); } else { delay(60000); } }