From ee496d47026b5aef87a3cb8c34eec0b8b04eb6b4 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Mon, 29 Oct 2018 07:39:40 +0100 Subject: [PATCH] Added Project --- ArduinoServer2.1/ArduinoServer2.1.ino | 180 ++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 ArduinoServer2.1/ArduinoServer2.1.ino diff --git a/ArduinoServer2.1/ArduinoServer2.1.ino b/ArduinoServer2.1/ArduinoServer2.1.ino new file mode 100644 index 0000000..d647e01 --- /dev/null +++ b/ArduinoServer2.1/ArduinoServer2.1.ino @@ -0,0 +1,180 @@ +#include +#include +#include +#include + +#define relay_pin 2 +#define servo_pin 6 +#define clock_pin 7 +#define data_pin 8 +#define button_pin 3 + +/** + * pin | text + * 2 | light + * 3 | button + * 4 | ethernet? + * 6 | servo audio + * 7 | clock screen + * 8 | data screen + * 10 | ethernet shield + * 11 | ethernet + * 12 | ethernet + * 13 | ethernet + */ + + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +// the router's gateway address: +byte gateway[] = { 10, 0, 0, 1 }; +// the subnet: +byte subnet[] = { 255, 255, 0, 0 }; + +IPAddress ip(10, 3, 1, 1); +EthernetServer server(7979);//protocoll: [a/l][n/f/t/v] -> audio / light , on / off / toggle / toggle var +Servo servo; +TM1637Display display(clock_pin, data_pin); + +boolean audio_ = false;//stadi +boolean light_ = false; + +int pos = 0;//leer klein +int pos_ = 17;//triggered klein + +unsigned long dispon = 0; +boolean isdispon = false; + +void setup() { + disabledisp(); + + pinMode(relay_pin, OUTPUT);//relay + + servo.attach(servo_pin);//servo + servo.write(pos);//reset servo + delay(200); + + // start the Ethernet connection and the server: + Ethernet.begin(mac, ip, gateway, subnet); + server.begin(); +} + + +void loop() { + handle_screen(); + + // listen for incoming clients + EthernetClient client = server.available(); + boolean audio = false; + boolean light = false; + if (client) { + // an http request ends with a blank line + boolean currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + + if(c == 'a')//select audio + audio = true; + else if(c =='l') //select light + light = true; + else if(c == 'n') {//on + if(audio && !audio_) {//turn audio on + toggle_audio(); + } + if(light && !light_) {//turn light on + toggle_light(); + } + //reset + audio = false; + light = false; + }else if(c == 'f') {//off + if(audio && audio_) {//turn audio off + toggle_audio(); + } + if(light && light_) {//turn light off + toggle_light(); + } + audio = false; + light = false; + }else if( c == 't') {//toggle + if(audio) {//togle audio + toggle_audio(); + } + if(light) {//toggle light + toggle_light(); + } + audio = false; + light = false; + }else if(c == 'v') {//toggle var + if(audio) + audio_ = !audio_; + if(light) + light_ = !light_; + audio = false; + light = false; + } else { + //client.print("FAILED"); + } + //client.print("OK"); + //client.flush(); + } + } + // give the client time to receive the data + delay(15); + // close the connection: + client.stop(); + //Ethernet.maintain(); + } +} + + +void handle_screen() { + if(digitalRead(button_pin)) { + dispon = millis(); + } + + + if((millis() - dispon)/1000 < 5) { + //diplay on + if(!isdispon)//falls es noch nicht on ist + enabledisp(); + + + } else { + //display off + if(isdispon)//falls es noch nicht off ist + disabledisp(); + } +} + +void enabledisp() { + //set light + display.setBrightness(0x0f); + dispon = true; +} +void disabledisp() { + //set dark + display.setBrightness(0x00); + dispon = false; +} + +void toggle_audio() { + servo.write(pos_);//kleiner (stereo anlage) + delay(200); + servo.write(pos);//reset kleine + audio_ = !audio_; +} + +void toggle_light() { + light_ = !light_; + if(light_) + digitalWrite(relay_pin, HIGH); + else + digitalWrite(relay_pin, LOW); +} + +