#include "etherShield.h" #include "ETHER_28J60.h" static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; static uint8_t ip[4] = {10, 10, 0, 115}; static uint16_t port = 80; ETHER_28J60 e; int AC_pin = 10; //Pin to MOC3020 - OptoTriac byte dim = 0; //Initial brightness level from 0 to 255, change as you like! void setup() { Serial.begin(9600); pinMode(AC_pin, OUTPUT); attachInterrupt(0, light, FALLING);//When arduino Pin 2 is FALLING from HIGH to LOW, run light procedure! e.setup(mac, ip, port); } void light() { if (Serial.available()) { dim = Serial.read(); new_triac_value(); } if (dim > 0 && dim < 255) { //Dimming part, if dim is not 0 and not 255 delayMicroseconds(34*(255-dim)); triac_on(); delayMicroseconds(500); triac_off(); } } void new_triac_value() { if (dim < 1) { //Turn TRIAC completly OFF if dim is 0 triac_off(); } if (dim > 254) { //Turn TRIAC completly ON if dim is 255 triac_on(); } } void triac_off() { digitalWrite(AC_pin, LOW); } void triac_on() { digitalWrite(AC_pin, HIGH); } void loop() { char* params; String ndim; if (params = e.serviceRequest()) { if (strstr(params, "?dim=") != 0) { ndim = String(params); ndim.replace("?dim=",""); dim = ndim.toInt(); new_triac_value(); } e.print("

DIM level: "); e.print(dim); e.print("


"); e.respond(); } }