Duvida programar RTC 3231 Alarme e acender leds/reles hora programada

para configurar o RTC usei o código no Arduíno 1.6 

Agora preciso programar pra acender luzes em horários 

#include <LiquidCrystal.h> //Inclui a biblioteca do LCD
#include <Wire.h>
#include <Time.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <DS1307RTC.h> 

#define ONE_WIRE_BUS 10
#define RELAY13 //pino do rele
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer = { 0x28, 0xDF, 0x63, 0x51, 0x05, 0x00, 0x00, 0xC3 };

// Pinos de comando dos botões do relógio
#define clockSet A0
#define clockUp 9
#define clockDown 8
 
//Estados de Clock
#define stClockRunning 0
#define stSetDay 1
#define stSetMonth 2
#define stSetYear 3
#define stSetHour 4
#define stSetMinute 5
#define stSetSecond 6
int pinorelay13 = 13; 
int stat = stClockRunning;
 
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //configuração dos pinos do lcd
 
void Print(int number)
{
 lcd.print(number/10);
 lcd.print(number%10);
}
 
// Preenchimento do display LCD
void printTime()
{
 lcd.setCursor(2,1); Print(hour());
 lcd.print(":"); Print(minute());
 lcd.print(":"); Print(second());
 lcd.setCursor(3,0); Print(day());
 lcd.print("/"); Print(month());
 lcd.print("/"); Print(year());
 lcd.setCursor(0,0);
 lcd.noCursor(); // Cursor invisível
 lcd.noBlink(); // Efeito blink desligado
 
 if (stat != stClockRunning)
 lcd.print("*");
 else
 lcd.print(" ");
 simbolorelogio();
 lcd.setCursor(0,1);
 lcd.write(3);
 
 switch(stat)
 {
 case stSetDay:
 lcd.setCursor(1,0);
 lcd.print("d ");
 lcd.setCursor(4,0);
 lcd.cursor(); // Cursor visível
 lcd.blink(); // Cursor piscando
 break;
 case stSetMonth:
 lcd.setCursor(1,0);
 lcd.print("m ");
 lcd.setCursor(7,0);
 lcd.cursor(); // Cursor visível
 lcd.blink(); // Cursor piscando
 break;
 case stSetYear:
 lcd.setCursor(1,0);
 lcd.print("a ");
 lcd.setCursor(12,0);
 lcd.cursor(); // Cursor visível
 lcd.blink(); // Cursor piscando
 break;
 case stSetHour:
 lcd.setCursor(1,0);
 lcd.print("h ");
 lcd.setCursor(3,1);
 lcd.cursor(); // Cursor visível
 lcd.blink(); // Cursor piscando
 break;
 case stSetMinute:
 lcd.setCursor(1,0);
 lcd.print("M ");
 lcd.setCursor(6,1);
 lcd.cursor(); // Cursor visível
 lcd.blink(); // Cursor piscando
 break;
 case stSetSecond:
 lcd.setCursor(1,0);
 lcd.print("s ");
 lcd.setCursor(9,1);
 lcd.cursor(); // Cursor visível
 lcd.blink(); // Cursor piscando
 break;
 }
}
 
// Lê pino usando limiar, como um interruptor, isto é,
// interruptor pressionado primeira vez liga, pela segunda vez desliga
int readPinSwitch(int pin, int threshold)
{
 if (digitalRead(pin))
 {
 unsigned long tt = millis();
 while (digitalRead(pin));
 if ((millis() - tt) > threshold)
 return 1;
 else
 return 0;
 }
 else
 return 0;
}
 
//Lê pino usando limiar
int readPin(int pin, int threshold)
{
 if (digitalRead(pin))
 {
 unsigned long tt = millis();
 while ((digitalRead(pin) && (millis() - tt) <= threshold));
 if (digitalRead(pin))
 return 1;
 else
 return 0;
 }
 else
 return 0;
}
 
// obter novo status, se houver
int getStat()
{
 if (readPinSwitch(clockSet,300))
 if (stat == stSetSecond)
 return stClockRunning;
 else
 return stat+1;
 else
 return stat;
}
 
// definir Arduino e tempo do RTC
void setRTCTime(int hour, int minute, int second, int day, int month, int year)
{
// define tempo do Arduino
 setTime(hour,minute,second,day,month,year);
 time_t t = now();
// define tempo do RTC
 RTC.set(t);
}
 
