-
Dependencies: mbed
main.cpp@0:350c4c9c0047, 2017-05-23 (annotated)
- Committer:
- tunagonen
- Date:
- Tue May 23 13:31:17 2017 +0000
- Revision:
- 0:350c4c9c0047
potentiometer check;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tunagonen | 0:350c4c9c0047 | 1 | #include "mbed.h" |
tunagonen | 0:350c4c9c0047 | 2 | Serial pc(USBTX, USBRX); // to connect to pc |
tunagonen | 0:350c4c9c0047 | 3 | float resistor; // defining the variable resistor |
tunagonen | 0:350c4c9c0047 | 4 | AnalogIn mypotentiometer(A2); // getting anolog reading from the potentiometer |
tunagonen | 0:350c4c9c0047 | 5 | DigitalOut plus(PTE20) ; //output for 3.3 V |
tunagonen | 0:350c4c9c0047 | 6 | DigitalOut ground(PTE22) ; //output for the ground |
tunagonen | 0:350c4c9c0047 | 7 | |
tunagonen | 0:350c4c9c0047 | 8 | |
tunagonen | 0:350c4c9c0047 | 9 | int main() |
tunagonen | 0:350c4c9c0047 | 10 | { |
tunagonen | 0:350c4c9c0047 | 11 | while(1) { |
tunagonen | 0:350c4c9c0047 | 12 | plus = 1 ; // voltage in is 3.3 V |
tunagonen | 0:350c4c9c0047 | 13 | ground = 0 ; // ground is 0 V |
tunagonen | 0:350c4c9c0047 | 14 | resistor = (mypotentiometer); // reading from the potentiometer |
tunagonen | 0:350c4c9c0047 | 15 | if (resistor > 0.999 ) { //in order to get an exact array from 0 to 1 |
tunagonen | 0:350c4c9c0047 | 16 | resistor = 1 ; |
tunagonen | 0:350c4c9c0047 | 17 | } |
tunagonen | 0:350c4c9c0047 | 18 | wait(0.5); |
tunagonen | 0:350c4c9c0047 | 19 | pc.printf("%f \r\n", resistor); //to print into terminal |
tunagonen | 0:350c4c9c0047 | 20 | } |
tunagonen | 0:350c4c9c0047 | 21 | } |
tunagonen | 0:350c4c9c0047 | 22 | |
tunagonen | 0:350c4c9c0047 | 23 |