ADM, uma força aee

Ver o tópico anterior Ver o tópico seguinte Ir em baixo

ADM, uma força aee

Mensagem  SrMion em Dom 13 Jan - 16:09

Estou montando um projeto bacana de alarme inteligente, e estou com algumas ideias para o código, mas enpaquei nessa parte... novato, já viu..
eu quero colocar na função no alarme, quando ele dispara tem uma função de RESET, tipo, ALARME DISPARA - COMANDO (reset) DESATIVA SIRENE delay(20000); ESPERA PRA VER SE NÃO HÁ ATIVIDADE - REINICIA ALARME.

E quero fazer essa função de RESET com um pushbotton fisico e via HTTP.

The Code:




Código:

#include <SPI.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <Udp.h>
#include <EEPROM.h>
#include <LiquidCrystal.h>
//-------------------------------------------------------------
#define BAUD_RATE 9600
#define TERM_CHAR '\n'
#define BUF_LEN        30
//-------------------------------------------------------------
byte mac[]    = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[]      = { 192, 168, 0, 105 };                  // ip in lan
byte gateway[] = { 192, 168, 0, 1 };                    // internet access via router
byte subnet[]  = { 255, 255, 255, 0 };                  //subnet mask
Server server(80);                                      //server port
byte sampledata=50;            //some sample data - outputs 2 (ascii = 50 DEC)

int GazPin        = 8;    // select the input pin for the potentiometer
float sensorGaz  = 0;
int TempPin      = 9;    // select the input pin for the potentiometer
float sensorTemp  = 0;
float Temp        = 0;
int i;
int count=0;
boolean DispAlarme = false;
boolean FlagAlarme = false;
boolean AIMode    = false;
char c;
String readString = String(BUF_LEN); //string for fetching data from address

//-------------------------------------------------------------
int Sensor3          = 10;        // Sensor 3 Pino
int Sensor4          = 11;        // Sensor 4 Pino
int Sensor5          = 12;        // Sensor 5 Pino
int Sensor6          = 13;        // Sensor 6 Pino
int Sensor7          = 14;        // Sensor 7 Pino
int Sensor8          = 15;        // Sensor 8 Pino
int IN_03            =  0;        // Estado do Pino
int IN_04            =  0;        // Estado do Pino
int IN_05            =  0;        // Estado do Pino
int IN_06            =  0;        // Estado do Pino
int IN_07            =  0;        // Estado do Pino
int IN_08            =  0;        // Estado do Pino
//-------------------------------------------------------------
int powerbox1        = 12;      // PowerBox pino
//-------------------------------------------------------------
int ContatoSecoState1 = 0;        // variable for reading the status
int ContatoSecoState2 = 0;        // variable for reading the status
int ContatoSecoState3 = 0;        // variable for reading the status
int ContatoSecoState4 = 0;        // variable for reading the status
int ContatoSecoState5 = 0;        // variable for reading the status
int ContatoSecoState6 = 0;        // variable for reading the status
int ContatoSecoState7 = 0;        // variable for reading the status
int ContatoSecoState8 = 0;        // variable for reading the status

int optoacopladorState1 = 0;        // variable for reading the status
int optoacopladorState2 = 0;        // variable for reading the status


const int relay1 =  22;      // Rele 1 PA0
const int relay2 =  23;      // Rele 2 PA1
const int relay3 =  24;      // Rele 3 PA2
const int relay4 =  25;      // Rele 4 PA3
const int relay5 =  26;      // Rele 5 PA4
const int relay6 =  27;      // Rele 6 PA5
const int relay7 =  28;      // Rele 7 PA6
const int relay8 =  29;      // Rele 8 PA7
const int relay9 =  42;      // Rele 8 PA7
const int relay10 = 43;      // Rele 8 PA7

const int contatoseco8 = 41;    // the number of the pushbutton pin
const int contatoseco7 = 40;    // the number of the pushbutton pin
const int contatoseco6 = 49;    // the number of the drybutton pin
const int contatoseco5 = 48;    // the number of the drybutton pin
const int contatoseco4 = 47;    // the number of the drybutton pin
const int contatoseco3 = 46;    // the number of the drybutton pin
const int contatoseco2 = 45;    // the number of the drybutton pin
const int contatoseco1 = 44;    // the number of the drybutton pin


