Hope this is the right forum section!
So I made a multiple button analog input using this guide:
https://rayshobby.net/wordpress/multiple-button-inputs-using-arduino-analog-pin/
I am using a proMicro as my controller to run some LEDs. When the USB cable is plugged in and attached to the PC, everything works fine. However, when I unplug the USB cable, it seems my analog '0' value is more around 80-100. Can't verify easily as to monitor serial I have to plug in the USB cable. So when I am not pressing any buttons it fires off the input command looking for >60.
I have double and triple checked that I have good grounds. Everything shows proper continuity.
I am using a good 5V power supply, and have it plugged in even with the USB connected so as to power the LEDs.
I have checked my wiring many times. It works fine with the USB, and fine without if I hold down the button (lock it into the specific IF THEN state), but when I let go it fires off a step that shouldn't turn on.
It also seems that when I press the button, and with no USB cable, it doesn't immediately jump to the correct analog value but instead works up to it (will fire off the wrong section before the correct one).
I am connected to Vcc, Gnd (common throughout all components), and an analog pin.
And to reiterate, this works fine when I have the USB cable plugged in and connected to my PC, even if the IDE isn't open. Plugging in or pulling out the USB cable will immediately swap it between functioning correctly and not.
/*
Momentary potentiometer (onl gives Analog value while button held)
feeds into the RemotePin, read during the Void loop to determine
what color to turn on all the LED's. A Delay is placed to avoid any
readings while the button is released.
No button press is an Analog value of 0 (zero)
*/
#include <FastLED.h>
String Effect; //change current effect
#define NUM_LEDS 60
#define RemotePin 9
#define LED_PIN 10
CRGB led[NUM_LEDS];
void setup() {
Serial.begin(9600);
pinMode(RemotePin, INPUT);
FastLED.addLeds<WS2812B, LED_PIN, GRB>(led, NUM_LEDS);
delay (3000);
setAll(0,0,0);
FastLED.show();
}
//---------main program
void loop() {
if ( analogRead(RemotePin) > 900 ){
Effect = "OFF";
setAll(0,0,0);
delay(500);
}
else if ( analogRead(RemotePin) > 800 ){
Effect = "Red";
setAll(255,0,0);
delay(500);
}
else if ( analogRead(RemotePin) > 700 ){
Effect = "Green";
setAll(0,255,0);
delay(500);
}
else if ( analogRead(RemotePin) > 600 ){
Effect = "Blue";
setAll(0,0,255);
delay(500);
}
else if ( analogRead(RemotePin) > 500 ){
Effect = "Purple";
setAll(127,0,255);
delay(500);
}
else if ( analogRead(RemotePin) > 400 ){
Effect = "Yellow";
setAll(255,255,0);
delay(500);
}
else if ( analogRead(RemotePin) > 300 ){
Effect = "Teal";
setAll(0,255,255);
delay(500);
}
else if ( analogRead(RemotePin) > 200 ){
Effect = "White";
setAll(100,100,100);
delay(500);
}
else if ( analogRead(RemotePin) > 120 ){
Effect = "Orange";
setAll(255,128,0);
delay(500);
}
else if ( analogRead(RemotePin) > 60 ){
Effect = "Fuscia";
setAll(255,0,255);
delay(500);
}
Serial.println(Effect);
Serial.println(analogRead(RemotePin));
delay(100);
} //end main program
//--------set values for all LEDS----------------
void setAll(byte new_clr0,byte new_clr1,byte new_clr2){
for (byte i = 0; i < NUM_LEDS; i++){
led[i] = CRGB(new_clr0, new_clr1, new_clr2);
}
FastLED.show();
}
Any thoughts would greatly be appreciated!