void simbolorelogio()
{
 byte relogio[8] = {
 B00000,
 B01110,
 B10101,
 B10111,
 B10001,
 B01110,
 B00000,
 B00000};
 lcd.createChar(3, relogio); // Cria o caractere personalizado de um relogio
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
lcd.print("Error");
}


else
{
lcd.setCursor(11,1);  
lcd.print(tempC);
lcd.print("");

}

 
void setup()
{
 pinMode(pinorelay13, OUTPUT); //Define o pino como saida
sensors.begin(); 
sensors.setResolution(insideThermometer, 10);
// Start the I2C interface
Wire.begin();
       
// Start the serial interface
Serial.begin(9600);
lcd.begin(16, 2);     
lcd.clear(); // start with a blank screen



 pinMode(clockUp,INPUT); // configura os pinos dos botões como entrada
 pinMode(clockDown,INPUT);
 pinMode(clockSet,INPUT);
 
 lcd.begin(16, 2); // Seta o display para 16 colunas and 2 linhas
 setSyncProvider(RTC.get); // função para obter o tempo do RTC
 if(timeStatus()!= timeSet) // verifica status do RTC e retorna erro
 {
 lcd.setCursor(0,0);
 lcd.print("Erro do RTC:");
 lcd.setCursor(0,1);
 lcd.print("Ajuste o Relogio");
 delay(3000);
 lcd.clear();
 }
}
 
int oldStat = stat;
unsigned long t=millis();
 
void loop()
{
  //Aciona o rele
  digitalWrite(pinorelay13, HIGH); 
  delay(50); //Aguarda 2 Horas
  //Desliga o rele
  digitalWrite(pinorelay13, LOW); 
  delay(50); //Aguarda 5 segundos e reinicia o processo
  sensors.requestTemperatures();

printTemperature(insideThermometer);
lcd.setCursor(17,1);
delay(04/33/20); //
  //Desliga o rele

  delay(04/36/20); //Aguarda 5 segundos   
  
 int value = 0;
 printTime(); // rotina que imprime o tempo no lcd
 delay(100);
 stat=getStat();
 if (stat != oldStat)
 {
 t=millis();
 oldStat = stat;
 }
 else
 if ((stat != stClockRunning) && ((millis() - t) > 30000)) //tempo em milisegundos que o ajuste do relógio ficará disponível para ser alterado
 stat=stClockRunning;
 switch(stat)
 {
 case stClockRunning:
 break;
 case stSetDay:
 // inicializa value
 value=day();
 //si botao UP (para cima) for pressionado
 while(readPin(clockUp,200))
 {
 value++;
 if (value > 31)
 value=1;
 setRTCTime(hour(),minute(),second(),value,month(),year());
 printTime();
 }
 //si botao DOWN (para baixo) for pressionado
 while(readPin(clockDown,200))
 {
 value--;
 if (value < 1)
 value=31;
 setRTCTime(hour(),minute(),second(),value,month(),year());
 printTime();
 }
 break;
// ver comentários em stSetDay
 case stSetMonth:
 value=month();
 while(readPin(clockUp,200))
 {
 value++;
 if (value > 12)
 value=1;
 setRTCTime(hour(),minute(),second(),day(),value,year());
 printTime();
 }
 while(readPin(clockDown,200))
 {
 value--;
 if (value < 1)
 value=12;
 setRTCTime(hour(),minute(),second(),day(),value,year());
 printTime();
 }
 break;
 case stSetYear:
 value=year();
 while(readPin(clockUp,200))
 {
 value++;
 if (value > 2050)
 value=2000;
 setRTCTime(hour(),minute(),second(),day(),month(),value);
 printTime();
 }
 while(readPin(clockDown,200))
 {
 value--;
 if (value < 2000)
 value=2050;
 setRTCTime(hour(),minute(),second(),day(),month(),value);
 printTime();
 }
 break;
 case stSetHour:
 value=hour();
 while(readPin(clockUp,200))
 {
 value++;
 if (value > 23)
 value=0;
 setRTCTime(value,minute(),second(),day(),month(),year());
 printTime();
 }
 while(readPin(clockDown,200))
 {
 value--;
 if (value < 1)
 value=24;
 setRTCTime(value,minute(),second(),day(),month(),year());
 printTime();
 }
 break;
 case stSetMinute:
 value=minute();
 while(readPin(clockUp,200))
 {
 value++;
 if (value > 59)
 value=0;
 setRTCTime(hour(),value,second(),day(),month(),year());
 printTime();
 }
 while(readPin(clockDown,200))
 {
 value--;
 if (value < 0)
 value=59;
 setRTCTime(hour(),value,second(),day(),month(),year());
 printTime();
 }
 break;
 case stSetSecond:
 value=minute();
 while(readPin(clockUp,200))
 {
 value++;
 if (value > 59)
 value=0;
 setRTCTime(hour(),minute(),value,day(),month(),year());
 printTime();
 }
 while(readPin(clockDown,200))
 {
 value--;
 if (value < 0)
 value=59;
 setRTCTime(hour(),minute(),value,day(),month(),year());
 printTime();
 }
 }
 }

