Skip to content

Instantly share code, notes, and snippets.

@yratof
Last active December 28, 2015 09:09
Show Gist options
  • Save yratof/7476759 to your computer and use it in GitHub Desktop.
Save yratof/7476759 to your computer and use it in GitHub Desktop.
Arduino temp + rgb
#include <SPI.h>
#include <Ethernet.h> // Initialize the libraries.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //I left the MAC address and IP address blank.
byte ip[] = { 192, 168, 1, 99 }; // You will want to fill these in with your MAC and IP address.
EthernetServer server(80); // Assigning the port forwarded number. It's almost always 80.
String readString; // We will be using strings to keep track of things.
//Temperature
float temp;
int tempPin = 5;
//RGB
const int redPin = 6;
const int greenPin = 10;
const int bluePin = 9;
//////////////////////
void setup(){
Ethernet.begin(mac, ip);
setColourRgb(0,0,0);
Serial.begin(9600);
}
void loop(){
temp = analogRead(tempPin);
temp = (5.0 * temp * 100.0)/1024.0; //convert the analog data to temperature
Serial.println(temp);
delay(1000);
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) { // This is all where we start up the server and strings.
char c = client.read();
if (readString.length() < 100) {
readString += c;
}
if (c == '\n') {
Serial.println(readString); // And here we begin including the HTML
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html>");
client.println("<head>");
client.println("<meta http-equiv=\"refresh\" content=\"4\">");
client.println("<title>Full Phat Design Studio Temperature</title>");
client.println("<link rel='stylesheet' href='http://fullphatdesign.fullphattest.co.uk/wp-content/themes/Full_Phat/library/css/style.css' type='text/css' media='all' />");
client.println("<style>body{text-align: center; padding: 4em;}</style>");
client.println("</head>");
client.println("<h1>Full Phat Temperature Monitor</h1>");
client.println("<h2 class='bluetext'>");
client.println("Obviously, the temperature is");
client.println(temp);
client.println("&deg;C");
client.println("</h2>");
if (temp > 25){
client.println("<p>you need to go get some ice cream.</p>");
}
if (temp > 20){
client.println("<p>You'll be fine.</p>");
}
if (temp < 19){
client.println("<p>Put a damn jumper on.</p>");
}
client.println("<body>");
client.println("</body>");
client.println("</html>");
delay(1);
readString="";
client.stop(); // End of session.
}
}
}
}
unsigned int rgbColour[3];
// Start off with red.
rgbColour[0] = 255;
rgbColour[1] = 0;
rgbColour[2] = 0;
// Choose the colours to increment and decrement.
for (int decColour = 0; decColour < 3; decColour += 1) {
int incColour = decColour == 2 ? 0 : decColour + 1;
// cross-fade the two colours.
for(int i = 0; i < 255; i += 1) {
rgbColour[decColour] -= 1;
rgbColour[incColour] += 1;
if (temp > 21){
setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
delay(5);
} else {
setColourRgb(0,255,255);
}
}
}
}
void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) {
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment