Raspberry Pi Buzzer Control
네오즈 · 2019-09-27 · 4
```json
{
"time": 1717347247544,
"blocks": [
{
"id": "QW6Xlk_uA5",
"type": "headerAlign",
"data": {
"text": "1. BUZZER Test Circuit Configuration",
"level": 4,
"alignment": "left"
}
},
{
"id": "UzJGSYwMzi",
"type": "simpleImage",
"data": {
"url": "http://192.168.10.9:3000/img_e4dsmake/ck/8T9ORHMN2ACGUFP7KT63.png",
"caption": "",
"withBorder": false,
"withBackground": false,
"stretched": false
}
},
{
"id": "wh2U1xBMLa",
"type": "paragraph",
"data": {
"text": "Buzzer : Connected to GPIO 1"
}
},
{
"id": "WvuMWH0WDG",
"type": "headerAlign",
"data": {
"text": "2. BUZZER Test Python Code",
"level": 4,
"alignment": "left"
}
},
{
"id": "a5Il9J8RsH",
"type": "paragraph",
"data": {
"text": "For code writing and execution methods, refer to the \"Raspberry Pi GPIO Port (LED, Button) Control\" guide"
}
},
{
"id": "KvzCG7TX81",
"type": "paragraph",
"data": {
"text": "Code that outputs the musical scale \"do, re, mi, fa, sol, la, ti, do\" through the buzzer using PWM."
}
},
{
"id": "os6ngMQi9c",
"type": "code",
"data": {
"code": "import RPi.GPIO as GPIO # Use functionality defined in RPi.GPIO with the name GPIO\nimport time # time module\n\nGPIO.setmode(GPIO.BCM) # Use BCM naming for GPIO names\n\nbuzz = 1 # Substitute pin number 1 with the name buzz\nGPIO.setup(buzz, GPIO.OUT) # Set GPIO buzz pin (1) as output\n\nfreq = [523,587,659,698,784,880,988,1047] # freq list (musical scale frequency list)\n\ndef makeTone(freq): # Define makeTone function that takes freq as parameter\n\tscale = GPIO.PWM(buzz, freq) # Define scale that generates PWM waveform at freq (Hz) on buzz pin\n\tscale.start(10) # Start scale\n\ttime.sleep(0.5) # Wait 0.5 seconds\n\tscale.stop() # Stop scale (end of makeTone function definition)\n\ntry:\n\n\tfor x in freq: # Start loop for freq list\n\t\tmakeTone(x) # Pass freq to makeTone function\n\tGPIO.cleanup() # Clear GPIO-related settings\n\nexcept KeyboardInterrupt: # When Ctrl-C is pressed\n\tGPIO.cleanup() # Clear GPIO-related settings\n"
}
}
],
"version": "2.30.5"
}
```
4
댓글 0개
등록된 댓글이 없습니다.