fmax()

[Math]
double fmax(double x, double y);

Description

Returns the greater of the two values between x and y.

Parameters

x: The first value to compare.

y: The second value to compare.

Returns

The greater of the two values x and y.

Example Code

The code reads the value of two potentiometers connected to pins INX and INY and places the greater of the two values on pin OUT.

void setup() {
    pinLabel(0, "INY");  // set the label of pin 0 to "INY"
    pinLabel(1, "INX");  // set the label of pin 1 to "INX"
    pinLabel(2, "OUT");  // set the label of pin 2 to "OUT"
    pinMode(2, OUTPUT);  // set pin 2 as output
    pinLabel(3, "OUT2"); // set the label of pin 3 to "OUT2"
    pinMode(3, OUTPUT);  // set pin 3 as output
    pinLabel(4, "VCC");  // set the label of pin 3 to "VCC"
    powerPin(4);         // set pin 4 as power pin
    pinLabel(5, "GND");  // set the label of pin 4 to "GND"
    groundPin(5);        // set pin 5 as ground pin
}
void loop() {   
    int val_x = analogRead(0); // read the value of the potentiometers
    int val_y = analogRead(1); 
    analogWrite(2, (int) fmax(val_x, val_y)); // write fmax to pin 2
}

Notes and Warnings

  • If an argument is NaN, NaN is returned.
  • If both arguments are NaN, NaN is returned.