#include <LiquidCrystal.h>
#define PIN_TRIG PB5
#define PIN_ECHO PB6
#define LED PB9
const int rs = PB11, en = PB10, d4 = PB0, d5 = PB1, d6 = PC13, d7 = PC14; //mention the pin names to with LCD is connected to
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); //Initialize the LCD
void setup() {
Serial.begin(115200);
Serial.println("Hello STM32!");
Serial.println("Welcome to Wokwi :-)");
pinMode(LED, OUTPUT);
Serial.begin(115200);
pinMode(PIN_TRIG, OUTPUT);
pinMode(PIN_ECHO, INPUT);
cd.begin(16, 2);//We are using a 16*2 LCD
lcd.setCursor(0, 0); //At first row first column
lcd.print("Interfacing LCD"); //Print this
lcd.setCursor(0, 1); //At secound row first column
lcd.print("STM32"); //Print this
delay(2000); //wait for two secounds
lcd.clear(); //Clear the screen
}
void loop() {
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
// Start a new measurement:
digitalWrite(PIN_TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(PIN_TRIG, LOW);
// Read the result:
int duration = pulseIn(PIN_ECHO, HIGH);
Serial.print("Distance in CM: ");
Serial.println(duration / 58);
Serial.print("Distance in inches: ");
Serial.println(duration / 148);
delay(1000);
lcd.setCursor(0, 0); //At first row first column
lcd.print("STM32 -Blue Pill"); //Print this
lcd.setCursor(4, 1); //At secound row first column
lcd.print("Hello World"); //Print the value of secounds
}Loading
stm32-bluepill
stm32-bluepill