#include <CoreX.h>
#include <WiFi.h>
#include "Connection.h"
WiFiClient Net;
CoreX Client;
const char* AUTH_TOKEN = "hNZ5HAqnH3fW0gT";
const char* DEVICE_ID = "qV18LO6yA";
const char ssid[] = "Wokwi-GUEST";
const char pass[] = "";
const int pinBuzzer = 26;
const int pinRed = 17;
const int pinGreen = 18;
const int pinBlue = 19;
void setup() {
Serial.begin(115200);
pinMode(pinRed, OUTPUT);
pinMode(pinGreen, OUTPUT);
pinMode(pinBlue, OUTPUT);
WiFi.begin(ssid, pass);
corex.begin(net);
setupCorex();
}
void loop() {
tone(26, 200); //membunyikan buzzer sebesar 200Hz, boleh diubah-ubah sesuai dengan keinginan, semakin tinggi frekuensi semakin tinggi pula suara buzzernya
delay(2000);
tone(26, 250);
delay(2000);
if (!corex.connected()) {
setupCorex();
}
}
void buzzerOn(int pin){
tone(26, 0); // nomor pin, channel
ledcWriteNote(0, NOTE_A, 6);
}
void rgb(bool Red, bool Green, bool Blue){
digitalWrite(pinRed, Red);
digitalWrite(pinGreen, Green);
digitalWrite(pinBlue, Blue);
}
void connect(){
rgb(1,0,0);//merah
while(WiFi.status() !=WL_CONNECTED){
delay(500);
}
rgb(0,1,0);//hijau
while(!Client.connect("corex.id")){
delay(500);
}
rgb(0,0,1);//biru
corex.send("alarm_kebakaran", ("String"));
}