Skip to content

Commit

Permalink
Modify the diagram and code analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
xiemeiping committed Sep 22, 2023
1 parent ea7ec21 commit 5174c62
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ or an adept learner seeking to deepen your knowledge, this kit is tailored to me

<a id="update"></a>
## Update:
2023-09-22:
- Modify the diagram and code analysis of 3.1_Reversing_Aid.

2023-08-17:
- Modify certain project content that requires libraries.

Expand Down
61 changes: 47 additions & 14 deletions docs/source/arduino/3.1_Reversing_Aid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,53 @@ Code
Example Explanation
---------------------------

In this project, we need to avoid the interference between the LCD
screen and the alarm system as much as possible (for example, the LED
flicker time is too long and the LCD refresh is delayed), so please
avoid using the delay() statement and use two separate intervals to
control the working frequency of the LCD and alarm system respectively.
Its workflow is shown in the flow chart. For analysis of Interval
function, refer to :ref:`ar_interval`.

.. image:: img/Part_three_1_Example_Explanation.png
:align: center
This code helps us create a simple distance measuring device that can measure the distance between objects and provide feedback through an LCD display and a buzzer.

Phenomenon Picture
-------------------------
The ``loop()`` function contains the main logic of the program and runs continuously. Let's take a closer look at the ``loop()`` function.

.. image:: img/image267.jpeg
:align: center
#. Loop to read distance and update parameters

In the ``loop``, the code first reads the distance measured by the ultrasonic module and updates the interval parameter based on the distance.

.. code-block:: arduino
// Update the distance
distance = readDistance();
// Update intervals based on distance
if (distance <= 10) {
intervals = 300;
} else if (distance <= 20) {
intervals = 500;
} else if (distance <= 50) {
intervals = 1000;
} else {
intervals = 2000;
}
#. Check if it's time to beep

The code calculates the difference between the current time and the previous beep time, and if the difference is greater than or equal to the interval time, it triggers the buzzer and updates the previous beep time.

.. code-block:: arduino
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= intervals) {
Serial.println("Beeping!");
beep();
previousMillis = currentMillis;
}
#. Update LCD display

The code clears the LCD display and then displays "Dis:" and the current distance in centimeters on the first line.

.. code-block:: arduino
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Dis: ");
lcd.print(distance);
lcd.print(" cm");
delay(100);
Binary file modified docs/source/arduino/img/Part_three_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5174c62

Please sign in to comment.