Biorobotics_group_2
/
PWM_LED
Adjust the brightness of a LED using potmeter input and FastPWM output
Diff: main.cpp
- Revision:
- 0:fe2a62ab1017
- Child:
- 1:db6539dc8ea9
diff -r 000000000000 -r fe2a62ab1017 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Oct 07 09:41:40 2016 +0000 @@ -0,0 +1,43 @@ +#include "mbed.h" +#define SERIAL_BAUD 115200 // baud rate for serial communication +#include "FastPWM.h" + +// This program controlls the brightness of a LED using PWM with the potmeter as input + +// Serial connection with PC +Serial pc(USBTX,USBRX); + +// Led +FastPWM led(D7); + +// PotmeterIn +AnalogIn pot(A0); + +// Initial duty value and period +volatile float duty = 0.0; +volatile float frequency = 100.0; +const int Timeset_duty_cycle = 1000; + +void set_dutycycle() { + duty=pot.read(); + pc.printf("\r\n Potvalue = %f \r\n",duty); + led.write(duty/3); + } + +int main() +{ + // Set baud connection with PC + pc.baud(SERIAL_BAUD); + pc.printf("\r\n ***THERMONUCLEAR WARFARE COMMENCES*** \r\n"); + + // Make tickers and attach + Ticker tick_set_brightness; + tick_set_brightness.attach(set_dutycycle,1/Timeset_duty_cycle); + + // Set period of LED + led.period(1.0/frequency); + + while(true){ + + }; +} \ No newline at end of file