TickerScheduler ts(2);
const char WiFiPassword[] = "pushmybutton";
const char AP_NameChar[] = "BELLMENOW" ;
static boolean Ringon=false;
int LED_Pin = 0;
static boolean lEDon=false;
void lightledl()// called every 500ms
{
Serial.println("Called by Ticker1 every500ms...");
if (digitalRead(LED_Pin) == LOW)
{
digitalWrite(LED_Pin, HIGH);
Serial.println("TURNING ON LED...");
}
else//MUST BE HIGH
{
digitalWrite(LED_Pin, LOW);
Serial.println("TURNING OFF LED...");
}
}
void Ringbell() {
Serial.println("Called by Ticker...");
if(Ringon==true)
{
digitalWrite(LED_BUILTIN, HIGH);//write the port
Serial.println("Port high...Flag reset");
Ringon=false;//reset the flag as soon as function fires
digitalWrite(LED_Pin, HIGH);
Serial.println("TURNING ON LED...");
ts.enable(1);//enable the calling func for the led
Serial.println("enabling timer1...");
}
else
{
Serial.println("Port LOW...Flag reset");
digitalWrite(LED_BUILTIN, LOW);//write the port TO TURMN OFF SOUNG
Serial.println("TURNING OFF SOUND...");
ts.disable(1);//disable he led drive for now
digitalWrite(LED_Pin, LOW);// leave in off state
Serial.println("diasabling timer1...");
}
}
WiFiServer server(80);
String header = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
String html_1 = "NOC BELLCALL THE NOC!
";
String html_2 = "";
String html_4 = "";
String request = "";
void setup()
{
Serial.begin(115200);
Serial.println("Entering Setup...");
pinMode(LED_Pin, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
ts.add(0, 10000, [&](void *) { Ringbell(); }, nullptr, true);
ts.add(1, 500, [&](void *) { lightledl(); }, nullptr, true);
ts.disable(1);//disable he led drive for now
boolean conn = WiFi.softAP(AP_NameChar, WiFiPassword);
server.begin();
} // void setup()
void loop()
{
ts.update();
//Serial.println("tsupdate...");
// Check if a client has connected
WiFiClient client = server.available();
if (!client) { return; }
Serial.println("Client Connected...");
// Read the first line of the request
request = client.readStringUntil('\r');
// if ( request.indexOf("bellON") > 0 ) { digitalWrite(LED_BUILTIN, HIGH); }
// else if ( request.indexOf("bellOFF") > 0 ) { digitalWrite(LED_BUILTIN, LOW); }
if ( request.indexOf("bellON") > 0 ) { Ringon=true; }
//else if ( request.indexOf("bellOFF") > 0 ) { Ringon=true; }
// Get the LED pin status and create the LED status message
//if (digitalRead(LED_BUILTIN) == HIGH)
//if(Ringon==true)
{
Serial.println("Ringon is true");
digitalWrite(LED_BUILTIN, HIGH);//write the port early before led kicks in
Serial.println("Port high...Flag reset");
// the command to ring the bell is still active so send status
html_2 = "
";
}
// else
// {
// Serial.println("Ringon is FALSE");
// the LED is off so the button needs to say turn it on
// html_2 = "
";
//}
client.print( header );
client.flush();
client.print( html_1 );
client.print( html_2 );
client.print( html_4);
delay(5);
// The client will actually be disconnected when the function returns and 'client' object is detroyed
} // void loop()