Question: Can you make a flowchart for this code in draw.io format? #include / / Libraries that allow I 2 C communication #include / / Libraries

Can you make a flowchart for this code in draw.io format?
#include // Libraries that allow I2C communication
#include // Libraries for controlling the LCD with an I2C interface
LiquidCrystal_I2C lcd(0x27,16,2); // Creates an LCD object using the I2C address 0x27 with dimensions of 16 columns and 2 rows.
#define trigPin A0// Sensor Trig pin connected to Arduino pin A0
#define echoPin A1// Sensor Echo pin connected to Arduino pin A1
#define buttonPin 2// Pushbutton pin
#define onboardLED 13// Onboard LED pin
#define potPin A2// Potentiometer pin
#define externalLED 12// External LED pin
long distanceInch; // Global variable to store the measured distance
int ledBlinkRate; // Variable for LED blink rate based on potentiometer
bool isPaused = false; // State of the pause functionality
void setup(){
pinMode(trigPin, OUTPUT); // Sends pulse signal
pinMode(echoPin, INPUT); // Receives the reflected signal
pinMode(buttonPin, INPUT_PULLUP); // Pushbutton input with pull-up resistor
pinMode(onboardLED, OUTPUT); // Onboard LED output
pinMode(externalLED, OUTPUT); // External LED output
pinMode(potPin, INPUT); // Potentiometer input
lcd.init(); // Initializes the LCD
lcd.backlight(); // Turns on the backlight
lcd.clear(); // Clears any previous content
lcd.setCursor(0,0);
lcd.print("Simple Circuits"); // Displays "Simple Circuits"
delay(2000);
lcd.clear(); // Clears screen
lcd.setCursor(0,0); // Set LCD cursor to upper left corner, column 0, row 0
lcd.print("Distance:"); // Print message on the first row
lcd.setCursor(0,1);
lcd.print("Distance:");
}
void loop(){
// Check the pushbutton state
if (digitalRead(buttonPin)== LOW){// Button pressed (LOW because of INPUT_PULLUP)
if (!isPaused){
pauseDistanceMeasurement();
isPaused = true;
}
} else {
if (isPaused){
resumeDistanceMeasurement();
isPaused = false;
}
}
if (!isPaused){
measureDistance(); // Callable function to measure and display distance
ledBlinkRate = analogRead(potPin)/4; // Read potentiometer and scale to delay range (0-255)
controlExternalLED(); // Callable function to control LED based on distance
}
}
void measureDistance(){
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance =(duration /2)/29.1;
distanceInch = duration *0.0133/2;
lcd.setCursor(9,0);
lcd.print("");
lcd.setCursor(9,0);
lcd.print(distance); // Print measured distance
lcd.print(" cm"); // Print your units.
lcd.setCursor(9,1);
lcd.print(""); // Print blanks to clear the row
lcd.setCursor(9,1);
lcd.print(distanceInch);
lcd.print(" inch"); // Print your units.
delay(200); // Pause to let things settle
}
void controlExternalLED(){
int distanceThreshold = analogRead(potPin)/4; // Potentiometer sets the threshold
if (distanceInch < distanceThreshold){
digitalWrite(externalLED, HIGH); // Turn on the LED if distance is below threshold
} else {
digitalWrite(externalLED, LOW); // Turn off the LED if distance is above threshold
}
}
void pauseDistanceMeasurement(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Paused"); // Display paused message
digitalWrite(onboardLED, HIGH); // Turn on the onboard LED while paused
}
void resumeDistanceMeasurement(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Distance:"); // Restore the distance message
lcd.setCursor(0,1);
lcd.print("Distance:");
digitalWrite(onboardLED, LOW); // Turn off the onboard LED
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!