lab2 part5

Dependencies:   Servo mbed

Committer:
m162568
Date:
Wed Sep 03 19:49:24 2014 +0000
Revision:
0:27be254c7ddc
lab 2 part 5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
m162568 0:27be254c7ddc 1 #include "mbed.h"
m162568 0:27be254c7ddc 2 #include "Servo.h"
m162568 0:27be254c7ddc 3 Serial pc(USBTX, USBRX);
m162568 0:27be254c7ddc 4
m162568 0:27be254c7ddc 5 int main() {
m162568 0:27be254c7ddc 6
m162568 0:27be254c7ddc 7 pc.baud(921600); //set the baud rate to 921600
m162568 0:27be254c7ddc 8 float x,y; //creates variables
m162568 0:27be254c7ddc 9 AnalogIn an(p15); // sets pin15 as an analogin
m162568 0:27be254c7ddc 10 PwmOut sm(p21); // sets pin21 as a PwmOut
m162568 0:27be254c7ddc 11
m162568 0:27be254c7ddc 12 while(1)
m162568 0:27be254c7ddc 13 {
m162568 0:27be254c7ddc 14 x=an.read(); // read in the value off an
m162568 0:27be254c7ddc 15 y=x*3.3; // convert to associated voltage
m162568 0:27be254c7ddc 16 printf("The analog data value is %f, and the associated voltage is %f\n",x, y);
m162568 0:27be254c7ddc 17 sm=x; //set the PwmOut, sm, to the value read off of an.
m162568 0:27be254c7ddc 18 wait(.1);
m162568 0:27be254c7ddc 19 }
m162568 0:27be254c7ddc 20 }