Exibições: 2428

Responder esta

Respostas a este tópico

Implemente um if.

Veja este topico, talvez lhe ajude.

http://labdegaragem.com/forum/topics/rtc-despertador-ds1307

Abs.

Cara deu certo, fiz o teste com o led do pin 13 e deu certo programei pra ligar 19:05 e desligar 19:06 segue o código 1, queri anexar ou código e não sei como fazer da muito erro como se possível faço para colocar um código Ethernet pra liga o mesmo pin 13 segue codigo 2 abaixo

Codigo 1

include <DS3231.h>
#include <Wire.h>
int buzzer = 13;

DS3231 Clock;
bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
byte year, month, date, DoW, hour, minute, second;
void setup() {

pinMode (buzzer, OUTPUT);
// Start the I2C interface
Wire.begin();
// VERY IMPORTANT COMMENTS BELOW!!!
// If you want to set the time, change these numbers to the date and time you want to set to, and then upload it to the arduino.
// once you have finished setting the time, comment out the following clock.set functions and then reupload it to the board. Otherwise your clock will reset every time you open the serial monitor.
//Clock.setSecond(05);//Set the second
//Clock.setMinute(58);//Set the minute
//Clock.setHour(17); //Set the hour
//Clock.setDoW(5); //Set the day of the week
//Clock.setDate(16); //Set the date of the month
//Clock.setMonth(10); //Set the month of the year
//Clock.setYear(15); //Set the year (Last two digits of the year)
// Start the serial interface
Serial.begin(9600);
}
void ReadDS3231()
{
int second,minute,hour,date,month,year,temperature;
second=Clock.getSecond();
minute=Clock.getMinute();
hour=Clock.getHour(h12, PM);
date=Clock.getDate();
month=Clock.getMonth(Century);
year=Clock.getYear();

// Definicao do alarme.
if (hour == 19 && minute == 05 && second == 30)//Define a hora de tocar o alarme por 1o segundos
{
digitalWrite (buzzer, HIGH);// Eleva tensao pino 13 para 5V
delay (10000);// Atrasa 50ms
}
if (hour == 19 && minute == 06 && second == 0)//Define a hora de tocar o alarme por 1o segundos
{
digitalWrite (buzzer, LOW); //Abaixa tensao pino 13 para 0V
delay (10000);
}
// if (AHour == 18 && AMinute == 31 && ASecond == 05)//Define a hora de tocar o alarme por 10 segundos
{
// digitalWrite (buzzer, HIGH);// Eleva tensao pino 13 para 5V
// delay (10000);// Atrasa 50ms
}
{
// digitalWrite (buzzer, LOW); //Abaixa tensao pino 13 para 0V
}


temperature=Clock.getTemperature();

Serial.print("20");
Serial.print(year,DEC);
Serial.print('-');
Serial.print(month,DEC);
Serial.print('-');
Serial.print(date,DEC);
Serial.print(' ');
Serial.print(hour,DEC);
Serial.print(':');
Serial.print(minute,DEC);
Serial.print(':');
Serial.print(second,DEC);
Serial.print('\n');
Serial.print("Temperature=");
Serial.print(temperature);
Serial.print('\n');
}
void loop() {ReadDS3231();delay(1000);
// send what's going on to the serial monitor.
// Start with the year
/* Serial.print("2");
if (Century) { // Won't need this for 89 years.
Serial.print("1");
} else {
Serial.print("0");
}
Serial.print(Clock.getYear(), DEC);
Serial.print('-');
// then the month
Serial.print(Clock.getMonth(Century), DEC);
Serial.print('-');
// then the date
Serial.print(Clock.getDate(), DEC);
Serial.print(' ');*/
// and the day of the week
/*Serial.print(Clock.getDoW(), DEC);
Serial.print(' ');*/
// Finally the hour, minute, and second
/*Serial.print(Clock.getHour(h12, PM), DEC);
Serial.print(':');
Serial.print(Clock.getMinute(), DEC);
Serial.print(':');
Serial.print(Clock.getSecond(), DEC);
// Add AM/PM indicator
if (h12) {
if (PM) {
Serial.print(" PM ");
} else {
Serial.print(" AM ");
}
} else {
Serial.print(" 24h ");
}
// Display the temperature
Serial.print("T=");
Serial.print(Clock.getTemperature(), 2);
// Tell whether the time is (likely to be) valid
if (Clock.oscillatorCheck()) {
Serial.print(" O+");
} else {
Serial.print(" O-");
}*/
// Indicate whether an alarm went off
/*if (Clock.checkIfAlarm(1)) {
Serial.print(" A1!");
}
if (Clock.checkIfAlarm(2)) {
Serial.print(" A2!");
}*/
// New line on display
//Serial.print('\n');
// delay(1000);
// Display Alarm 1 information
/* Serial.print("Alarm 1: ");
Clock.getA1Time(ADay, AHour, AMinute, ASecond, ABits, ADy, A12h, Apm);
Serial.print(ADay, DEC);
if (ADy) {
Serial.print(" DoW");
} else {
Serial.print(" Date");
}
Serial.print(' ');
Serial.print(AHour, DEC);
Serial.print(' ');
Serial.print(AMinute, DEC);
Serial.print(' ');
Serial.print(ASecond, DEC);
Serial.print(' ');
if (A12h) {
if (Apm) {
Serial.print('pm ');
} else {
Serial.print('am ');
}
}
if (Clock.checkAlarmEnabled(1)) {
Serial.print("enabled");
}
Serial.print('\n');
// Display Alarm 2 information
Serial.print("Alarm 2: ");
Clock.getA2Time(ADay, AHour, AMinute, ABits, ADy, A12h, Apm);
Serial.print(ADay, DEC);
if (ADy) {
Serial.print(" DoW");
} else {
Serial.print(" Date");
}
Serial.print(' ');
Serial.print(AHour, DEC);
Serial.print(' ');
Serial.print(AMinute, DEC);
Serial.print(' ');
if (A12h) {
if (Apm) {
Serial.print('pm');
} else {
Serial.print('am');
}
}
if (Clock.checkAlarmEnabled(2)) {
Serial.print("enabled");
}*/
/* display alarm bits
Serial.print('\n');
Serial.print('Alarm bits: ');
Serial.print(ABits, DEC);
*/
/*
Serial.print('\n');
Serial.print('\n');
delay(1000);
// Display the time once more as a test of the getTime() function
Clock.getTime(year, month, date, DoW, hour, minute, second);
Serial.print(year, DEC);
Serial.print("/");
Serial.print(month, DEC);
Serial.print("/");
Serial.print(date, DEC);
Serial.print("day of the week :");
Serial.println(DoW, DEC);
Serial.print(hour, DEC);
Serial.print(":");
Serial.print(minute, DEC);
Serial.print(":");
Serial.println(second, DEC);*/

}

