I'm trying to take an analogin signal (0 to 3.3V) and turn a digitalout and an LED on or off based on the analogin signal.
If the analogin signal is below 0.9V,(0.9/3.3 = 0.27) I want led4 to turn on and I want pin 24 to go high. If the analog signal is above 3V, (3/3.3 = 0.92) then I want led3 to turn on and pin 25 to go high. If the voltage is between 0.9 and 3V, then I want neither the leds nor pins 24 and 25 on.
The code I've written is below. The final product will be more complicated and have more function than this, but the problem I'm having at this point is that the leds and the outputs are flickering. My mbed is powered by an external 5V power supply with a 0.1uF tantalum capacitor and a 2200uF capacitor across the terminals to smooth out the power supply.
Pins 24 and 25 are connected to 1200 ohm resistors going to the base leg of a 2N2222A transistor to switch the voltage higher for input to a motor controller, but the results are unpredictable based on the flickering LEDs and output on pins 24 and 25.
I can capture the analogin signal. It's a nice smooth sinusoidal-esque signal. It does not fluctutate rapidly above the thresholds set for the output pins and leds.
What can I do to stop the erratic flickering?
//EBRGT9
#include "mbed.h"
AnalogIn loadright(p16);
DigitalOut right1(p25);
DigitalOut right2(p24);
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
int main() {
led1=led2=led3=led4=0;
right1=right2=0;
wait(0.5);
wait (1);
led1=1;
wait(0.1);
led2=1;
wait(0.1);
led1=0;;
led3=1;
wait(0.1);
led4=1;
led2=0;
wait(0.1);
led3=0;
wait(0.1);
led4=0;
if (loadright <0.27){
right2=led4=1;
right1=led3=0;
wait(0.1);
}
else if (loadright >0.92){
right1=led3=1;
right2=led4=0;
}
else led1=led2=led3=led4=left1=left2=right1=right2=0;
}
}
I'm trying to take an analogin signal (0 to 3.3V) and turn a digitalout and an LED on or off based on the analogin signal.
If the analogin signal is below 0.9V,(0.9/3.3 = 0.27) I want led4 to turn on and I want pin 24 to go high. If the analog signal is above 3V, (3/3.3 = 0.92) then I want led3 to turn on and pin 25 to go high. If the voltage is between 0.9 and 3V, then I want neither the leds nor pins 24 and 25 on.
The code I've written is below. The final product will be more complicated and have more function than this, but the problem I'm having at this point is that the leds and the outputs are flickering. My mbed is powered by an external 5V power supply with a 0.1uF tantalum capacitor and a 2200uF capacitor across the terminals to smooth out the power supply. Pins 24 and 25 are connected to 1200 ohm resistors going to the base leg of a 2N2222A transistor to switch the voltage higher for input to a motor controller, but the results are unpredictable based on the flickering LEDs and output on pins 24 and 25.
I can capture the analogin signal. It's a nice smooth sinusoidal-esque signal. It does not fluctutate rapidly above the thresholds set for the output pins and leds. What can I do to stop the erratic flickering?