const int optoacopladorbutton1 = 31;    // optobutton detectar 12v
const int optoacopladorbutton2 = 30;    // optobutton detectar 12v
const int Sirene = 33;    //Saida de 12 volts Até 1,5A
const int Discadora = 32;  //Saida de 12 volts até 1A 
//-------------------------------------------------------------
LiquidCrystal lcd(39, 38, 34, 35, 36, 37);
//-------------------------------------------------------------
  void setup(){
  lcd.begin(16, 2); 
  lcd.print("iconTech V1.00A");
 
//----------------------------------------------Confi Pins------ 
  pinMode            (Sensor3,      INPUT);
  pinMode            (Sensor4,      INPUT);
  pinMode            (Sensor5,      INPUT);
  pinMode            (Sensor6,      INPUT);
  pinMode            (Sensor7,      INPUT);
  pinMode            (Sensor8,      INPUT);
//------------------------------------------------------------- 
  pinMode            (relay1,      OUTPUT);
  pinMode            (relay2,      OUTPUT);
  pinMode            (relay3,      OUTPUT);
  pinMode            (relay4,      OUTPUT);
  pinMode            (relay5,      OUTPUT);
  pinMode            (relay6,      OUTPUT);
  pinMode            (relay7,      OUTPUT);
  pinMode            (relay8,      OUTPUT);
  pinMode            (relay9,      OUTPUT);
  pinMode            (relay10,    OUTPUT);
//------------------------------------------------------------- 
  pinMode            (powerbox1,  OUTPUT);

//------------------------------------------------------------- 
  pinMode            (contatoseco6, INPUT); 
  pinMode            (contatoseco5, INPUT); 
  pinMode            (contatoseco4, INPUT); 
  pinMode            (contatoseco3, INPUT);
  pinMode            (contatoseco2, INPUT); 
  pinMode            (contatoseco1, INPUT);
  pinMode            (contatoseco2, INPUT); 
  pinMode            (contatoseco1, INPUT);
//-------------------------------------------------------------   
  pinMode(Discadora, OUTPUT);
  pinMode(Sirene,    OUTPUT);
//------------------------------------------------------------- 
  pinMode(optoacopladorbutton1, INPUT);
  pinMode(optoacopladorbutton2, INPUT); 
//-------------------------------------------------------------
//start Ethernet
  ip[0] = 192; EEPROM.read(0);
  ip[1] = 168; EEPROM.read(1);
  ip[2] =  0; EEPROM.read(2);
  ip[3] = 105; EEPROM.read(3);
  Ethernet.begin(mac, ip, gateway, subnet);
//------------------------------------------------------------- 
//enable serial datada print
  Serial.begin(9600);
  Serial2.begin(9600);
  Serial1.begin(9600);
}
//-------------------------------------------------------------   
  void loop()
  {
  leserial();
  rede();
  count++; 
//------------------------------------------------------------- 
  if(count == 500)
  {
  sensorGaz = analogRead(GazPin);//
  http://lcd.setCursor(10,1);
  http://lcd.print("Gaz:    ");
  http://lcd.setCursor(14,1);
  http://lcd.print(sensorGaz);
 
  sensorTemp = analogRead(TempPin);
  Temp = (5 * sensorTemp * 100) / 1024;
  http://lcd.setCursor(0,1);
  http://lcd.print("Temp:    ");
  http://lcd.setCursor(5,1);
  http://lcd.print(Temp);
  count=0;
  }
//------------------------------------------------------------- 
  /*{
  Sensor3 = analogRead(IN_03);
  IN_03 = ( DEC ) ;
  http://lcd.setCursor(0,1);
  http://lcd.print("IN 03:    ");
  http://lcd.setCursor(5,1);
  http://lcd.print(IN_03);
  //count=0;
  }*/
//------------------------------------------------------------- 
  /*{
  Sensor4 = analogRead(IN_04);
  IN_04 = ( DEC ) ;
  http://lcd.setCursor(0,1);
  http://lcd.print("IN 04:    ");
  http://lcd.setCursor(5,1);
  http://lcd.print(IN_04);
  //count=0;
  }*/
//------------------------------------------------------------- 
  /*{
  Sensor5 = analogRead(IN_05);
  IN_05 = ( DEC ) ;
  http://lcd.setCursor(0,1);
  http://lcd.print("IN 05:    ");
  http://lcd.setCursor(5,1);
  http://lcd.print(IN_05);
  //count=0;
  }*/
//------------------------------------------------------------- 
  /*{
  Sensor6 = analogRead(IN_06);
  IN_06 = ( DEC ) ;
  http://lcd.setCursor(0,1);
  http://lcd.print("IN 06:    ");
  http://lcd.setCursor(5,1);
  http://lcd.print(IN_06);
  //count=0;
  }*/
//------------------------------------------------------------- 
  /*{
  Sensor7 = analogRead(IN_07);
  IN_07 = ( DEC ) ;
  http://lcd.setCursor(0,1);
  http://lcd.print("IN 07:    ");
  http://lcd.setCursor(5,1);
  http://lcd.print(IN_07);
  //count=0;
  }*/
//------------------------------------------------------------- 
  /*{
  Sensor8 = analogRead(IN_08);
  IN_08 = ( DEC ) ;
  http://lcd.setCursor(0,1);
  http://lcd.print("IN 08:    ");
  http://lcd.setCursor(5,1);
  http://lcd.print(IN_08);
  //count=0;
  }*/
//-----------------------------------------------------Reles!!!-------------------------------------- 
if(readString.indexOf("r1on") >0)//replaces if(readString.contains("L=1"))
          {
            //led has to be turned ON
            digitalWrite(relay1, HIGH);    // set the LED on           
            {
            lcd.clear();
            lcd.setCursor(0,0);
            lcd.print("Relay 01: ON");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Ligando Rele 1");
            Serial2.println("Ligando Rele 1");
            Serial.println(readString);
          }
if(readString.indexOf("r1off") >0)//replaces if(readString.contains("L=1"))
          {
            digitalWrite(relay1, LOW);   
            {
            lcd.clear();
            lcd.setCursor(0,0);
            lcd.print("Relay 01: OFF");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Desligando Rele 1");
            Serial2.println("Desligando Rele 1");
            Serial.println(readString);
          }
//--------------------------------------------------------------------------------------------------------             
              if(readString.indexOf("r2on") >0)//replaces if(readString.contains("L=1"))
          {   
            digitalWrite(relay2, HIGH);    // set the LED OFF
            {
            lcd.print("Relay 02: ON");
            delay(2000);
            lcd.clear();
            }     
            Serial.println("Ligando Rele 2");
            Serial2.println("Ligando Rele 2");
            Serial.println(readString);           
          }
              if(readString.indexOf("r2off") >0)//replaces if(readString.contains("L=1"))
          {
            digitalWrite(relay2, LOW);    // set the LED on
            {
            lcd.print("Relay 02: OFF");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Desligando Rele 2");
            Serial2.println("Desligando Rele 2");
            Serial.println(readString);
          }
//--------------------------------------------------------------------------------------------------------             
              if(readString.indexOf("r3on") >0)//replaces if(readString.contains("L=1"))
          {   
            digitalWrite(relay3, HIGH);    // set the LED OFF
            {
            lcd.print("Relay 03: ON");
            delay(2000);
            lcd.clear();       
            }
            Serial.println("Ligando Rele 3");
            Serial2.println("Ligando Rele 3");
            Serial.println(readString);
           
          }
              if(readString.indexOf("r3off") >0)//replaces if(readString.contains("L=1"))
          {
            //led has to be turned ON
            digitalWrite(relay3, LOW);    // set the LED on
            {
            lcd.print("Relay 03: OFF");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Desligando Rele 3");
            Serial2.println("Desligando Rele 3");
            Serial.println(readString);
          }
//--------------------------------------------------------------------------------------------------------           
            if(readString.indexOf("r4on") >0)//replaces if(readString.contains("L=1"))
          {   
            digitalWrite(relay4, HIGH);    // set the LED OFF       
            {
            lcd.print("Relay 04: ON");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Ligando Rele 4");
            Serial2.println("Ligando Rele 4");
            Serial.println(readString);
           
          }
              if(readString.indexOf("r4off") >0)//replaces if(readString.contains("L=1"))
          {
            //led has to be turned ON
            digitalWrite(relay4, LOW);    // set the LED on
            {
            lcd.print("Relay 04: OFF");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Desligando Rele 4");
            Serial2.println("Desligando Rele 4");
            Serial.println(readString);
          }
         
//--------------------------------------------------------------------------------------------------------           
            if(readString.indexOf("r5on") >0)//replaces if(readString.contains("L=1"))
          {   
            digitalWrite(relay5, HIGH);    // set the LED OFF       
            {
            lcd.print("Relay 05: ON");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Ligando Rele 5");
            Serial2.println("Ligando Rele 5");
            Serial.println(readString);
           
          }
              if(readString.indexOf("r5off") >0)//replaces if(readString.contains("L=1"))
          {
            //led has to be turned ON
            digitalWrite(relay5, LOW);    // set the LED on
            {
            lcd.print("Relay 05: OFF");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Desligando Rele 5");
            Serial2.println("Desligando Rele 5");
            Serial.println(readString);
          }
         
//--------------------------------------------------------------------------------------------------------         
            if(readString.indexOf("r6on") >0)//replaces if(readString.contains("L=1"))
          {   
            digitalWrite(relay6, HIGH);    // set the LED OFF       
            {
            lcd.print("Relay 06: ON");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Ligando Rele 6");
            Serial2.println("Ligando Rele 6");
            Serial.println(readString);
           
          }
              if(readString.indexOf("r6off") >0)//replaces if(readString.contains("L=1"))
          {
            //led has to be turned ON
            digitalWrite(relay6, LOW);    // set the LED on
            {
            lcd.print("Relay 06: OFF");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Desligando Rele 6");
            Serial2.println("Desligando Rele 6");
            Serial.println(readString);
          }
//--------------------------------------------------------------------------------------------------------           
            if(readString.indexOf("r7on") >0)//replaces if(readString.contains("L=1"))
          {   
            digitalWrite(relay7, HIGH);    // set the LED OFF       
            {
            lcd.print("Relay 07: ON");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Ligando Rele 7");
            Serial2.println("Ligando Rele 7");
            Serial.println(readString);
           
          }
              if(readString.indexOf("r7off") >0)//replaces if(readString.contains("L=1"))
          {
            //led has to be turned ON
            digitalWrite(relay7, LOW);    // set the LED on
            {
            lcd.print("Relay 07: OFF");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Desligando Rele 7");
            Serial2.println("Desligando Rele 7");
            Serial.println(readString);
          }
//--------------------------------------------------------------------------------------------------------           
            if(readString.indexOf("r8on") >0)//replaces if(readString.contains("L=1"))
          {   
            digitalWrite(relay8, HIGH);    // set the LED OFF       
            {
            lcd.print("Relay 08: ON");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Ligando Rele 8");
            Serial2.println("Ligando Rele 8");
            Serial.println(readString);
           
          }
              if(readString.indexOf("r8off") >0)//replaces if(readString.contains("L=1"))
          {
            //led has to be turned ON
            digitalWrite(relay8, LOW);    // set the LED on
            {
            lcd.print("Relay 08: OFF");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Desligando Rele 8");
            Serial2.println("Desligando Rele 8");
            Serial.println(readString);
          }
//--------------------------------------------------------------------------------------------------------           
            if(readString.indexOf("r9on") >0)//replaces if(readString.contains("L=1"))
          {   
            digitalWrite(relay9, HIGH);    // set the LED OFF       
            {
            lcd.print("Relay 09: ON");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Ligando Rele 9");
            Serial2.println("Ligando Rele 9");
            Serial.println(readString);
           
          }
              if(readString.indexOf("r9off") >0)//replaces if(readString.contains("L=1"))
          {
            //led has to be turned ON
            digitalWrite(relay9, LOW);    // set the LED on
            {
            lcd.print("Relay 09: OFF");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Desligando Rele 9");
            Serial2.println("Desligando Rele 9");
            Serial.println(readString);
          }
//--------------------------------------------------------------------------------------------------------           
            if(readString.indexOf("r10on") >0)//replaces if(readString.contains("L=1"))
          {   
            digitalWrite(relay10, HIGH);    // set the LED OFF       
            {
            lcd.print("Relay 10: ON");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Ligando Rele 10");
            Serial2.println("Ligando Rele 10");
            Serial.println(readString);
           
          }
              if(readString.indexOf("r10off") >0)//replaces if(readString.contains("L=1"))
          {
            //led has to be turned ON
            digitalWrite(relay10, LOW);    // set the LED on
            {
            lcd.print("Relay 10: OFF");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Desligando Rele 10");
            Serial2.println("Desligando Rele 10");
            Serial.println(readString);
          }
//----------------------------------------------------------------------------------------PowerBox-----           
            if(readString.indexOf("p1on") >0)//replaces if(readString.contains("L=1"))
          {   
            digitalWrite(powerbox1, HIGH);    // set the LED OFF       
            {
            lcd.print("PowerBox1: ON");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Ligando PowerBox1");
            Serial2.println("Ligando PowerBox1");
            Serial.println(readString);
           
          }
              if(readString.indexOf("p1off") >0)//replaces if(readString.contains("L=1"))
          {
            //led has to be turned ON
            digitalWrite(powerbox1, LOW);    // set the LED on
            {
            lcd.print("PowerBox1: OFF");
            delay(2000);
            lcd.clear();
            }
            Serial.println("Desligando PowerBox1");
            Serial2.println("Desligando PowerBox1");
            Serial.println(readString);
          }
//------------------------------------------------------------------------------------------------------         
////////////////////////////Aciona sirene ou dicadora ////////////////////////////////////////////


          if(readString.indexOf("all=Ativar+Alarme") >0)//replaces if(readString.contains("L=1"))
          {
            FlagAlarme = true;
            {
            lcd.setCursor(0,0);
            lcd.print(" Alarme Ativado ");
            delay(2000);
            lcd.clear();
            }
          }
          if(readString.indexOf("all=Desativar+Alarme") >0)//replaces if(readString.contains("L=1"))
          {
            FlagAlarme = false;
            DispAlarme = false;
            digitalWrite(Discadora, LOW);
            digitalWrite(Sirene, LOW);
            {
            lcd.setCursor(0,0);
            lcd.print("* Alarme OFF !!*");
            delay(2000);
            lcd.clear();
            }           
          }
          if(readString.indexOf("all=DiscadoraON") >0)//replaces if(readString.contains("L=1"))
          {
            digitalWrite(Discadora, HIGH);
            {
            lcd.setCursor(0,0);
            lcd.print("Sirene lIGADA !!");
            delay(2000);
            lcd.clear();
            }
          }
          if(readString.indexOf("all=DiscadoraOff") >0)//replaces if(readString.contains("L=1"))
          {
            digitalWrite(Discadora, LOW);
            {
            lcd.setCursor(0,0);
            lcd.print("Sirene DESLIGADA");
            delay(20000);
            lcd.clear();
            }
          }
         
          if (FlagAlarme == true)
          {
            le_sensores();     
            if (DispAlarme == true)
            {
            digitalWrite(Sirene, HIGH);   
            digitalWrite(Discadora, HIGH);
            {
            lcd.setCursor(0,0);
            lcd.print("Falha Seguranca!");
            delay(2000);
            lcd.clear();
            }
          }
          }
//Teste de opto acopladores detectam 9~12v podem ser usados tambem como zonas de alarmes principalmente para sensores de portas e janelas
        optoacopladorState1 = digitalRead(optoacopladorbutton1);
        optoacopladorState2 = digitalRead(optoacopladorbutton2);
       
            if(optoacopladorState1 == 0)
            {           
            lcd.setCursor(0,1);
            lcd.print("12v entrada 1");
            delay(1000);
            lcd.clear();           
            }
            if(optoacopladorState2 == 0)
            {           
            lcd.setCursor(0,1);
            lcd.print("12v entrada 2");
            delay(1000);
            lcd.clear();           
            }
           
   
          readString=""; //limpa a string depois de testa-la
 } // End loop
 
//Função Alarme UP
void le_sensores()
{
  ContatoSecoState1 = digitalRead(contatoseco1);
  ContatoSecoState2 = digitalRead(contatoseco2);
  ContatoSecoState3 = digitalRead(contatoseco3);
  ContatoSecoState4 = digitalRead(contatoseco4);
  ContatoSecoState5 = digitalRead(contatoseco5);
  ContatoSecoState6 = digitalRead(contatoseco6);
  ContatoSecoState7 = digitalRead(contatoseco7);
  ContatoSecoState8 = digitalRead(contatoseco8);
 
  if (ContatoSecoState1 == LOW)
  {
      DispAlarme = true;
      {
      lcd.setCursor(0,1);
      lcd.print("Sensor 1 Falha!!");
      delay(3000);
      lcd.setCursor(0,1);
      lcd.print("SENSOR COZINHA!!");
      }
  }
 
  if (ContatoSecoState2 == LOW)
  {
      DispAlarme = true;
      {
      lcd.setCursor(0,1);
      lcd.print("Sensor 2 Falha!!");
      delay(3000);
      lcd.setCursor(0,1);
      lcd.print(" SENSOR SALA !! ");
      }
  }
  if (ContatoSecoState3 == LOW)
  {
      DispAlarme = true;
      {
      lcd.setCursor(0,1);
      lcd.print("Sensor 3 Falha!!");
      delay(3000);
      lcd.setCursor(0,1);
      lcd.print(" JANELA SALA !! ");
      }
  }
 
  if (ContatoSecoState4 == LOW)
  {
      DispAlarme = true;
      {
      lcd.setCursor(0,1);
      lcd.print("Sensor 4 Falha!!");
      delay(3000);
      lcd.setCursor(0,1);
      lcd.print("!JANELA ESTUDIO!");
      }
  }
  if (ContatoSecoState5 == LOW)
  {
      DispAlarme = true;
      {
      lcd.setCursor(0,1);
      lcd.print("Sensor 5 Falha!!");
      delay(3000);
      lcd.setCursor(0,1);
      lcd.print(" SENSOR _____ !!");
      }
  }
  if (ContatoSecoState6 == LOW)
  {
      DispAlarme = true;
      {
      lcd.setCursor(0,1);
      lcd.print("Sensor 6 Falha!!");
      delay(3000);
      lcd.setCursor(0,1);
      lcd.print(" SENSOR _____ !!");
      }
  }
  if (ContatoSecoState7 == LOW)
  {
      DispAlarme = true;
      {
      lcd.setCursor(0,1);
      lcd.print("Sensor 7 Falha!!");
      delay(3000);
      lcd.setCursor(0,1);
      lcd.print(" SENSOR _____ !!");
      }
  }
  if (ContatoSecoState8 == LOW)
  {
      DispAlarme = true;
      {
      lcd.setCursor(0,1);
      lcd.print("Sensor 8 Falha!!");
      delay(3000);
      lcd.setCursor(0,1);
      lcd.print(" SENSOR _____ !!");
      }
  } 
 
}


//Função lê serial
void leserial(){
  // read incoming message
    while(Serial.available()){
    c = (char) Serial.read();
    if (readString.length() < 100)
      {
      //store characters to string
      readString += c; //replaces readString.append(c);
      }
      delay(10); // wait for another byte 
  }
      while(Serial2.available()){
      c = (char) Serial2.read();
      if (readString.length() < 100)
      {
      //store characters to string
      readString += c; //replaces readString.append(c);
      }
      delay(10); // wait for another byte 
  }
      while(Serial1.available()){
      c = (char) Serial1.read();
      if (readString.length() < 100)
      {
      //store characters to string
      readString += c; //replaces readString.append(c);
      }
      delay(10); // wait for another byte 
  }
 

///////////////////////////////////////////////////////////////////////////////////////////////////////// 
    //Função que recebe string do navegador
    void rede(){
    // Create a client connection
    Client client = server.available();
    if (client) {
    while (client.connected()) {
    if (client.available()) {
    c = client.read();
    //read char by char HTTP request
    if (readString.length() < 100)
    {
    //store characters to string
    readString += c; //replaces readString.append(c);
    }
    //output chars to serial port
    //if HTTP request has ended
    if (c == '\n') {
    //dirty skip of "GET /favicon.ico HTTP/1.1"
    if (readString.indexOf("?") <0)
    {
    //skip everything
    }
    //else
//--------------------------HTML------------------------         
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<html><head>");
client.print("<title>iconTch Master View V1.00A</title>");
client.println("</head>");
client.print("<body bgcolor='#444444'>");
client.println("<br><hr />");
client.println("<h1><div align='center'><font color='#2076CD'>iconTech Webserver 1.0</font color></div></h1>");
client.println("<hr /><br>");
client.println("<div align='left'><font face='Verdana' color='#FFFFFF'>Painel de Controle WEB:</font></div>");
client.println("<br>");
//-------------------------------------------------------------------------------------------------
client.println("<div align='left'><font face='Verdana' color='#FFFFFF'>Temperatura:");
client.print(Temp);
client.println("</font></div>");
//-------------------------------------------------------------------------------------------------
client.println("<div align='left'><font face='Verdana' color='#FFFFFF'>Gaz:");
client.print(sensorGaz);
client.println("</font></div>");
//-------------------------------------------------------------------------------------------------
client.println("<br>");
client.println("<table border='1' width='100%' cellpadding='5'>");
client.println("<tr bgColor='#222222'>");
/*-----------------------------------INIBIÇÃO DOS ANALOGICOS!!!--------------------------------------
client.println("<div align='left'><font face='Verdana' color='#FFFFFF'>Entrada Analogica 2:");
client.print(IN_02);
client.println("</font></div>");

client.println("<div align='left'><font face='Verdana' color='#FFFFFF'>Entrada Analogica 3:");
client.print(IN_03);
client.println("</font></div>");

client.println("<div align='left'><font face='Verdana' color='#FFFFFF'>Entrada Analogica 4:");
client.print(IN_04);
client.println("</font></div>");

client.println("<div align='left'><font face='Verdana' color='#FFFFFF'>Entrada Analogica 5:");
client.print(IN_05);
client.println("</font></div>");

client.println("<div align='left'><font face='Verdana' color='#FFFFFF'>Entrada Analogica 6:");
client.print(IN_06);
client.println("</font></div>");

client.println("<div align='left'><font face='Verdana' color='#FFFFFF'>Entrada Analogica 7:");
client.print(IN_07);
client.println("</font></div>");

client.println("<div align='left'><font face='Verdana' color='#FFFFFF'>Entrada Analogica 8:");
client.print(IN_08);
client.println("</font></div>");
---------------------------------------------------------------------------------------------------*/
//------------------------------------------------------------------------------------------------------RELES INFO--------------------
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>110/220 OUT 1<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r1on value='LIGAR'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r1off value='DESLIGAR'></form></td>");
if (digitalRead(relay1)== HIGH)
client.println("<td align='center'><font color='green' size='5'>LIG");
else
client.println("<td align='center'><font color='#CFCFCF' size='5'>DES");

client.println("</tr>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>110/220 OUT 2<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r2on value='LIGAR'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r2off value='DESLIGAR'></form></td>");
if (digitalRead(relay2) == HIGH)
 client.println("<td align='center'><font color='green' size='5'>LIG");
else
client.println("<td align='center'><font color='#CFCFCF' size='5'>DES");
 
client.println("</tr>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>110/220 OUT 3<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r3on value='LIGAR'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r3off value='DESLIGAR'></form></td>");
if (digitalRead(relay3) == HIGH)
client.println("<td align='center'><font color='green' size='5'>LIG");
else
client.println("<td align='center'><font color='#CFCFCF' size='5'>DES");
 
client.println("</tr>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>110/220 OUT 4<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r4on value='LIGAR'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r4off value='DESLIGAR'></form></td>");
if (digitalRead(relay4) == HIGH)
client.println("<td align='center'><font color='green' size='5'>LIG");
else
client.println("<td align='center'><font color='#CFCFCF' size='5'>DES");
 
client.println("</tr>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>110/220 OUT 5<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r5on value='LIGAR'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r5off value='DESLIGAR'></form></td>");
if (digitalRead(relay5) == HIGH)
client.println("<td align='center'><font color='green' size='5'>LIG");
else
client.println("<td align='center'><font color='#CFCFCF' size='5'>DES");
 
client.println("</tr>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>110/220 OUT 6<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r6on value='LIGAR'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r6off value='DESLIGAR'></form></td>");
if (digitalRead(relay6) == HIGH)
client.println("<td align='center'><font color='green' size='5'>LIG");
else
client.println("<td align='center'><font color='#CFCFCF' size='5'>DES");
 
client.println("</tr>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>110/220 OUT 7<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r7on value='LIGAR'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r7off value='DESLIGAR'></form></td>");
if (digitalRead(relay7) == HIGH)
client.println("<td align='center'><font color='green' size='5'>LIG");
else
client.println("<td align='center'><font color='#CFCFCF' size='5'>DES");
 
client.println("</tr>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>110/220 OUT 8<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r8on value='LIGAR'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r8off value='DESLIGAR'></form></td>");
if (digitalRead(relay8) == HIGH)
client.println("<td align='center'><font color='green' size='5'>LIG");
else
client.println("<td align='center'><font color='#CFCFCF' size='5'>DES");
 
client.println("</tr>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>110/220 OUT 9<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r9on value='LIGAR'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r9off value='DESLIGAR'></form></td>");
if (digitalRead(relay9) == HIGH)
client.println("<td align='center'><font color='green' size='5'>LIG");
else
client.println("<td align='center'><font color='#CFCFCF' size='5'>DES");
 
client.println("</tr>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>110/220 OUT 10<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r10on value='LIGAR'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=r10off value='DESLIGAR'></form></td>");
if (digitalRead(relay10) == HIGH)
client.println("<td align='center'><font color='green' size='5'>LIG");
else
client.println("<td align='center'><font color='#CFCFCF' size='5'>DES");

client.println("</tr>");
client.println("<tr bgColor='#222222'>");
client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>Power Box 1<br></font></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=p1on value='LIGAR'></form></td>");
client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=p1off value='DESLIGAR'></form></td>");
if (digitalRead(powerbox1) == HIGH)
client.println("<td align='center'><font color='green' size='5'>LIG");
else
client.println("<td align='center'><font color='#CFCFCF' size='5'>DES");
client.println("</tr>");

client.println("</tr>");
client.println("</table>");
client.println("<br>");

if (FlagAlarme == 0)
client.println("<form method=get><input type=submit name=all value='Ativar Alarme'></form>");
else
client.println("<form method=get><input type=submit name=all value='Desativar Alarme'></form>");

client.println("<br>");
client.println("<form method=get><input type=submit name=all value='DiscadoraON'></form>");
client.println("<form method=get><input type=submit name=all value='DiscadoraOff'></form>");
client.println("<form method=get><input name='ip' size='17' maxlength=17>");
client.println("<form method=get><input value='Salvar' type=submit></form>");


client.println("</body></html>");
         
          //stopping client
          client.stop();
            }             
          }       
        } //while             
      } //If client
 } //Void rede

SrMion

Mensagens : 1
Data de inscrição : 02/01/2013

Ver perfil do usuário

Voltar ao Topo Ir em baixo

Re: ADM, uma força aee

Mensagem  Admin em Seg 14 Jan - 6:21

Amigo recomendo vc não usar delay pois o programa vai ficar parado durante esse processo e vc perde todo o controle sobre o programa, utilize um contador e um flag para o mesmo
avatar
Admin
Admin

Mensagens : 560
Data de inscrição : 07/04/2009
Idade : 36
Localização : Franca

Ver perfil do usuário http://projetoarduino.forum-livre.com

Voltar ao Topo Ir em baixo

Ver o tópico anterior Ver o tópico seguinte Voltar ao Topo

- Tópicos similares

 
Permissão deste fórum:
Você não pode responder aos tópicos neste fórum