analogRead disables digitalRead?

I am experiencing something very strange. When I perform an anologRead and a digitalRead anywhere in the program, it simply ignores that the digitalRead ever happened and continues on. If I comment out the analogRead, the button works like normal. I proved that this is only happening on my SainSmart MEGA2560 and NOT on the UNO.

Here is the test code

#define soilPin A0
#define buttonPin 5

boolean currentButton = false;
boolean lastButton = false;

int soilReading = 0;

unsigned long currentMillis;
unsigned long loopMillis;

void setup()
{
  Serial.begin(9600);
  pinMode(buttonPin, INPUT_PULLUP);
  
   
}
void loop()
{
 
  currentMillis = millis();
  if((currentMillis - loopMillis) > 150){
   
   
    soilReading = analogRead(soilPin);
    currentButton = !digitalRead(buttonPin);
    
    
    
    if(currentButton == HIGH && lastButton  == LOW){
      
      Serial.println("Button Pressed");
      Serial.println(soilReading);
    }
    
    lastButton = currentButton;
    loopMillis = currentMillis;
  }
}

The mega was exposed to high humidity for an hour or two. Did something short out and ruin the ADC?

Are you saying that the analogRead() works properly at all times?

If so, how could there be a problem with the ADC?

Was the Mega immersed in water or wet steam? Was it powered up at the time?

...R

analogRead works if there is no call to digitalRead and vice versa. If both are called, it ignores the digitalRead. Sorry, I should have explained better.

Was the Mega immersed in water or wet steam? Was it powered up at the time?

It was in a plant box with a humidifier blowing into it. Yes it was powered up.

analogRead works if there is no call to digitalRead and vice versa.

That doesn't make a lot of sense maybe it is the fact you are not using a real arduino?
On a real arduino there is no connection between the analogue input pins and the digital pin 5.

Reduce the sketch to nothing but the two reads and a print of the results. Then see if they work.


Rob

The other thing is check your wiring, you might have a missing ground or something.

No matter what you do it will not allow any combination of digitalRead and analogRead, if you do use both, it prefers the analog . I adjusted the code of the main project to read the buttons via analogRead and got it working. Any ideas how the water could do that and no other noticeable problems?

Any ideas how the water could do that and no other noticeable problems?

No, and that is why I would suggest that is not your problem.
So:-
Post the minimal sketch that shows the problem and say what you see it do.
Post the schematic of how you have wired things up and also include a photograph of your setup.

That code works fine on a Arduino Mega - you have a hardware problem I think.
Or possibly a configuration one.

There's no issue with using digitalRead() and analogRead() in the same sketch,
100,000's of users would have noticed this already.

It is probably not good practise to refer to your variables as both true and false and high and low.