First, let's take a look at the schematic.
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:
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.
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.
Simple combination of the buzzer of 51 single-chip microcomputer and LED water lamp
Guess you like
Origin blog.csdn.net/weixin_43789635/article/details/85602873
Recommended
Ranking