/*
 * trimite M1 si M2 de la retea rezistiva feedback motoare
 * pe A0=36 si A1-39
 * RGB sau punte H pe GPIO 12,14,27,25
 * fara definitie cu butoane pe 
 * D12,14,27,25
 * afiseaza local pe Oled 
 * primeste text de la telefon Terminal
 * si afiseaza pe oled
  */

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#include <SimpleTimer.h>
SimpleTimer timer;

char auth[] = "e5beac0d31f4433da82dc64b99a03b39"; 
char ssid[] = "UPCF4821BC";
char pass[] = "Gherla1956";

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

void setup() {
    Serial.begin(115200);
    SPI.begin();
    Blynk.begin(auth, ssid, pass);
    timer.setInterval(500L, sendUptime);

  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print("ESP32 fdbk Blynk");
  display.display();
  delay(1000); 
}

BLYNK_WRITE(V12)//optional
    { //trimite pe oled text editat
      //pe terminal pe telefon
  //Serial.print(param.asInt());//trimite numai cifre
  Serial.print(param.asStr());  //trimite string litere si cifre

  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print(param.asStr());
  display.display();
  delay(1000);
    }

void sendUptime(){
    int M1 = analogRead (36);
    int M2 = analogRead (39);
    Serial.print("M1=");
    Serial.println(M2);
    
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print("M1=");
  display.println(M1);
  display.setCursor(0,20);
  display.print("M2=");
  display.println(M2);
  display.display();
    
    
   Blynk.virtualWrite(12, "  M1= ");
   Blynk.virtualWrite(12, M1);  
   Blynk.virtualWrite(5, M1);  
   //optional afiseaza pe Gauge pe virtual V5

   Blynk.virtualWrite(12, "  M2= ");
   Blynk.virtualWrite(12, M2); 
   Blynk.virtualWrite(6, M2);  
   //optional afiseaza pe Gauge pe virtual V6
     } 

void loop()
{
  Blynk.run(); 
  timer.run();
}
