How to set up your computer:
1. Go to System Preferences -> Click "Sharing" -> Turn on Internet Sharing from Wifi to Ethernet
2. Open the ethernet shield's library -> Open the example to find the IP address of your internet
(the following code is adapted from the internet)
- on the webpage: 0 means its fully on (no resistance); 255 means turned off (full resistance)
** the webpage is : http:// x.x.x.x/rgb (x.x.x.x = IP address)
1. Go to System Preferences -> Click "Sharing" -> Turn on Internet Sharing from Wifi to Ethernet
2. Open the ethernet shield's library -> Open the example to find the IP address of your internet
(the following code is adapted from the internet)
- on the webpage: 0 means its fully on (no resistance); 255 means turned off (full resistance)
** the webpage is : http:// x.x.x.x/rgb (x.x.x.x = IP address)
#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"
static uint8_t mac[6] = { 0x90, 0xA2, 0xDA, 0x0D, 0x9D, 0x80 };
// the digits on the sticker back of the ethernet shield
static uint8_t ip[4] = { 192, 168, 2, 3 };
// the IP address that you found using the example code in the library
#define PREFIX "/rgb"
WebServer webserver(PREFIX, 80);
#define RED_PIN A4
#define GREEN_PIN A1
#define BLUE_PIN A0
int red = 255;
int blue = 255;
int green = 255;
void rgbCmd(WebServer &server, WebServer::ConnectionType type, char *, bool){
if (type == WebServer::POST){
bool repeat;
char name[16], value[16];
do {
repeat = server.readPOSTparam(name, 16, value, 16);
if (strcmp(name, "red") == 0){
red = strtoul(value, NULL, 10);
}
if (strcmp(name, "green") == 0){
green = strtoul(value, NULL, 10);
}
if (strcmp(name, "blue") == 0){
blue = strtoul(value, NULL, 10);
}
} while (repeat);
// after procesing the POST data, tell the web browser to reload
// the page using a GET method.
server.httpSeeOther(PREFIX);
// Serial.print(name);
// Serial.println(value);
return;
}
server.httpSuccess();
if (type == WebServer::GET){
P(message) =
"<!DOCTYPE html><html><head>"
"<meta charset=\"utf-8\"><meta name=\"apple-mobile-web-app-capable\" content=\"yes\" /><meta http-equiv=\"X- UA-Compatible\" content=\"IE=edge,chrome=1\"><meta name=\"viewport\" content=\"width=device-width, user- scalable=no\">"
"<title>Webduino RGB</title>"
"<link rel=\"stylesheet\" href=\"http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css\" />"
"<script src=\"http://code.jquery.com/jquery-1.6.4.min.js\"></script>"
"<script src=\"http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js\"></script>"
"<style> body, .ui-page { background: black; } .ui-body { padding-bottom: 1.5em; } div.ui-slider { width: 88%; }#red, #green, #blue { display: block; margin: 10px; } #red { background: #f00; } #green { background: #0f0; }#blue { background: #00f; } </style>"
"<script>"
"$(document).ready(function(){ $('#red, #green, #blue').slider; $('#red, #green, #blue').bind( 'change', function(event, ui) { jQuery.ajaxSetup({timeout: 110}); var id = $(this).attr('id'); var strength = $(this).val(); if (id == 'red') $.post('/rgb', { red: strength } ); if (id == 'green') $.post('/rgb', { green: strength } ); if (id == 'blue') $.post('/rgb', { blue: strength } ); });});"
"</script>"
"</head>"
"<body>"
"hello" // printed on the first line on the web page
"<div data-role=\"header\" data-position=\"inline\"><h1>Webduino RGB</h1></div>"
"<div \"ui-body ui-body-a\">"
"<input \"range\" name=\"slider\" id=\"red\" value=\"0\" min=\"0\" max=\"255\" />"
"<input \"range\" name=\"slider\" id=\"green\" value=\"0\" min=\"0\" max=\"255\" />"
"<input \"range\" name=\"slider\" id=\"blue\" value=\"0\" min=\"0\" max=\"255\" />"
"</div>"
"</body>"
"</html>";
server.printP(message);
}
}
void setup(){
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
// Serial.begin(9600);
Ethernet.begin(mac, ip);
webserver.setDefaultCommand(&rgbCmd);
webserver.begin();
}
void loop(){
webserver.processConnection();
// Serial.print(red);
// Serial.print(" ");
// Serial.print(green);
// Serial.print(" ");
// Serial.println(blue);
analogWrite(RED_PIN, red);
analogWrite(GREEN_PIN, green);
analogWrite(BLUE_PIN, blue);
}