#include <WiFi.h>
#include "ThingSpeak.h"
int buttonPin1 = 34;
int buttonPin2 = 32;
int buttonPin3 = 25;
int buttonState1 = 0; // present state
int count_value1 =0;
int prestate1 =0; // previous state
int buttonState2 = 0;
int count_value2 =0;
int prestate2 =0;
int buttonState3 = 0;
int count_value3 =0;
int prestate3 =0;
const char* WIFI_NAME = "M31";
const char* WIFI_PASSWORD = "harsha@25";
const int myChannelNumber =2311045 ;
const char* myApiKey = "XZ7BQIHYPWWK0RXA";
const char* server = "api.thingspeak.com";
void setup() {
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
Serial.begin(9600);
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED){
delay(1000);
Serial.println("Wifi not connected");
}
Serial.println("Wifi connected !");
Serial.println("Local IP: " + String(WiFi.localIP()));
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}
}
void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
ThingSpeak.setField(1,dat.temperature);
ThingSpeak.setField(2,data.humidity);
// check if the pushbutton is pressed. If it is, then the buttonState is HIGH:
if (buttonState1 == HIGH && prestate1 == 0) {
count_value1++;
Serial.println("EXCELLENT");
Serial.print("EXCELLENT COUNT=");
Serial.println(count_value1);
delay(500);
prestate1 = 1;
}
else if(buttonState1 == LOW) {
prestate1 = 0;
}
if (buttonState2 == HIGH && prestate2 == 0) {
count_value2++;
Serial.println("GOOD");
Serial.print("GOOD COUNT=");
Serial.println(count_value2);
delay(500);
prestate2 = 1;
}
else if(buttonState2 == LOW) {
prestate2 = 0;
}
if (buttonState3 == HIGH && prestate3 == 0) {
count_value3++;
Serial.println("AVERAGE");
Serial.print("AVERAGE COUNT=");
Serial.println(count_value3);
delay(500);
prestate3 = 1;
}
else if(buttonState3 == LOW) {
prestate3 = 0;
}
}