-

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 Serial pc(USBTX, USBRX); // to connect to pc
00003 float resistor; // defining the variable resistor 
00004 AnalogIn mypotentiometer(A2); // getting anolog reading from the potentiometer
00005 DigitalOut plus(PTE20) ; //output for 3.3 V
00006 DigitalOut ground(PTE22) ; //output for the ground
00007 
00008 
00009 int main()
00010 {
00011     while(1) {
00012         plus = 1 ; // voltage in is 3.3 V
00013         ground = 0 ; // ground is 0 V
00014         resistor = (mypotentiometer); // reading from the potentiometer
00015         if (resistor > 0.999 ) { //in order to get an exact array from 0 to 1
00016             resistor = 1 ;
00017             }
00018         wait(0.5); 
00019         pc.printf("%f \r\n", resistor); //to print into terminal
00020     }
00021 }
00022     
00023