 
/*
 * ESP32 S cu tastatura PS2 cu convertor logic
 * trimite si primeste text
 cu aplic BT S2 terminal 
primeste text de la Terminal de pe Android
si afiseaza pe Oled

 afiseaza ce se tipareste pe PS2 Key
 afiseaza pe tetefon corect daca se debifeaza
 in aplicatie fereastra Autol casuta After Receive 
 setare ASCII
*/
#include "BluetoothSerial.h"  
BluetoothSerial SerialBT;
char c = ' ';
char d= ' ';

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

#include "PS2Keyboard.h"
const int DataPin = 4;//albastru
const int IRQpin =  0;//galben
PS2Keyboard keyboard;
 
void setup() 
{
   Serial.begin(115200);
   SerialBT.begin("ESP32 BT");
   keyboard.begin(DataPin, IRQpin);
   
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print("ESP32 BT Text Terminal PS2");
  display.display();
  delay(1000);  
}
 
void loop()
{
    if (SerialBT.available()) {  
        c = SerialBT.read(); 
        //primeste caractere de la telefon
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.print(c);   
  display.display();
   
  if (c == '/'){
    //sterge oled cand se tipareste '/'
    display.clearDisplay();
    display.setCursor(0,0);
    }
    }
    
    if (keyboard.available()) {
      //de la tastatura PS2 trimite ASCII
    char  d = keyboard.read();       
        SerialBT.print(d);
        display.print(d); 
        display.display();
        if (d == '/'){
          //sterge oled cand se tipareste '/'
    display.clearDisplay();
    display.setCursor(0,0);
    }
    }
    }
