Arduino Mega 2560 desn´t load the sketch due map() function

Hi,

in my code I have two different funcions returning a map(...), when I try to upload the sketch it doesn't (timeout) BUT if I comment one of the map return (no matter which one) then it loads...

Is not the first time I deal with some similar situation with the 2560. Any clues??

Thanks!!

int lightLevel()
{
  int inputLevel = analogRead(lightSensorPin);
  return map(inputLevel, 0, 800, 0, 100); 
}
/*
* Returns a % of moisture on the soil moisture sensor
 */
int soilMoisture()
{
  int inputLevel = analogRead(soilMoisturePin);
return 10;//  return map(inputLevel, 0, 700, 0, 100);
   
}

More,

even if I try to do the maths it keep failing!!!

int soilMoisture()
{
  int inputLevel = analogRead(soilMoisturePin);
  //return map(inputLevel, 0, 700, 0, 100);
  
  return (inputLevel) * (100) / (700 ); 
}

So finally doing this ... it works. It's seem that if the builder detects your are trying to map() twice it crash...

int soilMoisture()
{
  int inputLevel = analogRead(soilMoisturePin);

  return (inputLevel) * 0.1428;//(100) / (700 );
}

If it is hanging during uploading it is probably due to the known issue of "!!!" pattern in the hex code.

Could you post your full code listing that was failing?

Hey hiduino!!

is quite long, but i've searched for the !!!, and I didn't find anything...

Actually the idea was to search the generated hex code dump for the hex pattern 0x212121.

It may not be in the text code listing, but in the compiled hex code.

Hi,

hum, ok I'll lock in the generated code,

Thank you!

Maybe this may help, from the File menu, Preferences, Show verbose output during, check the box for upload.

If it show something like this during the failed upload?

avrdude: Recv: H [48] 
avrdude: Recv: u [75] 
avrdude: Recv: h [68] 
avrdude: Recv: ? [3f] 
avrdude: Recv: . [0d] 
avrdude: Recv: . [0a] 
avrdude: Recv: B [42] 
avrdude: Recv: o [6f] 
avrdude: Recv: o [6f] 
avrdude: Recv: t [74] 
avrdude: Recv: l [6c] 
avrdude: Recv: o [6f] 
avrdude: Recv: a [61] 
avrdude: Recv: d [64] 
avrdude: Recv: e [65] 
avrdude: Recv: r [72] 
avrdude: Recv: > [3e]

Then this is the indication that there is a “!!!” pattern in the hex code.