티스토리 뷰
728x90
출처
BPI-Bit : 부저 사용하기
BPI-Bit에는 사운드 출력을 위한 부저 모듈이 내장 되어 있습니다. 예제를 통해서 간단하게 부저로 사운드를 출력해보겠습니다.
GPIO control of BPI:bit
GPIO control of BPI:bit | |||
Light Sensor(L) | GPIO 36 | Analog Input | |
Light Sensor(R) | GPIO 39 | Analog Input | |
Botton A | GPIO 35 | Digital Input | |
Botton B | GPIO 27 | Digital Input | |
Temperature Sensor | GPIO 34 | Analog Input | |
Buzzer | GPIO 25 | PWM(Digital Output) / Analog Output | |
RGB_LED | GPIO 4 | Digital Output | |
MPU9250_SCL | GPIO 22 | Digital Output | |
MPU9250_SDA | GPIO 21 | Digital Output | |
MPU9250_INT | GPIO 16 | Digital Input | |
R_LED(SPI_SCK) | GPIO 18 | Digital Output |
예제 소스
int adTestFreq = 0; int BuzzerTestFreq = 0; int brightness = 0; int fadeAmount = 5; //buzzer config #define Buzzer 25 #define LEDC_CHANNEL_0 0 #define LEDC_TIMER_13_BIT 13 #define LEDC_BASE_FREQ 450 #define bout 3 /***************************************************************** * Function :ledcAnalogWrite * * Input Parameter :channel / value * * Output Parameter:None * * Features :Match value to channel and convert to duty * ****************************************************************/ void ledcAnalogWrite(uint8_t channel, uint32_t value) { // calculate duty, 8191 from 2 ^ 13 - 1 (2 ^ LEDC_TIMER_13_BIT - 1) //value_MAX = 255 uint32_t duty = (8191 / 255) * value; // write duty to LEDC ledcWrite(channel, duty); } void setup() { Serial.begin(115200); //Serial Port Config 115200-8-N-1 ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_13_BIT); ledcAttachPin(Buzzer, LEDC_CHANNEL_0); } void loop() { /***************************** ***Function:Buzzer Test *** ****************************/ Serial.println(); Serial.println("Buzzer Test!!!"); Serial.println("Buzzer is fading"); for (BuzzerTestFreq = 0; BuzzerTestFreq < bout; BuzzerTestFreq++) { for (brightness = 0; brightness < 255; brightness++) { Serial.print("."); // set the brightness on LEDC channel 0 ledcAnalogWrite(LEDC_CHANNEL_0, brightness); // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness <= 0 || brightness >= 255) { fadeAmount = -fadeAmount; } // wait for 30 milliseconds to see the dimming effect delay(30); } Serial.println(); ledcAnalogWrite(LEDC_CHANNEL_0, 0); } delay(1000); }
실행 결과
댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- android
- NDK
- ffmpeg
- 튜닝쇼 2008
- 송주경
- SAS
- koba2010
- Delphi
- Spring
- flex
- Delphi Tip
- ubuntu
- BPI-M4
- ble
- 서울오토살롱
- 레이싱모델 익스트림 포토 페스티벌
- Xcode
- JavaScript
- KOBA
- Java
- 지스타2007
- 동경
- 전예희
- sas2009
- oracle
- 일본여행
- Spring MVC
- Mac
- MySQL
- Linux
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
글 보관함