void hexbright::set_light(int start_level, int end_level, long time) { // duration ranges from 1-MAXINT // light_level can be from 0-1000 int current_level = get_light_level(); if(start_level == CURRENT_LEVEL) { start_light_level = current_level; } else { start_light_level = start_level; } if (end_level == CURRENT_LEVEL) { end_light_level = get_light_level(); } else { end_light_level = end_level; } change_duration = ((float)time)/update_delay; change_done = 0; #if (DEBUG==DEBUG_LIGHT) Serial.print("Light adjust requested, start level: "); Serial.println(start_light_level); Serial.print("Over "); Serial.print(change_duration); Serial.println(" updates"); #endif }
int hexbright::get_max_light_level() { int light_level = get_light_level(); if(light_level>max_light_level) return max_light_level; return light_level; }
int hexbright::get_safe_light_level() { int light_level = get_light_level(); if(light_level>safe_light_level) return safe_light_level; return light_level; }
void hexbright::apply_max_light_level() { // if max_light_level has changed, guarantee a light adjustment: // the second test guarantees that we won't turn on if we are // overheating and just shut down if(max_light_level < MAX_LEVEL && get_light_level()>MIN_OVERHEAT_LEVEL) { #if (DEBUG!=DEBUG_OFF && DEBUG!=DEBUG_PRINT) Serial.print("Max light level: "); Serial.println(max_light_level); #endif change_done = change_done < change_duration ? change_done : change_duration; } }
// If the starting temp is much higher than max_temp, it may be a long time before you can turn the light on. // this should only happen if: your ambient temperature is higher than max_temp, or you adjust max_temp while it's still hot. // Here's an example: ambient temperature is > void hexbright::overheat_protection() { int temperature = get_thermal_sensor(); safe_light_level = safe_light_level+(OVERHEAT_TEMPERATURE-temperature); // min, max levels... safe_light_level = safe_light_level > MAX_LEVEL ? MAX_LEVEL : safe_light_level; safe_light_level = safe_light_level < MIN_OVERHEAT_LEVEL ? MIN_OVERHEAT_LEVEL : safe_light_level; #if (DEBUG==DEBUG_TEMP) static float printed_temperature = 0; static float average_temperature = -1; if(average_temperature < 0) { average_temperature = temperature; Serial.println("Have you calibrated your thermometer?"); Serial.println("Instructions are in get_celsius."); } average_temperature = (average_temperature*4+temperature)/5; if (abs(printed_temperature-average_temperature)>1) { printed_temperature = average_temperature; Serial.print(millis()); Serial.print(" ms, average reading: "); Serial.print(printed_temperature); Serial.print(" (celsius: "); Serial.print(get_celsius()); Serial.print(") (fahrenheit: "); Serial.print(get_fahrenheit()); Serial.println(")"); } #endif // if safe_light_level has changed, guarantee a light adjustment: // the second test guarantees that we won't turn on if we are // overheating and just shut down if(safe_light_level < MAX_LEVEL && get_light_level()>MIN_OVERHEAT_LEVEL) { #if (DEBUG!=DEBUG_OFF) Serial.print("Estimated safe light level: "); Serial.println(safe_light_level); #endif change_done = min(change_done , change_duration); } }