Guys I need your help. I’m building a fuel level sensor with the ultrasonic sensor. The code I wrote works well, but instead of the “numbers in CM” I would like to make it appear on the virtual display of special characters as a full notch and empty notch based on a maximum of 90Cm all empty notches, 0 all full notches
I enclose code to figure out where I’m wrong. I’m mistaken when I compile on line 60
I apologize for my English and bad writing code, but I’m at the beginning.
#define BLYNK_PRINT Serial
#include <LiquidCrystal.h>
//CREAZIONE DEI DUE CARATTERI SPECIALI: Carattere Tacca Piena e Tacca Vuota
byte TaccaPiena[8] = //RIQUADRO PIENO (TACCA PIENA)
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
}; // Array 8x5 bit per la definizione di un singolo carattere
byte TaccaVuota[8] = //RIQUADRO VUOTO (TACCA VUOTA)
{
B11111,
B10001,
B10001,
B10001,
B10001,
B10001,
B10001,
B11111
};
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define triggerPort D1
#define echoPort D2
long r ; //variabile distanza
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "lxxxxxxxxx";
char pass[] = "xxxxxxxxx";
WidgetLCD lcd(V1);
void setup()
{
// Debug console
Serial.begin(9600);
pinMode( triggerPort, OUTPUT );
pinMode( echoPort, INPUT );
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
lcd.clear(); //Use it to clear the LCD Widget
lcd.createChar(0, TaccaPiena);
lcd.createChar(1, TaccaVuota);
lcd.print(0, 0, "Liv.Combustibile"); // ASSEGNAZIONE SCRITTA PRIMA RIGA use: (position X: 0-15, position Y: 0-1, "Message you want to print")
// Please use timed events when LCD printintg in void loop to avoid sending too many commands
// It will cause a FLOOD Error, and connection will be dropped
}
void loop() {
lcd.clear();
lcd.print(0, 0, "Liv.Combustibile"); // ASSEGNAZIONE SCRITTA PRIMA RIGA use: (position X: 0-15, position Y: 0-1, "Message you want to print")
digitalWrite( triggerPort, LOW ); //porta bassa l'uscita del trigger
digitalWrite( triggerPort, HIGH ); //invia un impulso di 10microsec su trigger
delayMicroseconds( 10 );
digitalWrite( triggerPort, LOW );
long duration = pulseIn( echoPort, HIGH , 10000 ); // 10000 µS = max circa 1,7 metr1
r = 0.034 * duration / 2;
Serial.print(r);
Serial.println("Cm");
if ( r > 0 ) {
lcd.setCursor(0, 1);
lcd.print(" ");
int x = map(r, 12, 90, 15, 0);
for (int i = 0 ; i <= x ; i++ ) {
lcd.setCursor(i, 1);
lcd.write(byte(0));
}
for (int i = 15 ; i > x ; i-- ) {
lcd.setCursor(i, 1);
lcd.write(byte(1));
}
if (r >= 90) {
for (int i = 0 ; i < 6 ; i++) {
lcd.print(0, 1, r); // ASSEGNAZIONE SCRITTA SECONDA RIGA
Blynk.run();
delay(3500);
}








