Dr_Doggy
Well-Known Member
First please note that the value for eeprom#2 =oxFF is wrong due to importing during writing, the actual value is 0, because Green is multiplied by 0 in the subroutine.
... which leads me to my problem... variable Im should be calculation that returns percent value of solar intensity, however as we can see in eeprom Im returns as 0, which i dont think is always the case cause the led is on sometimes, but I have not yet sampled data where the green value is other than 0 & 255...
.... so basically my problem is: How do i get the percent value of "Im" to multiply properly by the "Green" value?! ... which if i calculated correctly should be a decimal value between 0 & 1, I have tried calling it as both a float and double,...
EEPROM Output = AA 00 FF 6F 8C 7F 00
... which leads me to my problem... variable Im should be calculation that returns percent value of solar intensity, however as we can see in eeprom Im returns as 0, which i dont think is always the case cause the led is on sometimes, but I have not yet sampled data where the green value is other than 0 & 255...
.... so basically my problem is: How do i get the percent value of "Im" to multiply properly by the "Green" value?! ... which if i calculated correctly should be a decimal value between 0 & 1, I have tried calling it as both a float and double,...
EEPROM Output = AA 00 FF 6F 8C 7F 00
Code:
unsigned int solar = 0;
unsigned int solarMin = 255;
unsigned int solarMax = 0;
unsigned char Red = 0;
unsigned char Green = 0;
unsigned char Blue = 0;
while (1){
solar = getSolar(); // Dark=63 Light=129
if (solar > solarMax){solarMax = solar;}
if (solar < solarMin){solarMin = solar;}
setColorB(2); // sets values for Green = 255;
float Im;
Im = (solar - solarMin)/(solarMax-solarMin); // convert solar to percent
// if (Im > 1){Im = 1;}
// if (Im < 0){Im = 0;}
I = Green * Im; // ajust green based on solar percent
Green = (unsigned char)(Im);
Im = Im*100;
EEPROM_WRITE(0, 0xAA);
EEPROM_WRITE(1, ((unsigned char)(Im)));
EEPROM_WRITE(2, Green);
EEPROM_WRITE(3, ((unsigned char)(solarMin)));
EEPROM_WRITE(4, ((unsigned char)(solarMax)));
EEPROM_WRITE(5, ((unsigned char)(solar)));
EEPROM_WRITE(6, ((unsigned char)(I)));
}