Using mbed with external input
Progressed to using mbed to accept an external stimulus to control brightness of the led. The stimulus was a simple voltage applied from a 1.5V batt. connected to a 5K pot. But this is the first step to using the mbed for more complex control in a closed loop system to generate a PWM signal. The code is unbelievably simple:
#include "mbed.h"
AnalogIn ain(p20);
PwmOut led(LED1);
int main() {
while(1){
//read the value of pin 20 as a percentage of max voltage which is 3.3V.
//so 0V->0.0%
// 1V->30.3%
// 1.5V->45.45%
float varf = ain.read();
//use the %age of voltage value read in as the setting for
//output of PWM.
led = varf;
wait_ms(0.01);
}
} //main
Next experiment is to light up other leds as the voltage is increased.
11/18/10:
Made further improvements to my simple PWM program controllable by a pot. Set the lower limit of duty-cycle to 10% so that I don't go to zero D. Tested this out by printing actual analog value at the pin and the value passed to LED1.
Next steps:
Format the data going to tera term a bit more nicely.
Figure out a way to stop the system when the reset button is pressed. This will need some understanding of interrupts.
Apply this PWM output to drive a FET using a gate driver.
0 comments
You need to log in to post a comment