![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Using potentiometer to alter an onboard LED brightness and outputting the analog value of the pot to an LCD display
main.cpp@0:5c32b2d13fa7, 2020-07-31 (annotated)
- Committer:
- saltire78
- Date:
- Fri Jul 31 12:29:26 2020 +0000
- Revision:
- 0:5c32b2d13fa7
online posting
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
saltire78 | 0:5c32b2d13fa7 | 1 | #include "mbed.h" |
saltire78 | 0:5c32b2d13fa7 | 2 | #include "C12832.h" |
saltire78 | 0:5c32b2d13fa7 | 3 | |
saltire78 | 0:5c32b2d13fa7 | 4 | PwmOut led1(LED1); |
saltire78 | 0:5c32b2d13fa7 | 5 | AnalogIn pot1(p19); |
saltire78 | 0:5c32b2d13fa7 | 6 | C12832 lcd(p5, p7, p6, p8, p11); |
saltire78 | 0:5c32b2d13fa7 | 7 | |
saltire78 | 0:5c32b2d13fa7 | 8 | int main(){ |
saltire78 | 0:5c32b2d13fa7 | 9 | while(1) { |
saltire78 | 0:5c32b2d13fa7 | 10 | led1= pot1; |
saltire78 | 0:5c32b2d13fa7 | 11 | lcd.locate(0,0); |
saltire78 | 0:5c32b2d13fa7 | 12 | lcd.printf("Pot 1 = %.2f\n", pot1.read()); |
saltire78 | 0:5c32b2d13fa7 | 13 | lcd.printf("Pot 1 = %.2e\n", pot1.read()); |
saltire78 | 0:5c32b2d13fa7 | 14 | wait(0.01); |
saltire78 | 0:5c32b2d13fa7 | 15 | } |
saltire78 | 0:5c32b2d13fa7 | 16 | } |