本帖最后由 Ricky 于 2015-1-4 16:03 编辑
目录:
概述
PWM 参考函数
参考例程
1.概述
PWM是该模块的基础功能,Bluno M3板子上标有波浪号的端口都是PWM口(0, 1, 2, 3, 5, 6, 7, 8, 9, 11, 12 , 14, 27, 28, 35, 36, 37, 38),其中5、9、14是模拟,其他都是硬件定时器产生。
2.PWM 参考函数
analogWrite()
3.参考例程
- int ledPin = 0; // LED connected to digital pin 0
-
- void setup()
- {
- //nothing happens in setup
- }
- void loop() {
- // fade in from min to max in increments of 5 points:
- for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5)
- {
-
- analogWrite(ledPin, fadeValue); // sets the value (range from 0 to 255):
-
- delay(30); // wait for 30 milliseconds to see the dimming effect
- }
-
- // fade out from max to min in increments of 5 points:
- for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5)
- {
- analogWrite(ledPin, fadeValue); // sets the value (range from 0 to 255):
-
- delay(30); // wait for 30 milliseconds to see the dimming effect
- }
- }
-
复制代码
|