How would I make a variable that tracks which analog input is receiving a signal?

for example, it would be able to tell whether A0, A1, A2, A3, A4, or A5 is on and store a different value depending on which is receiving a signal at any given moment.

Read through the analog input code. You will see the processor controls what analog input is measured and when.

The analog inputs are disconnected unless the processor selects and requests a reading. So when the program is off doing something else, ALL the analog inputs are disconnected.

How would you define a signal?

1 Like

I might have worded things wrong.

For example, if the analog input pin A0 were to receive any sort of input of any kind, it would take that and give a certain value to a variable.

each analog input would assign something different to the variable.

I have some LED's. When they turn on, the analog pins receive an input. Each LED is connected to a different analog pin, so each LED has a corresponding analog input pin. I'm trying to make a variable that is assigned a different value depending on which analog pin is currently receiving an input.

The LED's are in a pattern, and the same configuration of 2 LED's appears twice. By tracking which LED's are on and when, the program can differentiate the two different points of the pattern by knowing the LED that was on beforehand.

No, they are all completely wired separately from each other.

also, I want to know the previous LEDs that were on, before the current ones.

They are all on the same breadboard, but wired separately.

The pattern I'm trying to follow gets modified with the press of a button. (This button is connected to an analog input pin, reading the input to tell when it's been pressed.)

all it does is modify the length of an LED being on, but I had a problem where it would restart the pattern from the beginning when thew button was pressed.

So, I connected each LED to an analog input (and one to a digital pin, I didn't have enough analog pins to connect to), and the program, using analog Read and digital Read, would be able to tell which LED's are on at any given moment when the button is pressed, so the program knows where to continue on with the modified pattern from.

However, there is a point in the pattern which is replicated later. These moments are far apart from each other.

This means that the program cannot differentiate between either of those moments, because the same 2 LED's are on in both.

So, I'm trying to make a variable that will track which LED is on at any given moment. Using this information, since the two iterations of the same configuration of LED's stem from different points, it would differ the two based on which LED's were on previously, and continue the pattern as it should.

What is controlling the leds?
How exactly are the leds wired?
Make a schematic. Or a picture.
Do not add a lot of words...

2 Likes

Hello loogeemian

Can you describe the desired functionality in simple words and very simply?

Analog pins are always receiving an input.

It would be best if you started by using a single led and button and developed your code step by step.

This sounds as if it could be resolved as a state machine. A bit like the traffic light example here

Please post a schematic

So reading your follow on post its not clear if the same board with the Analog inputs is the same board as controlling the LED. IF IT IS NOT THE SAME BOARD then,
You need to setup the Analog input board to read the analog inputs repeatedly over and over. When one input is the value you get when an LED goes on they you can assign this to a variable.

Is the input signal within the range of a digital input i.e. 0 to 5V or some boards 0 to3.3V if they are, you can use digital inputs and enable interrupts for these pins.

is this a random coincidence or is there a significant rise in "real beginners"-questions?

@loogeemian
a simple question:

are you using one microcontroller
or
are you using two microcontrollers?

do you mean photoDiode, photoTransistor, IR sensor/receiver?

an LED would normally be connected to an OUTPUT pin which is turned on/off to turn the LED on/off

code to monitor analog inputs and report values exceeding a threshold

const byte PinAdc [] = { A0, A1, A2, A3 };
const int  Nadc      = sizeof(PinAdc);

const int Thresh = 100;

// -----------------------------------------------------------------------------
void
loop (void)
{
    for (int n = 0; n < Nadc; n++)  {
        int adc = analogRead (PinAdc [n]);
        if (Thresh <= adc)  {
            Serial.print   ("adc read ");
            Serial.print   (n);
            Serial.print   (" ");
            Serial.println (adc);
        }
    }
}

void
setup (void)
{
    Serial.begin (9600);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.