Help with a sketch Analog to Digital.

I'm looking for an example sketch of how to conduct a led from an analogue input A1 of my Arduino MEGA 2560. The lead is connected to, for example, D26

Purpose: 5 volt on A0 -> lead on (connected to digital pin D26) 0 Volt on A0 -> Lead out again.

I know that it also works without digital connections, but in a complete setup it must be via the A1.

Thanks in advance for any response, Cees

You use analogRead() to read an analog pin. You use digitalWrite() to write to a digital pin. You use an if statement to determine whether to turn a pin on or off, based on what you read from the analog pin. Simple, really.

5 volt on A0 → lead on (connected to digital pin D26)
0 Volt on A0 → Lead out again.

Do you know how to read the value from an analogue pin ?
Do you know how to test the value read from the pin and make decisions based on it ?
Do you know how to write to a digital pin ?

I think your 3 questions are my core problem in understanding analogue to digital. I would appreciate if you would like to provide me with understandable information, maybe I can solve my question myself?

Cees

Why don't you answer the questions first?

You do know that you can use digitalRead on those analog inputs right? You don't have to do anything differently from how you would use a digital pin. All the analog pins double as digital pins too.

The Arduino reference: https://www.arduino.cc/en/Reference/HomePage

https://www.arduino.cc/en/Reference/AnalogRead https://www.arduino.cc/en/Reference/DigitalWrite https://www.arduino.cc/en/Reference/PinMode (Only needed for Digital Input/Output pins)