Curious about "ceil"

Found it in some code on the net and just wondering what it is exactly.
First thought was that it might have been some foreign language for "map".

Line 17.

int potPin = A4; // select the input pin for the potentiometer
int FETPin = A5; // select the pin for the LED
float potValue = 0; // variable to store the value coming from the potenciometer
float FETValue = 0; //write 0-255 open the FET
float pwmMax = 20; // limit the max opening of the FET

void setup() {
  Serial.begin(9600);
}

void loop() {

  // read the value from the potenciometer:
  potValue = analogRead(potPin);

  //map the pot value between 0- 1023
  FETValue = ceil (potValue / 1023 * (pwmMax / 100 * 255));

  // turn the FETPin on
  analogWrite(FETPin, FETValue);

  Serial.print ("pwmMax: ");
  Serial.println (pwmMax);
  Serial.print ("potValue: ");
  Serial.println (potValue);
  Serial.print ("FETValue: ");
  Serial.println (FETValue);

  delay(1000);

}

"ceiling"

Upward rounding, but negative numbers are getting smaller since they also go "upward", see: https://www.cplusplus.com/reference/cmath/ceil/

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.