codigo 2

#include <SPI.h>
#include <Ethernet.h>
  
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 235 };
     
EthernetServer server(80);
  
String readString;
int Pin = 6;
  
void setup(){
  
  pinMode(Pin, OUTPUT);
  Ethernet.begin(mac, ip);
  server.begin();
}
  
void loop(){
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
  
        if (readString.length() < 100) {
          readString += c;             
        }
 
        if (c == '\n') {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
           
          client.println("<HTML>");
          client.println("<BODY>");
          client.println("<H1>Acende LED</H1>");
          client.println("<hr />");
          client.println("<br />");
           
          client.println("<a href=\"/?ledon\"\">Ligar o led</a>");
          client.println("<a href=\"/?ledoff\"\">Desligar o led</a><br />");   
           
          client.println("</BODY>");
          client.println("</HTML>");
           
          delay(1);
          client.stop();
           
          if(readString.indexOf("?ledon") > 0)
          {
            digitalWrite(Pin, HIGH);
          }
          else {
            if(readString.indexOf("?ledoff") > 0)
            {
              digitalWrite(Pin, LOW);
            }
          }
          readString="";    
        }
      }
    }
  }
}

Desculpe Guilherme,

mas não entendi muito bem seu objetivo, se o que você pretende é juntar um código com outro, mais uma vez desculpe mas não costumo fazer isso.

