LED fading

Hi Arduinoreans!

Nice to be in this forum!

I hope that some of you guys might be able to help me with a programming question that I have.
I am using a formula “x = 0.5347 *pow(TSL2561.readVisibleLux(),1.1834)” to offset the measurements. After that, another formula is added in to control the brightness of the bulb “y = ((int)((-51/80) * x) + 255)”. However, I kept getting my value of y as 255. Could anyone advise me a way around this?

Thank you very much! :slight_smile:

#include <LiquidCrystal.h>
#include <Wire.h>
#include <Digital_Light_TSL2561.h>
int ledPin = 9;    // LED connected to digital pin 9
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Lcd connected to digital pin 2, 3, 4, 5, 11, 12
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  TSL2561.init(); // To initialise digital light sensor 
  int fadeValue;
  lcd.begin(16, 2); // set up the LCD's number of columns and rows:
  lcd.setCursor(0,0); // Set cursor to first row and first column
  
  for ( fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) // Fade in LED from min to max 
      {
        analogWrite(ledPin, fadeValue);
        delay(30); // wait for 30 milliseconds to see the dimming effect
      }
   while(1)
   {    
    double x = 0.5347 *pow(TSL2561.readVisibleLux(),1.1834); // Conversion of DLS data to Luxmeter data 
    Serial.print("The Light value is: ");
    Serial.println(x); // Print out the formatted lux reading from luxmeter
    Serial.print("Unformatted is: ");
    Serial.println(TSL2561.readVisibleLux()); // print out the lux reading frm dls reading
    delay(300);

    int y = ((int)((-51/80) * x) + 255);
    Serial.println(y); 
    analogWrite(ledPin, y);
    delay(1000);
   }
}

void loop() 
{
  
}

Best Regards
Nathaniel

 int y = ((int)((-51/80) * x) + 255);

x times zero is zero, plus 255 is 255.

 int y = ((int)((-51.0/80.0) * x) + 255);