Ciaran O'Malley
/
LAB_2_2_PotEx
Lab exercise 2.2 Potentiometers experiment
main.cpp@1:1bb7bf26a054, 2020-06-20 (annotated)
- Committer:
- ciaranom
- Date:
- Sat Jun 20 14:27:59 2020 +0000
- Revision:
- 1:1bb7bf26a054
- Parent:
- 0:9f16c71a1120
Added comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ciaranom | 0:9f16c71a1120 | 1 | #include "mbed.h" |
ciaranom | 0:9f16c71a1120 | 2 | #include "C12832.h" |
ciaranom | 0:9f16c71a1120 | 3 | |
ciaranom | 0:9f16c71a1120 | 4 | PwmOut led1(LED1); |
ciaranom | 0:9f16c71a1120 | 5 | AnalogIn pot1(p19); |
ciaranom | 0:9f16c71a1120 | 6 | C12832 lcd(p5, p7, p6, p8, p11); |
ciaranom | 1:1bb7bf26a054 | 7 | float pot1val; //creating floating number o be read and printed |
ciaranom | 0:9f16c71a1120 | 8 | |
ciaranom | 0:9f16c71a1120 | 9 | int main() { |
ciaranom | 0:9f16c71a1120 | 10 | while(1) { |
ciaranom | 1:1bb7bf26a054 | 11 | led1 = pot1; // sets output of led1 to the output of pot1 |
ciaranom | 0:9f16c71a1120 | 12 | wait(0.01); |
ciaranom | 0:9f16c71a1120 | 13 | |
ciaranom | 0:9f16c71a1120 | 14 | |
ciaranom | 0:9f16c71a1120 | 15 | pot1val = pot1*100; |
ciaranom | 0:9f16c71a1120 | 16 | |
ciaranom | 1:1bb7bf26a054 | 17 | lcd.cls(); // clear screen |
ciaranom | 1:1bb7bf26a054 | 18 | wait(.1); // allows time for screen to clear |
ciaranom | 1:1bb7bf26a054 | 19 | lcd.locate(0,0); // lets the location on EDC where to begin printing |
ciaranom | 1:1bb7bf26a054 | 20 | lcd.printf("Pot1 value: %.4f %%", pot1val); //prints value of potentiometer |
ciaranom | 1:1bb7bf26a054 | 21 | wait(1); // holds image on screen for 1 second before screen is clealed |
ciaranom | 0:9f16c71a1120 | 22 | |
ciaranom | 1:1bb7bf26a054 | 23 | lcd.cls(); // clears screen |
ciaranom | 1:1bb7bf26a054 | 24 | wait(.1); // allows time for screen to clear |
ciaranom | 1:1bb7bf26a054 | 25 | lcd.locate(0,0);; // lets the location on EDC where to begin printing |
ciaranom | 1:1bb7bf26a054 | 26 | lcd.printf("Pot1 value: %.4e", pot1.read()); //prints value of potentiometer |
ciaranom | 1:1bb7bf26a054 | 27 | wait (1); // holds image on screen for 1 second before screen is clealed |
ciaranom | 0:9f16c71a1120 | 28 | |
ciaranom | 0:9f16c71a1120 | 29 | |
ciaranom | 0:9f16c71a1120 | 30 | } |
ciaranom | 0:9f16c71a1120 | 31 | } |