Trate de explicar detalhadamente o que você quer, qual é seu proposito com seu projeto, esclarecendo isso fica mais fácil dar alguma dica, não da pra entender se você quer que o RTC controle um led via rede, ou se é outra coisa, trate de ser objetivo em sua pretensão em vez de ficar remendando códigos.

Abs.

Preciso de um código onde tenho que acender luzes em horários programados, ex:10:00 as 22:00 também podendo ser acionado por botão, e atualizando o status da lâmpada em qualquer dispositivo na rede celular pc que tmb que também controlara o a luz. Pelo menos 8 reles cada um horário independente.

será controlada pelo horário, pelo botão ou por dispositivo na rede que recebera o estado da lâmpada (acesa ou apagada). se possível com login e senha para acessar a pagina.

grato.

tenho o arduino Mega 2560, Ethernet shild  e o RTC 3231

Bem Guilherme,

O que voce se propõem, ou precisa, é possível, para isso vai ter que unir trabalho, conhecimento, e dedicação, não conheço nada pronto para te indicar, mas estude no site Arduino as maneiras de envio e recebimento de dados via rede, também existem vários tutoriais procurando no Google, eu não me comprometo em colaborar no seu projeto porque não tenho tempo suficiente para isso, mas muitos colegas aqui podem ajudar, e dar dicas.

Link para estudo: https://www.arduino.cc/en/Tutorial/HomePage

Boa sorte!

Abs.

Blz    vou compartilhando o que eu consegui e vc da uma olhada se der tempo

vlw

Deu certo a primeira parte, consegui ligar no horário com o RTC 3231 e pelo navegador com Ethernet shild, Agora falta da uma melhorada no html, e programar pra acionar por um push butom e atualizar o status. 

vlw pelas dicas

#include <DS3231.h>
#include <Wire.h>[
#include <SPI.h>
#include <Ethernet.h>
int buzzer = 13;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 235 };
EthernetServer server(80);
String readString;
int Pin = 13;

DS3231 Clock;
bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
byte year, month, date, DoW, hour, minute, second;


