Word variable and storing correct value
Code:
Fade:
Vb_1 = ((B_Day_On_H - B_Dawn_On_H)*60) ' difference between day start and dawn start hour, converted to min
Vb_2 = (B_Day_On_M - B_Dawn_On_M) ' difference between day start and dawn start mins
Vb_5 = (Vb_1+Vb_2)*60 ' Get total duration time in seconds
Vb_6 = B_Max - B_Min ' Work out the 'distance' the lights go from min to max
B_Fadein_Time = Vb_5 / Vb_6 ' Get number of seconds between each PWM pulse
Vb_7 = Vb_5 // Vb_6 'Get fractions of a second
Vb_8 = B_Fadein_Time
' with B day on at 8:10 and a Dawn on at 8:00, Vb1 = (8 - 8) * 60 which gives 0. Vb2 = (10-0) = 10, Vb5 = (0+10)*60 = 600
' Vb6 = 255-0 = 255
' so fadein time = 600/255 = 2.352941176470588
' Vb_8 therefore should equal 236
I need VB_8 to = 235 (rounding down the fadein time and removing the decimal) but can't work out how - can someone please point me in the right direction
Thanks
Malcolm
Re: Word variable and storing correct value
B_Fadein_Time = Vb_5 / Vb_6 * 100
Re: Word variable and storing correct value
Thanks for the input. However using this command B_Fadein_Time reaches the 255 max in around 90 seconds
I tried 1000 as the multiplier, but the timing is still out as it uses just the integer and not the full decimal value you get in the calculations. What I'm after is the ability to set the max value for the brightness (B_max - B_min) and then use this value (between 0 and 255) to work out the pulse duration so that it goes from 0 to B_Max in the difference between the two times. On paper it's a simple calculation, but getting it to work in PBP without any floating point maths is becoming the stumbling block. My code also used a 1307 RTC, so using the pause statement in DT's Multi SPWM routine might effect the time being displayed on the LCD -