Hello.
I have:
- 2 shift registers with 16 LEDS with 220 ohms each (8 Red, 8 Green)
- 3 buttons connected to ONE analog pin, with resistors (1k, 2.2k, 10k) and 100k direct to ground.
Everything is working fine. When all LED are open. I can know all the values for the analog pin and know which button has been pressed.
Goal:
I can connect up to 8 servos to any digital pins. That I'll detect and light up the Red light for each servos connected. ( Red LED => 1 to 8)
My 3 buttons are:
- 2 buttons to control ONLY one servo (Left, Right).
- 1 button for selecting which servo to control. Based on how many servos are connected to digital pins.
So the Green LEDs will light up to 1 to 8, based on which servo i want to control.
My problem is:
- My 8 Red LED, can be 1 to 8 open. (Depends on how many digital pin is connected).
- My 8 Green LED, can be 1 to 8, depends on the button.
Each time a LED is open, the value of the analog pin is changing. So I can't find which button has been pressed.
I tried to find the voltage, and mapping from 0 to 1023. But the value is so small between each.
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
int btn_value = analogRead(A5);
float voltage = btn_value * (5.0 / 1023.0);
float mapping = mapfloat(voltage, 0.0, 5.0, 0.0, 1023.0);
RESULT:
NBLed: 1 Value: 608 Voltage: 2.97 Mapping: 608.00
NBLed: 2 Value: 606 Voltage: 2.96 Mapping: 606.00
NBLed: 3 Value: 605 Voltage: 2.96 Mapping: 605.00
NBLed: 4 Value: 602 Voltage: 2.94 Mapping: 602.00
NBLed: 5 Value: 601 Voltage: 2.94 Mapping: 601.00
NBLed: 6 Value: 600 Voltage: 2.93 Mapping: 600.00
NBLed: 7 Value: 596 Voltage: 2.91 Mapping: 596.00
NBLed: 8 Value: 597 Voltage: 2.92 Mapping: 597.00
NBLed: 9 Value: 595 Voltage: 2.91 Mapping: 595.00
NBLed: 10 Value: 594 Voltage: 2.90 Mapping: 594.00
NBLed: 11 Value: 592 Voltage: 2.89 Mapping: 592.00
NBLed: 12 Value: 591 Voltage: 2.89 Mapping: 591.00
NBLed: 13 Value: 590 Voltage: 2.88 Mapping: 590.00
NBLed: 14 Value: 588 Voltage: 2.87 Mapping: 588.00
NBLed: 15 Value: 587 Voltage: 2.87 Mapping: 587.00
NBLed: 1 Value: 608 Voltage: 2.97 Mapping: 608.00
NOTE: My voltage is low, because I added more resistor to the ground. (It was shifting without any button). The 100k was not enough.
- I tried to add a tolerence between each value.
- I tried to add a drop voltage, when X red LED and Y green LED, are high.
Can someone help me? Any one have a idea how to find the values?
Thanks
NLT

