Grove Rotary Angle Sensor - Overloaded Function


#1

Hi,

I’m testing out the Grove Rotary Sensor Angle that comes in the Grove kit. I tried testing out this example which is linked off of part.cl/grove and the example is throwing the following error:

call of overloaded ‘map(float&, int, int, int, int)’ is ambiguous

//code
/macro definitions of Rotary angle sensor and LED pin/

#define ROTARY_ANGLE_SENSOR A0
#define LED D4  //the Grove - LED is connected D4 pin
#define ADC_REF 5 //reference voltage of ADC is 5v.If the Vcc switch on the seeeduino
                    //board switches to 3V3, the ADC_REF should be 3.3
#define GROVE_VCC 5 //VCC of the grove interface is normally 5v
#define FULL_ANGLE 300 //full value of the rotary angle is 300 degrees

void setup()
{
    Serial.begin(9600);
    pinMode(ROTARY_ANGLE_SENSOR, INPUT);
    pinMode(LED,OUTPUT);   
}

void loop()
{   
    float voltage;
    int sensor_value = analogRead(ROTARY_ANGLE_SENSOR);
    voltage = (float)sensor_value*ADC_REF/1023;
    float degrees = (voltage*FULL_ANGLE)/GROVE_VCC;
    Serial.println("The angle between the mark and the starting position:");
    Serial.println(degrees);

    int brightness;
    brightness = map(degrees, 0, FULL_ANGLE, 0, 255);
    analogWrite(LED,brightness);
    delay(500);
}

Any ideas?

Thanks.


#2

The error message provides all you need to know :wink:

There is no version of map() that takes one float and four ints.
There are onle versions that either take all floats or all ints.

While casting int to float or float to int can be done implicitly, the compiler can’t decide which way it should do it, so you need to help it decide.

BTW

Particle ADCs are of 12bit resolution (0…4095) unlike Arduino’s 10bit (0…1023).
And ADC_REF is 3.3V not 5 - make sure to never apply more than 3.3V to an ADC pin.