void setup() {
pinMode(Pin, OUTPUT);
Ethernet.begin(mac, ip);
server.begin();

pinMode (buzzer, OUTPUT);
// Start the I2C interface
Wire.begin();
// VERY IMPORTANT COMMENTS BELOW!!!
// If you want to set the time, change these numbers to the date and time you want to set to, and then upload it to the arduino.
// once you have finished setting the time, comment out the following clock.set functions and then reupload it to the board. Otherwise your clock will reset every time you open the serial monitor.
// Clock.setSecond(05);//Set the second
// Clock.setMinute(37);//Set the minute
// Clock.setHour(10); //Set the hour
// Clock.setDoW(7); //Set the day of the week
// Clock.setDate(18); //Set the date of the month
// Clock.setMonth(10); //Set the month of the year
// Clock.setYear(15); //Set the year (Last two digits of the year)
// Start the serial interface
Serial.begin(9600);
}
void ReadDS3231()
{
int second,minute,hour,date,month,year,temperature;
second=Clock.getSecond();
minute=Clock.getMinute();
hour=Clock.getHour(h12, PM);
date=Clock.getDate();
month=Clock.getMonth(Century);
year=Clock.getYear();

// Definicao do alarme.
if (hour == 10 && minute ==39 && second == 0)//Define a hora de tocar o alarme por 1o segundos
{
digitalWrite (buzzer, HIGH);// Eleva tensao pino 13 para 5V
delay (10000);// Atrasa 50ms
}
{
if (hour == 10 && minute == 56 && second == 05)//Define a hora de tocar o alarme por 10 segundos

digitalWrite (buzzer, LOW); //Abaixa tensao pino 13 para 0V
}


temperature=Clock.getTemperature();

Serial.print("20");
Serial.print(year,DEC);
Serial.print('-');
Serial.print(month,DEC);
Serial.print('-');
Serial.print(date,DEC);
Serial.print(' ');
Serial.print(hour,DEC);
Serial.print(':');
Serial.print(minute,DEC);
Serial.print(':');
Serial.print(second,DEC);
Serial.print('\n');
Serial.print("Temperature=");
Serial.print(temperature);
Serial.print('\n');
}
void loop() {ReadDS3231();delay(1000);
// send what's going on to the serial monitor.
// Start with the year
/* Serial.print("2");
if (Century) { // Won't need this for 89 years.
Serial.print("1");
} else {
Serial.print("0");
}
Serial.print(Clock.getYear(), DEC);
Serial.print('-');
// then the month
Serial.print(Clock.getMonth(Century), DEC);
Serial.print('-');
// then the date
Serial.print(Clock.getDate(), DEC);
Serial.print(' ');*/
// and the day of the week
/*Serial.print(Clock.getDoW(), DEC);
Serial.print(' ');*/
// Finally the hour, minute, and second
/*Serial.print(Clock.getHour(h12, PM), DEC);
Serial.print(':');
Serial.print(Clock.getMinute(), DEC);
Serial.print(':');
Serial.print(Clock.getSecond(), DEC);
// Add AM/PM indicator
if (h12) {
if (PM) {
Serial.print(" PM ");
} else {
Serial.print(" AM ");
}
} else {
Serial.print(" 24h ");
}
// Display the temperature
Serial.print("T=");
Serial.print(Clock.getTemperature(), 2);
// Tell whether the time is (likely to be) valid
if (Clock.oscillatorCheck()) {
Serial.print(" O+");
} else {
Serial.print(" O-");
}*/
// Indicate whether an alarm went off
/*if (Clock.checkIfAlarm(1)) {
Serial.print(" A1!");
}
if (Clock.checkIfAlarm(2)) {
Serial.print(" A2!");
}*/
// New line on display
//Serial.print('\n');
// delay(1000);
// Display Alarm 1 information
/* Serial.print("Alarm 1: ");
Clock.getA1Time(ADay, AHour, AMinute, ASecond, ABits, ADy, A12h, Apm);
Serial.print(ADay, DEC);
if (ADy) {
Serial.print(" DoW");
} else {
Serial.print(" Date");
}
Serial.print(' ');
Serial.print(AHour, DEC);
Serial.print(' ');
Serial.print(AMinute, DEC);
Serial.print(' ');
Serial.print(ASecond, DEC);
Serial.print(' ');
if (A12h) {
if (Apm) {
Serial.print('pm ');
} else {
Serial.print('am ');
}
}
if (Clock.checkAlarmEnabled(1)) {
Serial.print("enabled");
}
Serial.print('\n');
// Display Alarm 2 information
Serial.print("Alarm 2: ");
Clock.getA2Time(ADay, AHour, AMinute, ABits, ADy, A12h, Apm);
Serial.print(ADay, DEC);
if (ADy) {
Serial.print(" DoW");
} else {
Serial.print(" Date");
}
Serial.print(' ');
Serial.print(AHour, DEC);
Serial.print(' ');
Serial.print(AMinute, DEC);
Serial.print(' ');
if (A12h) {
if (Apm) {
Serial.print('pm');
} else {
Serial.print('am');
}
}
if (Clock.checkAlarmEnabled(2)) {
Serial.print("enabled");
}*/
/* display alarm bits
Serial.print('\n');
Serial.print('Alarm bits: ');
Serial.print(ABits, DEC);
*/
/*
Serial.print('\n');
Serial.print('\n');
delay(1000);
// Display the time once more as a test of the getTime() function
Clock.getTime(year, month, date, DoW, hour, minute, second);
Serial.print(year, DEC);
Serial.print("/");
Serial.print(month, DEC);
Serial.print("/");
Serial.print(date, DEC);
Serial.print("day of the week :");
Serial.println(DoW, DEC);
Serial.print(hour, DEC);
Serial.print(":");
Serial.print(minute, DEC);
Serial.print(":");
Serial.println(second, DEC);*/

EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

if (readString.length() < 100) {
readString += c;
}

if (c == '\n') {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();

client.println("<HTML>");
client.println("<BODY>");
client.println("<H1>Acende LED</H1>");
client.println("<hr />");
client.println("<br />");

client.println("<a href=\"/?ledon\"\">Ligar o led</a>");
client.println("<a href=\"/?ledoff\"\">Desligar o led</a><br />");

client.println("</BODY>");
client.println("</HTML>");

delay(1);
client.stop();

if(readString.indexOf("?ledon") > 0)
{
digitalWrite(Pin, HIGH);
}
else {
if(readString.indexOf("?ledoff") > 0)
{
digitalWrite(Pin, LOW);
}
}
readString="";
}
}
}
}
}

Que bom!

Abs.

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço