Simple combination of the buzzer of 51 single-chip microcomputer and LED water lamp

First, let's take a look at the schematic.
Insert picture description here
Insert picture description here
The buzzer bz1 is then pulled up to high level, so if you want the buzzer to sound, you must connect the bz port to low level. (The bz port of the buzzer is connected to the P1^5 port of the microcontroller)
The following is a code example:
Insert picture description here
the actual result of the code, the LED lights turn on from d1 to d8, and then turn on from d8 to d1. Each time the light moves, the buzzer sounds The device will ring once, 16 times in a loop. Among them, beep=~beep is placed in different positions, and the results are different. We can determine how many times the LED lights up by how many times the buzzer sounds.
Insert picture description here
For example: put beep=~beep at the beginning of while(1), and the result is that the LED from d1 to d8 is from d8 to d1, and the buzzer only sounds once, once in total. By how many times the buzzer has sounded, you can determine when the running water lamp starts to work.

Guess you like

Origin blog.csdn.net/weixin_43789635/article/details/85602873