Skip to content

Instantly share code, notes, and snippets.

@evanemolo
Created April 25, 2012 19:37
Show Gist options
  • Save evanemolo/2492675 to your computer and use it in GitHub Desktop.
Save evanemolo/2492675 to your computer and use it in GitHub Desktop.
twitter-stepper
//Twitter-Stepper Test
#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
#include <Stepper.h>
#define STEPS 200
// MAC address and server DNS:
byte mac[] = {
0x90, 0xA2, 0xDA, 0x00, 0x7E, 0xE9 };
char server[] = "twitknit-json-parsing.herokuapp.com";
EthernetClient client;
TextFinder finder (client);
Stepper stepper1(STEPS, 2, 3, 4, 5);
void setup() {
// set stepper speed
stepper1.setSpeed(60);
// start the serial library:
Serial.begin(9600);
// start the ethernet connection:
Ethernet.begin(mac);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing:
while(true);
}
// 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 HTTP GET request
client.println("GET / HTTP/1.0");
client.println("HOST: twitknit-json-parsing.herokuapp.com");
client.println();
} else {
// if connection failed:
Serial.println("connection failed");
}
}
void loop() {
long value = 5;
// if there are incoming bytes available from the server, read them and print them
if (client.available()) {
char c = client.read();
Serial.print(c);
// TextFinder code:
if (finder.find("*") == true) { //find asterisk
long value = finder.getValue(); // get numeric value
Serial.print(value);
Serial.println(" tweets");
}
}
// if the server is disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting");
client.stop();
// do nothing more
while(true);
}
// stepper instructions upon recieving tweets:
stepper1.step(value * 1000);
delay(500);
stepper1.step(value * -1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment