Annoy Me!

I snagged a Ethernet shield for $4.00 and wanted to use it right away. I found some tutorials online to control various devices and decided, just for fun, to make a project that will annoy the heck out of me. Head over to http://projects.mytestbox.org:8002 and see that you can control very bright LEDs.

Unfortunately, the webcam isn’t real time. It updates the picture every two seconds. Also the WS2811 seems to be a bit glitchy, so sometimes there will be incorrect LED colors displayed.

Have fun!

Code after the break.

//simple button GET server code to control servo and arduino pin 5
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html
//for use with W5100 based ethernet shields
//Powering a servo from the arduino usually DOES NOT WORK.
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605
 
#include <SPI.h>
#include <Ethernet.h>
#include <Adafruit_NeoPixel.h>

#define PIN 6
#define NUMPIXELS 12
 


Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);
 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //Mac address of your shield
byte ip[] = { 192, 168, 0, 177 }; // Set the sheild's IP address
byte gateway[] = { 192, 168, 0, 1 }; // Set your gateway IP address
byte subnet[] = { 255, 255, 255, 0 }; //Set your Subnet
EthernetServer server(8002); //Set the port to listen on
 
String readString;
 
void setup(){
 
 pinMode(6, OUTPUT); //PIN to output pixel data to LEDs
 Ethernet.begin(mac, ip, gateway, subnet); //Enable Ethernet
 server.begin();

//Enable Serial to connect via console for debugging
 Serial.begin(9600);
 Serial.println("server LED test 1.0"); 
 pixels.setPixelColor(0,pixels.Color(0,0,0));
 pixels.setPixelColor(1,pixels.Color(0,0,0));
 pixels.setPixelColor(2,pixels.Color(0,0,0));
 pixels.setPixelColor(3,pixels.Color(0,0,0));
 pixels.setPixelColor(4,pixels.Color(0,0,0));
 pixels.setPixelColor(5,pixels.Color(0,0,0));
 pixels.setPixelColor(6,pixels.Color(0,0,0));
 pixels.setPixelColor(7,pixels.Color(0,0,0));
 pixels.setPixelColor(8,pixels.Color(0,0,0));
 pixels.setPixelColor(9,pixels.Color(0,0,0));
 pixels.setPixelColor(10,pixels.Color(0,0,0));
 pixels.setPixelColor(11,pixels.Color(0,0,0)); 
 pixels.show();

}
 
void loop(){
 int r=0;
 int g=0;
 int b=0;
 // Create a client connection
 EthernetClient client = server.available();
 if (client) {
 while (client.connected()) {
 if (client.available()) {
 char c = client.read();
 
 //read char by char HTTP request
 if (readString.length() < 100) {
 
 //store characters to string
 readString += c;
 //Serial.print(c);
 }
 
 //if HTTP request has ended
 if (c == '\n') {
 
 ///////////////
 Serial.println(readString); //print to serial monitor for debuging
 
 client.println("HTTP/1.1 200 OK"); //send new page
 client.println("Content-Type: text/html");
 client.println();
 
 client.println("<HTML>");
 client.println("<HEAD>");
 client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
 client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
 client.println("<TITLE>Annoy Me</TITLE>");
 client.println("</HEAD>");
 client.println("<BODY>");
 client.println("<H1>Annoy Me</H1><p>This controls 36 bright LEDs aimed at my face.");
 client.println("<hr />");
 client.println("<br />");
 
 client.println("<a href=\"/?1\"\">Red</a>");
 client.println("<a href=\"/?2\"\">Green</a>");
 client.println("<a href=\"/?3\"\">Blue</a>");
 client.println("<a href=\"/?4\"\">White</a>");
 client.println("<a href=\"/?5\"\">Random</a>"); 
 client.println("<a href=\"/?0\"\">Off</a><br />"); 
 client.println("<br><br>");
 client.println("<img src=\"http://projects.mytestbox.org/webcam/webcam/Webcam.jpg\">");
 client.println("</BODY>");
 client.println("</HTML>");
 
 delay(1);
 client.stop();
 
//Read string variable and turn on or off the LEDs
 if(readString.indexOf("?3") >0){
 pixels.setPixelColor(0,pixels.Color(0,0,255));
 pixels.setPixelColor(1,pixels.Color(0,0,255));
 pixels.setPixelColor(2,pixels.Color(0,0,255));
 pixels.setPixelColor(3,pixels.Color(0,0,255));
 pixels.setPixelColor(4,pixels.Color(0,0,255));
 pixels.setPixelColor(5,pixels.Color(0,0,255));
 pixels.setPixelColor(6,pixels.Color(0,0,255));
 pixels.setPixelColor(7,pixels.Color(0,0,255));
 pixels.setPixelColor(8,pixels.Color(0,0,255));
 pixels.setPixelColor(9,pixels.Color(0,0,255));
 pixels.setPixelColor(10,pixels.Color(0,0,255));
 pixels.setPixelColor(11,pixels.Color(0,0,255)); 
 pixels.show();
 Serial.println("Led Blue");
 readString="";
 }else{ 
 if(readString.indexOf("?2") >0){
 pixels.setPixelColor(0,pixels.Color(0,255,0));
 pixels.setPixelColor(1,pixels.Color(0,255,0));
 pixels.setPixelColor(2,pixels.Color(0,255,0));
 pixels.setPixelColor(3,pixels.Color(0,255,0));
 pixels.setPixelColor(4,pixels.Color(0,255,0));
 pixels.setPixelColor(5,pixels.Color(0,255,0));
 pixels.setPixelColor(6,pixels.Color(0,255,0));
 pixels.setPixelColor(7,pixels.Color(0,255,0));
 pixels.setPixelColor(8,pixels.Color(0,255,0));
 pixels.setPixelColor(9,pixels.Color(0,255,0));
 pixels.setPixelColor(10,pixels.Color(0,255,0));
 pixels.setPixelColor(11,pixels.Color(0,255,0)); 
 pixels.show();
 Serial.println("Led Green");
 readString="";
 }else{ 
 if(readString.indexOf("?1") >0){
 pixels.setPixelColor(0,pixels.Color(255,0,0));
 pixels.setPixelColor(1,pixels.Color(255,0,0));
 pixels.setPixelColor(2,pixels.Color(255,0,0));
 pixels.setPixelColor(3,pixels.Color(255,0,0));
 pixels.setPixelColor(4,pixels.Color(255,0,0));
 pixels.setPixelColor(5,pixels.Color(255,0,0));
 pixels.setPixelColor(6,pixels.Color(255,0,0));
 pixels.setPixelColor(7,pixels.Color(255,0,0));
 pixels.setPixelColor(8,pixels.Color(255,0,0));
 pixels.setPixelColor(9,pixels.Color(255,0,0));
 pixels.setPixelColor(10,pixels.Color(255,0,0));
 pixels.setPixelColor(11,pixels.Color(255,0,0)); 
 pixels.show();
 Serial.println("Led Red");
 readString="";
 }else{
 if(readString.indexOf("?4") >0){
 pixels.setPixelColor(0,pixels.Color(255,255,125));
 pixels.setPixelColor(1,pixels.Color(255,255,125));
 pixels.setPixelColor(2,pixels.Color(255,255,125));
 pixels.setPixelColor(3,pixels.Color(255,255,125));
 pixels.setPixelColor(4,pixels.Color(255,255,125));
 pixels.setPixelColor(5,pixels.Color(255,255,125));
 pixels.setPixelColor(6,pixels.Color(255,255,125));
 pixels.setPixelColor(7,pixels.Color(255,255,125));
 pixels.setPixelColor(8,pixels.Color(255,255,125));
 pixels.setPixelColor(9,pixels.Color(255,255,125));
 pixels.setPixelColor(10,pixels.Color(255,255,125));
 pixels.setPixelColor(11,pixels.Color(255,255,125)); 
 pixels.show();
 Serial.println("Led White");
 readString="";
 }else{
 if(readString.indexOf("?5") >0){
 r=random(0,255);
 g=random(0,255);
 b=random(0,255);
 pixels.setPixelColor(0,pixels.Color(r,g,b));
 pixels.setPixelColor(1,pixels.Color(r,g,b));
 pixels.setPixelColor(2,pixels.Color(r,g,b));
 pixels.setPixelColor(3,pixels.Color(r,g,b));
 pixels.setPixelColor(4,pixels.Color(r,g,b));
 pixels.setPixelColor(5,pixels.Color(r,g,b));
 pixels.setPixelColor(6,pixels.Color(r,g,b));
 pixels.setPixelColor(7,pixels.Color(r,g,b));
 pixels.setPixelColor(8,pixels.Color(r,g,b));
 pixels.setPixelColor(9,pixels.Color(r,g,b));
 pixels.setPixelColor(10,pixels.Color(r,g,b));
 pixels.setPixelColor(11,pixels.Color(r,g,b)); 
 pixels.show();
 Serial.println("Led White");
 readString="";
 }else{
 if(readString.indexOf("?0") >0){
 pixels.setPixelColor(0,pixels.Color(0,0,0));
 pixels.setPixelColor(1,pixels.Color(0,0,0));
 pixels.setPixelColor(2,pixels.Color(0,0,0));
 pixels.setPixelColor(3,pixels.Color(0,0,0));
 pixels.setPixelColor(4,pixels.Color(0,0,0));
 pixels.setPixelColor(5,pixels.Color(0,0,0));
 pixels.setPixelColor(6,pixels.Color(0,0,0));
 pixels.setPixelColor(7,pixels.Color(0,0,0));
 pixels.setPixelColor(8,pixels.Color(0,0,0));
 pixels.setPixelColor(9,pixels.Color(0,0,0));
 pixels.setPixelColor(10,pixels.Color(0,0,0));
 pixels.setPixelColor(11,pixels.Color(0,0,0)); 
 pixels.show();
 Serial.println("Led Off");
 readString="";
 }
 }
 readString="";
 
 }
 }
 }
 }
 }
 }
 }
}
}





 

Leave a Reply

Your email address will not be published. Required fields are marked *