Can't Debounce

how to provide delay on debouncing programs?

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(10, 14, 206, 116);
EthernetClient client;
IPAddress server(10, 14, 206, 64); //computer

unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
unsigned long debounceDelay = 50; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10 * 1000; // delay between updates, in milliseconds

int temp1[2];
int temp2[2];
int temp3[2];
int temp4[2];
int temp5[2];
int temp6[2];

int stat1;
int stat2;
int stat3;
int stat4;
int stat5;
int stat6;

int bt1 = A14;
int bt2 = A13;
int bt3 = A12;
int bt4 = A11;
int bt5 = A10;
int bt6 = A8;

bool lock1 = true;
bool lock2 = true;
bool lock3 = true;
bool lock4 = true;
bool lock5 = true;
bool lock6 = true;

void setup() {
pinMode(bt1, INPUT);
pinMode(bt2, INPUT);
pinMode(bt3, INPUT);
pinMode(bt4, INPUT);
pinMode(bt5, INPUT);
pinMode(bt6, INPUT);

Serial.begin(9600);
while (!Serial) { ;}

Serial.println("Initialize Ethernet with DHCP:");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");

if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1);
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
Ethernet.begin(mac, ip);
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
} else {
Serial.print(" DHCP assigned IP ");
Serial.println(Ethernet.localIP());
}
delay(2000);

temp1[0] = digitalRead(bt1);
temp1[1] = digitalRead(bt1);

temp2[0] = digitalRead(bt2);
temp2[1] = digitalRead(bt2);

temp3[0] = digitalRead(bt3);
temp3[1] = digitalRead(bt3);

temp4[0] = digitalRead(bt4);
temp4[1] = digitalRead(bt4);

temp5[0] = digitalRead(bt5);
temp5[1] = digitalRead(bt5);

temp6[0] = digitalRead(bt6);
temp6[1] = digitalRead(bt6);
}

void loop() {
if (client.available()) {
char c = client.read();

Serial.write(c);
}
temp1[0] = digitalRead(bt1);
if (temp1[0] != temp1[1] && lock1==true) {
stat1 = temp1[0];
temp1[1] = temp1[0];
httpRequest();
}
else if (temp1[0] = temp1[1])
{lock1=true;}

temp2[0] = digitalRead(bt2);
if (temp2[0] !=temp2[1] && lock2==true) {
stat2 = temp2[0];
temp2[1] = temp2[0];
httpRequest();
}
else if (temp2[0] = temp2[1])
{lock2=true;}

temp3[0] = digitalRead(bt3);
if (temp3[0] !=temp3[1] && lock3==true) {
stat3 = temp3[0];
temp3[1] = temp3[0];
httpRequest();
}
else if (temp3[0] = temp3[1])
{lock3=true;}

temp4[0] = digitalRead(bt4);
if (temp4[0] != temp4[1] && lock4==true) {
stat4 = temp4[0];
temp4[1] = temp4[0];
httpRequest();
}
else if (temp4[0] = temp4[1])
{lock4=true;}

temp5[0] = digitalRead(bt5);
if (temp5[0] != temp5[1] && lock5==true) {
stat5 = temp5[0];
temp5[1] = temp5[0];
httpRequest();
}
else if (temp5[0] = temp5[1])
{lock5=true;}

temp6[0] = digitalRead(bt6);
if (temp6[0] != temp6[1] && lock6==true) {
stat6 = temp6[0];
temp6[1] = temp6[0];
httpRequest();
}
else if (temp6[0] = temp6[1])
{lock6=true;}
}

void httpRequest() {
client.stop();

if (client.connect(server, 80)) {
Serial.println("connecting...");
if (stat6==1) client.println("GET /line_stop/ethernet0.php?a=1 HTTP/1.1");
if (stat6==0) client.println("GET /line_stop/ethernet0.php?b=0 HTTP/1.1");
client.println("Host: 10.14.206.64");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
lastConnectionTime = millis();
} else {
Serial.println("connection failed");
}

if (client.connect(server, 80)) {
Serial.println("connecting...");
if (stat1==1) client.println("GET /line_stop/ethernet1.php?c=1 HTTP/1.1");
if (stat1==0) client.println("GET /line_stop/ethernet1.php?d=0 HTTP/1.1");
client.println("Host: 10.14.206.64");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
lastConnectionTime = millis();
} else {
Serial.println("connection failed");
}

if (client.connect(server, 80)) {
Serial.println("connecting...");
if (stat2==1) client.println("GET /line_stop/ethernet2.php?e=1 HTTP/1.1");
if (stat2==0) client.println("GET /line_stop/ethernet2.php?f=0 HTTP/1.1");
client.println("Host: 10.14.206.64");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
lastConnectionTime = millis();
} else {
Serial.println("connection failed");
}

if (client.connect(server, 80)) {
Serial.println("connecting...");
if (stat3==1) client.println("GET /line_stop/ethernet3.php?g=1 HTTP/1.1");
if (stat3==0) client.println("GET /line_stop/ethernet3.php?h=0 HTTP/1.1");
client.println("Host: 10.14.206.64");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
lastConnectionTime = millis();
} else {
Serial.println("connection failed");
}

if (client.connect(server, 80)) {
Serial.println("connecting...");
if (stat4==1) client.println("GET /line_stop/ethernet4.php?i=1 HTTP/1.1");
if (stat4==0) client.println("GET /line_stop/ethernet4.php?j=0 HTTP/1.1");
client.println("Host: 10.14.206.64");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
lastConnectionTime = millis();
} else {
Serial.println("connection failed");
}

if (client.connect(server, 80)) {
Serial.println("connecting...");
if (stat5==1) client.println("GET /line_stop/ethernet5.php?k=1 HTTP/1.1");
if (stat5==0) client.println("GET /line_stop/ethernet5.php?l=0 HTTP/1.1");
client.println("Host: 10.14.206.64");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
lastConnectionTime = millis();
} else {
Serial.println("connection failed");
}
}

Do not hijack. Thread split.

Read How to post code properly and then use the </> icon to create [code]...[/code] tags around your code so that it is easier to read.

Pete

there was a problem with my project
the problem is the arduino error in sending data to the php web

the process flow in the Arduino circuit is

  1. plc / output y0 send signal to coil relay with 24vdc voltage
  2. Arduino input goes to the relay contact with a 10k ohm step down resistor circuit.
    Arduino works when the PLC output (hold) Arduino sends data to the web in the form of days and dates, when the PLC output is Arduino, send data to the web in the form of days and dates.