#include "BluetoothSerial.h"
int input;
int down;
BluetoothSerial SerialBT;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // memulai komunikasi serial
SerialBT.begin("ESP32test");
Serial.println("Perangkat telah dimulai, sekarang Anda dapat memasangkan perangkat dengan Bluetooth!");
pinMode(4, OUTPUT);
input = 0;
down = 0;
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
analogWrite(4, input);
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
Serial.println(input);
if (Serial.available()) { // jika data tersedia di monitor serial
SerialBT.write(Serial.read()); // kirim data ke perangkat Bluetooth
}
if (SerialBT.available()) { // jika data tersedia di perangkat Bluetooth
Serial.write(SerialBT.read()); // mencetak data di monitor serial
}
delay(20);
if(down == 0){
input += 10;
if(input == 255){
down = 1;
}
}else if(down==1){
input -=10;
if(input == 0){
down = 0;
}
}
delay(100);
}