
// RGB la GND, D12,14,27


#include "BluetoothSerial.h" 
BluetoothSerial ESP_BT; 
#define ledPin 12
#define ledPin2 14
#define ledPin3 27

#include <Adafruit_SSD1306.h>
  #include <Adafruit_GFX.h>
  #define OLED_ADDR   0x3C
  Adafruit_SSD1306 display(-1);

int state = 0;

void setup() {
 pinMode(ledPin, OUTPUT);
 digitalWrite(ledPin, LOW);
 
 pinMode(ledPin2, OUTPUT);
 digitalWrite(ledPin2, LOW);
 
 pinMode(ledPin3, OUTPUT);
 digitalWrite(ledPin3, LOW);
 
 ESP_BT.begin("ESP32_RGB voce_Control");
 Serial.begin(115200); 
 
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
    display.clearDisplay(); 
    display.setTextSize(2); 
    display.setTextColor(WHITE);
    display.setCursor(0,0); 
    display.print("voce rgb Oled ESP32");
    display.display(); 
    delay(1000); 
    display.clearDisplay(); 
    }

void loop() {
 if(ESP_BT.available() > 0){ // Checks whether data is comming from the serial port
 state = ESP_BT.read(); // Reads the data from the serial port

    display.clearDisplay(); 
    display.setTextSize(2); 
    display.setTextColor(WHITE);
    display.setCursor(0,0); 
    display.print(state,DEC);
    display.display(); 
      }
 
  if (state == 'a') {
 digitalWrite(ledPin, LOW); // Turn LED OFF
 Serial.println("LED1: OFF"); 
 state = 0;
 }
 
  else if (state == 'n') {
 digitalWrite(ledPin, HIGH);
 Serial.println("LED1: ON");;
 state = 0;
 } 

 if (state == 'e') {
 digitalWrite(ledPin2, LOW); // Turn LED OFF
 //Serial.println("LED2: OFF"); // Send back, to the phone, the String "LED: ON"
 state = 0;
 }
 else if (state == 'i') {
 digitalWrite(ledPin2, HIGH);
 //Serial.println("LED2: ON");;
 state = 0;
 } 
 
 if (state == 'c') {
 digitalWrite(ledPin3, LOW); // Turn LED OFF
 //Serial.println("LED3: OFF"); // Send back, to the phone, the String "LED: ON"
 state = 0;
 }
 else if (state == 'd') {
 digitalWrite(ledPin3, HIGH);
 //Serial.println("LED3: ON");;
 state = 0;
 } 
}
