embedded system Q3

Dependencies:   mbed

Committer:
liammchale
Date:
Sat Aug 08 11:42:12 2020 +0000
Revision:
1:92cc47cc4e16
Parent:
0:0955f54a0564
replaced /n with/r

Who changed what in which revision?

UserRevisionLine numberNew contents of line
liammchale 0:0955f54a0564 1 #include "mbed.h"//preprocessor command
liammchale 0:0955f54a0564 2
liammchale 0:0955f54a0564 3 Serial pc(USBTX,USBRX);//serial communication with teraterm via USBTX, USBRX
liammchale 0:0955f54a0564 4
liammchale 0:0955f54a0564 5 AnalogIn pot1(p19);//Analog pin associated with potentiometer 1
liammchale 0:0955f54a0564 6 AnalogIn pot2(p20);//Analog pin associated with potentiometer 2
liammchale 0:0955f54a0564 7 PwmOut red(p23);//Pulse width modulator(red)
liammchale 0:0955f54a0564 8 PwmOut green(p24);//Pulse width modulator(green)
liammchale 0:0955f54a0564 9 float pot1value;//float the value of pot1
liammchale 0:0955f54a0564 10 float pot2value;//float the value of pot2
liammchale 0:0955f54a0564 11
liammchale 0:0955f54a0564 12 int main(){//main program
liammchale 0:0955f54a0564 13 while (1) {
liammchale 0:0955f54a0564 14 red = pot1;
liammchale 0:0955f54a0564 15 green = pot2;
liammchale 0:0955f54a0564 16 pot1value = pot1.read();
liammchale 0:0955f54a0564 17 pot2value = pot2.read();
liammchale 1:92cc47cc4e16 18 pc.printf("pot1 = %.3f %.3fV | pot2 = %.3f %.3fV\r", pot1value,
liammchale 0:0955f54a0564 19 pot1value*3.3, pot2value, pot2value*3.3);
liammchale 0:0955f54a0564 20 //shows the current value of the poteniometers in the range 0-1,
liammchale 0:0955f54a0564 21 //also shows the voltage value
liammchale 0:0955f54a0564 22
liammchale 0:0955f54a0564 23 wait (0.5); //wait half a second
liammchale 0:0955f54a0564 24 }
liammchale 0:0955f54a0564 25 }