In the past, bus tickets were sold by conductors on the bus. Whenever there is rush hour in the morning and evening, the bus is always crowded with people, and it becomes a hassle for the conductor to collect and change.
With the development of science and technology, the smart bus ticketing machine on the unmanned ticket vending vehicle has brought a lot of convenience to our lives. You can swipe your card or insert a coin directly. After the card payment is successful, you will hear the corresponding prompt "standard card", or "student card". Different cards correspond to different charging standards.
Now, let's make a smart bus card machine! How can we achieve the function of swiping a card and then deduce money from it?
1. Learn the working principle and application field of two-dimensional code technology
2. Learn the two-dimensional code recognition function of HUSKYLENS
3. Use the two-dimensional code recognition function of HUSKYLENS to make a smart bus ticketing machine.
Carefully observe the process of using the card, you will find that as long as the bus card is close to the machine, your money in the card will be automatically deducted. Different cards correspond to different charging standards. So as long as we find alternatives for card devices and cards, the project can be realized.
Ticketing machine—Two-dimensional code recognition function of HUSKYLENS
Bus card—Cards with two-dimensional code
Two-dimensional codes are also called two-dimensional barcodes. There are many types of two-dimensional codes. The common two-dimensional code, QR Code, which refers to Quick Response, is a popular encoding mode on mobile devices. QR code can store more information, and can also represent more data types than traditional two-dimensional codes.
In fact, the two-dimensional code is not mysterious. It mainly converts information into small black and white squares, and then fills them into a large square. How information and squares correspond to each other? Here we have to mention an invention of age---binary.
Through the binary system, each word, number, and symbol are "translated" into a string of "0" and "1". Use white squares to represent "0" and black squares to represent "1". Then arrange these white and black squares according to a specific rule to obtain a two-dimensional code. The essence of a two-dimensional code is to convert information (data) into a binary code, and then fill the binary code into this large square.
From the picture above, we can see that there are black squares in the upper right corner, upper left corner, and lower left corner of the QR code. What are these three squares used for? They are used for positioning, so that the information recorded in the QR code can be accurately identified whether you scan the code horizontally or vertically. Compared with the horizontal direction of the barcode, the two-dimensional code records information in two dimensions, increasing the amount of information storage.
The two-dimensional code is widely used in daily life, you can scan it to pay, enter a website, and so on.
Many restaurants have adopted the form of QR code electronic menu. Consumers can see the introduction and price of related dishes as long as they enter the online menu by scanning a QR code.
The QR code can also be made into an electronic coupon, and the user can obtain the coupon or check which products are discounted by scanning it.
You can check the product production place by scanning the code.
Question: Do you also know that where are QR codes are used? Or do you think where can QR codes be used?
When HUSKYLENS detects QR codes, all the detected QR codes will be automatically selected by orange frames.
Next, make HuskyLens learn and recognize the standard card and student card.
Point the "+" symbol at the QR code, long or short press the "Learning button" to complete the first code learning. After releasing the "Learning button", the screen will display: "Press the button again to continue! Press other buttons to end. " To continue learning the next code, press the "Learning button" before the countdown ends. If you no longer need to learn other codes, press the "Function button" before the countdown ends, or do not operate and wait for the end of the countdown.
In this project, we are going to learn multiple QR codes. Therefore, we need to short press the “Learning Button” before the countdown ends. Then, point the “+” at the second QR code, pressing or holding the “Learning Button” to complete this learning. And so on.
The code ID is in the same order as the code entered. That is, the learned codes will be tagged as "background: ID1", " background: ID2", " background: ID3", and so on. Moreover, different codes correspond to different frame colors.
When the HUSKYLENS encounters the learned QR codes again, there will be a colored frame to select them and display their IDs on the screen. The size of the frame can change with the size of QR codes and track them automatically.
The voice recorder module is an audio module that integrates recording and playback functions. There are buttons and microphones onboard, you can directly record your voice by pressing the record button, speaking and then releasing the button when finished.
Note: The voice recorder module can realize audio recording within 10s. When you release the button or reach 10s, the red LED on the board will flash once.
In the project, the voice recorder module needs to be used with the stereo enclosed speaker. The stereo enclosed speaker is used to play the pre-recorded audio, which makes our work greater. How to use the voice recorder module? Let's try it together next!
First learn how to use the voice recorder module to record and play sounds. The use of the voice recorder module with stereo enclosed speaker is very simple. No programming is required. Power up the module, then you are ready to go!
Note: When recording, the IO expansion board needs to be powered.
There is an "RCE" recording button on the voice recorder module. Press this button to start recording, and release the button to end the recording. Next, record an audio by yourself, the audio content is "Payment successful, get in please."
Press the "PLAY" button, and the stereo enclosed speaker will play the recorded audio. Each time you press the "PLAY" button, the audio will be played (press once to play the entire audio). After the playback is over, the red LED on the voice recorder flashes once.
We will finish the project in two steps. First, use multiple QR codes recognition function of HUSKYLENS to learn and recognize the bus cards with QR codes, and then display the fees that should be paid for each card on the HUSKYLENS screen.
Based on the previous step, the balance display and voice broadcast functions are added. Each time the card is successfully recognized, the corresponding fee will be subtracted from the balance, and then the voice broadcast " Payment successful, get in please.", which basically realizes the function of the ticketing machine.
Task1: Charge by cards
HUSKYLENS learns and recognizes the bus card with a QR code. Write a program to display the fee on the HUSKYLENS screen.
Task 2: Voice broadcast " Payment successful, get in please."
On the basis of task 1, the balance display and voice broadcast function are added. When the learned bus card is recognized, the voice broadcast is performed. It is assumed that each card is charged with 20 yuan, and the corresponding fee will be deducted on the basis of the remaining fee once the payment is successful.
Different types of bus cards, such as student cards, and standard cards are designed for different groups of people. Each type of bus card corresponds to a charging standard (take 2 yuan as an example, the charging standard and discount can be modified by yourself).
Before designing the program, it has defaulted that HUSKYLENS has learned different bus cards (for specific operations, please refer to the demonstration of HUSKYLENS QR code recognition function).
When a certain kind of card is recognized, the corresponding fee to be deducted will be displayed on the HUSKYLENS screen. The mid-note Do played in the program is mainly used as a reminder. As shown in the figure, the student card pays 1 yuan, and the standard card pays 1.5 yuan.
In this task, I take the elderly card as an example, and add two new functions on the basis of task 1: When the HUSKYLENS camera recognizes the QR code bus card, the voice broadcast "Payment successes, get in please.", and the fee and the balance will be displayed on the screen.
Homework: The following flowchart and program only realize the function of the student card, the rest of the standard cards need to be realized by yourself!
After HUSKYLENS successfully recognizes the QR code bus card, it will play " Payment successful, get in please." and then display the fee and the balance in the card on the screen.
This project mainly uses QR code recognition technology to recognize the corresponding bus card type and output the corresponding ID. Then calculate the fees through different charging standards, so as to realize charging different types of cards according to different payment standards. In Task 2, the functions of voice broadcast and balance display are also added, which simulates the working principle of the smart bus ticketing machine.
Although there is a balance display function of the smart bus card machine project, when the balance in the card is insufficient, there is no notification. How to remind users when the balance is insufficient?
Note: You need to use conditional judgment statements to judge the balance, use a buzzer to prompt according to the judgment result, or use an audio module+a passive speaker.