![](/media/cache/profiles/cf25c9a7182456585c8dcdc4782e97bf.jpg.50x50_q85.jpg)
Two LEDS connected on chanel 0 and 1 that change their brightness continually.
main.cpp@1:812d6effcc5f, 2015-07-24 (annotated)
- Committer:
- dreamworker
- Date:
- Fri Jul 24 09:49:38 2015 +0000
- Revision:
- 1:812d6effcc5f
- Parent:
- 0:46968a9b2b95
Test program for PCA9685 library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreamworker | 0:46968a9b2b95 | 1 | /*Test program for PCA9685 library |
dreamworker | 1:812d6effcc5f | 2 | *Two leds connected on chanel 0 and 1 that change their brightness continually |
dreamworker | 0:46968a9b2b95 | 3 | */ |
dreamworker | 0:46968a9b2b95 | 4 | #include"PCA9685.h" |
dreamworker | 0:46968a9b2b95 | 5 | #include"mbed.h" |
dreamworker | 0:46968a9b2b95 | 6 | |
dreamworker | 0:46968a9b2b95 | 7 | |
dreamworker | 0:46968a9b2b95 | 8 | |
dreamworker | 0:46968a9b2b95 | 9 | PCA9685 pwm(D14,D15); |
dreamworker | 0:46968a9b2b95 | 10 | |
dreamworker | 0:46968a9b2b95 | 11 | |
dreamworker | 0:46968a9b2b95 | 12 | void initDriver() { |
dreamworker | 0:46968a9b2b95 | 13 | pwm.begin(); |
dreamworker | 0:46968a9b2b95 | 14 | pwm.setPWMFreq(1600); // max frequency |
dreamworker | 0:46968a9b2b95 | 15 | pwm.frequencyI2C(400000); //400kHz fast I2C comunication |
dreamworker | 0:46968a9b2b95 | 16 | } |
dreamworker | 0:46968a9b2b95 | 17 | |
dreamworker | 0:46968a9b2b95 | 18 | int main() { |
dreamworker | 0:46968a9b2b95 | 19 | initDriver(); |
dreamworker | 0:46968a9b2b95 | 20 | |
dreamworker | 0:46968a9b2b95 | 21 | while(1){ |
dreamworker | 0:46968a9b2b95 | 22 | for (int i = 0; i < 4095; i=i+8){ |
dreamworker | 0:46968a9b2b95 | 23 | pwm.setPWM(0,4095-i,0); |
dreamworker | 0:46968a9b2b95 | 24 | wait(0.0005); |
dreamworker | 0:46968a9b2b95 | 25 | pwm.setPWM(1,i,0); |
dreamworker | 0:46968a9b2b95 | 26 | wait(0.0005); |
dreamworker | 0:46968a9b2b95 | 27 | } |
dreamworker | 0:46968a9b2b95 | 28 | for (int i = 4094; i > 0; i=i-8){ |
dreamworker | 0:46968a9b2b95 | 29 | pwm.setPWM(0,4095-i,0); |
dreamworker | 0:46968a9b2b95 | 30 | wait(0.0005); |
dreamworker | 0:46968a9b2b95 | 31 | pwm.setPWM(1,i,0); |
dreamworker | 0:46968a9b2b95 | 32 | wait(0.0005); } |
dreamworker | 0:46968a9b2b95 | 33 | } |
dreamworker | 0:46968a9b2b95 | 34 | } |