Although in most cases if you are using the analog pins as analog inputs, the analogRead() will do it for you.
So you do not necessarily have to pinMode pinA0 at all.
I have a request. Would you be so kind and read through the following code and answer very honest if this code is easy or hard to understand for you?
/* Blink without Delay
delay() is the most crappy command that makes every newcomer scratch
their head why does my program not work as expected?
This demo-code is structured into functions
to all newcomers: programming with functions needs 1 minute more time
to write the code but saves 2 to 10 HOURS to find bugs
= you will finish your project much faster because you write a small function
test function and then write the next function.
This means if a bug occurs it is located in a much smaller area
= much faster to find. ==> faster finished project
This version of Blink without delay is based on a function
called "TimePeriodIsOver"
This function gives back a result "true" or "false" depending on what the name
of the function says "timePeriodIsOver"
You need ONE additional line of code to make it work.
You have to define a variable that acts as a timing-variable
example: unsigned long myTimer;
This example code is in the public domain.
*/
// constants won't change. Used here to set a pin number:
const int ledPin = LED_BUILTIN;// the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long myTimer; // timing-variable
const unsigned long myInterval = 1000; // interval at which to blink (milliseconds)
// TimePeriodIsOver ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// function for timing just copy & paste without modifying it
boolean timePeriodIsOver (unsigned long &periodStartTime, unsigned long timePeriod) {
unsigned long currentMillis = millis();
if ( currentMillis - periodStartTime >= timePeriod )
{
periodStartTime = currentMillis; // set new expireTime
return true; // more time than TimePeriod) has elapsed since last time if-condition was true
}
else return false; // not expired
} //TimePeriodIsOver ----------------------------------------------------------------------------
// LED-switching +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// function for switching the LED
void switchLEDState() {
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
}
else {
ledState = LOW;
}
digitalWrite(ledPin, ledState); // set the LED with the ledState of the variable:
} //LED-switching --------------------------------------------------------------
void setup() {
pinMode(ledPin, OUTPUT); // set the digital pin as output:
}
void loop() {
// here is where you'd put code that needs to be running all the time.
// check if TimePeriodIsOver if true then change the state of the LED
if ( timePeriodIsOver(myTimer,myInterval) ) {
switchLEDState(); // a single line of code with a SELF-explaining name what the function does
}
}
thank you very much
if you want to ask questions abou this code ask as much as you want
best regards Stefan
sneaky is a hard word for that.
I want to emphasize again: amila if it is not your thing just post a short "no" or ignore it and everything will be fine.