//**************************************************************// // Name : DaisyShift - Daisy Chain Shift Register display // using Arduino Ethernet // Author : Will Bradley // Date : 18 Feb, 2012 // Version : 1.0 // Notes : Outputs HTTP data to 74HC595 shift registers // Based on ShiftOut and WebClient examples from Arduino // URL : http://zyphon.com/daisyshift //**************************************************************** #include #include // Variables you should change based on preferences int updateFrequency = 30; // in seconds int numrows = 2; // number of shift registers in the daisy chain // Enter a MAC address and IP address info for your Arduino below. // These values will change based on your network. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xAC, 0xB3 }; byte ip[] = { 192,168,1,222 }; byte subnet[] = { 255,255,255,0 }; byte gateway[] = { 192,168,1,1 }; // Enter the IP address of the web server to query. byte server[] = { 192,168,1,100 }; //Pin connected to ST_CP of 74HC595 int latchPin = 6; //Pin connected to SH_CP of 74HC595 int clockPin = 5; ////Pin connected to DS of 74HC595 int dataPin = 7; // Runtime variables -- no need to change long updateTime = 0; // just a counter String httpresponse = ""; // for storing server responses // Initialize the Ethernet client library Client client(server, 80); void setup() { //set pins to output so you can control the shift register pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); // start the Ethernet connection: Ethernet.begin(mac, ip, gateway, subnet); // start the serial library: Serial.begin(9600); // give the Ethernet shield a second to initialize: delay(1000); // flash LEDs to indicate initialization displayData(0); displayData(0); delay(100); displayData(255); displayData(255); delay(100); displayData(0); displayData(0); delay(100); displayData(255); displayData(255); delay(100); displayData(0); displayData(0); } void displayData(int numberToDisplay) { // take the latchPin low so // the LEDs don't change while you're sending in bits: digitalWrite(latchPin, LOW); // shift out the bits: shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay); //take the latch pin high so the LEDs will light up: digitalWrite(latchPin, HIGH); // pause before next value: delay(1); } // Function that prints data from the server void printData(char* data, int len) { Serial.print("Printing "); Serial.print(data); Serial.print(" with a length of "); Serial.println(len); String matrix; digitalWrite(latchPin, LOW); // start writing to LEDs // Print the data returned by the server // Note that the data is not null-terminated, may be broken up into smaller packets, and // includes the HTTP header. for(int i=0;i0) { Serial.println("Parse!"); int a = httpresponse.indexOf('^'); int b = httpresponse.indexOf('$'); String data = httpresponse.substring(a,b); Serial.println(data); char charData[50]; data.toCharArray(charData, sizeof(charData)); Serial.println(charData); printData(charData, strlen(charData)); httpresponse = ""; } // if the server's disconnected, stop the client: if (!client.connected()) { client.stop(); } } // end of loop