Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Pretty Vandal PlusPlus
- Notes:
- 1. This code is intended for a 5-volt Arduino Nano or Nano clone, or an Uno or Uno clone. It uses 12% of program storage space and 13% of dynamic memory.
- 2. This code is written to operate a single 3-color RGB LED and the single color power-indicator and hard-drive-activity-indicator LEDs by PWM. It uses hardware PWM pins, not software PWM.
- 3. For the RGB LED, at the minimums--the red LED should have a 150 ohm resistor, green needs a 100 ohm and blue needs a 100 ohm. In my version I used 220 ohms for the red and 150 ohms each for the green and blue.
- 4. For the single-color power and hard-drive-activity LEDs, the minimum resistor value will vary depending on the LED colors but it is safe to use a 220-ohm resistor for any color.
- This program allows having two separate color RGB values: one for the power/sleep indication, and the other for the hard-drive activity indication.
- Additionally, each of the above two conditions has two transitional colors for the rising-value and the decaying-value.
- The colors are made to transition smoothly into each other.
- The single-color power and hard-drive LEDs can be operated also.
- Both have a maximum brightness setting, and have separate settings for how fast the light levels of each LED rise and decay.
- */
- /*
- The three settings below control if each feature is enabled or not.
- Technically it doesn't matter if they are left on and just left unconnected, but anyway.
- If you wanted to use those pins for anything else you added, you would need to disable the LED functions here from altering them.
- */
- boolean use_RGB_output = true; // This controls the single RGB LED or button.
- boolean use_case_power_LED = true; // This controls the PC case normal power LED.
- boolean use_case_hardDrive_LED = true;// This controls the PC case normal hard-drive-activity LED.
- /*
- The RGB LED color levels are set here, in the first 18 variables stated.
- The first nine are for the power indicator colors, and the second nine are for the hard-drive activity indicator colors.
- Each RGB LED has a value of 0 to 255 for each of the primary LED colors.
- The first three variables below state the maximum value for that primary color that will be used.
- The second set controls how fast that each of the three primary colors will rise, if the indicator state is positive.
- The third set is the amount that each of the three primary colors decrease, if the indicator state is negative.
- Since you mostly see the power in a constant state of being [on] with the hard drive signal flickering on and off, it may be more useful to set the decay values relative to each other's maximum values rather than zero.
- */
- // ###############################################################################################################################################
- // Power indicator maximum values, can range from 0 to 255. These values may be zero, but if all three are set to zero, then the LED of that primary color will not light up at all in that color.
- int power_indicator_red_maximum_value = 0;
- int power_indicator_green_maximum_value = 100;
- int power_indicator_blue_maximum_value = 30;
- // Power indicator increment values, maximum = 255. These values should not be zero unless the corresponding primary color maximum value (above) is also set to zero.
- // A larger number will cause that color to rise faster.
- int power_indicator_red_rise_value = 0;
- int power_indicator_green_rise_value = 10;
- int power_indicator_blue_rise_value = 15;
- // Power indicator decay values are below. These can be values from 1 to 255, but should not be zero unless the maximum value and the rising value for that primary color are also zero.
- // A larger number will cause that color to decay faster.
- int power_indicator_red_decay_value = 10;
- int power_indicator_green_decay_value = 40;
- int power_indicator_blue_decay_value = 5;
- // ###############################################################################################################################################
- // Hard drive indicator maximum values, can range from 0 to 255. These values may be zero, but if all three are set to zero, then the LED of that primary color will not light up at all.
- int hardDrive_indicator_red_maximum_value = 60;
- int hardDrive_indicator_green_maximum_value = 0;
- int hardDrive_indicator_blue_maximum_value = 120;
- // Hard drive indicator increment values, maximum = 255. These values should not be zero unless the corresponding primary color maximum value (above) is also set to zero.
- // A larger number will cause that color to rise faster.
- int hardDrive_indicator_red_rise_value = 30;
- int hardDrive_indicator_green_rise_value = 0;
- int hardDrive_indicator_blue_rise_value = 10;
- // Hard drive indicator decay values are below. These can be values from 1 to 255, but should not be zero unless the maximum value and the rising value for that primary color are also zero.
- // A larger number will cause that color to decay faster.
- int hardDrive_indicator_red_decay_value = 25;
- int hardDrive_indicator_green_decay_value = 60;
- int hardDrive_indicator_blue_decay_value = 10;
- // ###############################################################################################################################################
- /*
- The section below is the variables to control the single-color case LEDs for the power and hard-drive-activity indicators.
- There is no color setting because these are single-color LEDs.
- There is only the maximum level setting, the rising rate and decay rate for each.
- */
- int case_LED_power_indicator_maximum_brightness = 100;
- int case_LED_power_indicator_rising_rate = 50;
- int case_LED_power_indicator_decay_rate = 25;
- int case_LED_hardDrive_indicator_maximum_brightness = 255;
- int case_LED_hardDrive_indicator_rising_rate = 100;
- int case_LED_hardDrive_indicator_decay_rate = 50;
- // ###############################################################################################################################################
- /*
- Input/Output Pins
- ------------------------------------------------
- Different boards use different I/O pin assignments.
- The set for the board you are using must be un-commented, and the other two should be commented out.
- */
- // Arduino Nano pins --------------------------------------------------------
- int power_indicator_pin_positive = A7; // this connects to the (+) power LED line of the PC
- int power_indicator_pin_negative = A6; // this connects to the (-) power LED line of the PC
- int hard_drive_indicator_pin_positive = A5; // this connects to the (+) hard drive LED line of the PC
- int hard_drive_indicator_pin_negative = A4; // this connects to the (-) hard drive LED line of the PC
- int LED_red_pin = 5; // This is pin D5: it connects to the red pin of the RGB LED
- int LED_green_pin = 6;// This is pin D6: it connects to the green pin of the RGB LED
- int LED_blue_pin = 9;// This is pin D9: it connects to the blue pin of the RGB LED
- int case_power_LED_pin = 10; // This is pin D10: this is where the case power indicator LED (+) wire is connected to.
- int case_hardDrive_LED_pin = 11;// This is pin D11: this is where the case hard-drive-activity LED (+) wire is connected to.
- // ---------------------------------------------------------------------------
- /*
- // Arduino Uno pins ----------------------------------------------------------
- int power_indicator_pin_positive = A1; // this connects to the (+) power LED line of the PC
- int power_indicator_pin_negative = A2; // this connects to the (-) power LED line of the PC
- int hard_drive_indicator_pin_positive = A3; // this connects to the (+) hard drive LED line of the PC
- int hard_drive_indicator_pin_negative = A4; // this connects to the (-) hard drive LED line of the PC
- int LED_red_pin = 11; // This is pin ~11: it connects to the red pin of the RGB LED
- int LED_green_pin = 10;// This is pin ~10: it connects to the green pin of the RGB LED
- int LED_blue_pin = 9;// This is pin ~9: it connects to the blue pin of the RGB LED
- int case_power_LED_pin = 5; // This is pin ~5: this is where the case power indicator LED (+) wire is connected to.
- int case_hardDrive_LED_pin = 6;// This is pin ~6: this is where the case hard-drive-activity LED (+) wire is connected to.
- // ---------------------------------------------------------------------------
- */
- // ###############################################################################################################################################
- // PWM levels (don't change these values)
- int current_LED_red_PWM_level = 0;
- int current_LED_green_PWM_level = 0;
- int current_LED_blue_PWM_level = 0;
- int previous_LED_red_PWM_level = 0;
- int previous_LED_green_PWM_level = 0;
- int previous_LED_blue_PWM_level = 0;
- int current_case_LED_power_level = 0;
- int previous_case_LED_power_level = 0;
- int current_case_LED_hardDrive_level = 0;
- int previous_case_LED_hardDrive_level = 0;
- int temp_difference = 0; // A temporary-use variable for setting the LED levels properly.
- // power monitoring variables
- int array_powerChecks[20];
- /*
- The array above is 20 elements long, and the power check interval is set to 1/10th of a second (100 milliseconds).
- This is used to keep the hard-drive LED from triggering unless the power has been "on" for at least 2 seconds.
- Since we only have one display here and two inputs (power ahd hard drive activity) one of them must be given priotity.
- In this sketch, the hard-drive activity gets ignored while the computer is sleeping (while the power status input line is blinking on and off).
- */
- int power_check_total = 0;
- int power_pin_value = 0;
- //float power_pin_measured_volts = 0;
- float power_pin_positive_volts = 0;
- float power_pin_negative_volts = 0;
- float power_pin_minimum_volts = 1;
- int power_check_interval_milliseconds = 100; // This is the time interval that the power activity pin is checked. 100 milliseconds = ten times per second.
- unsigned long previous_power_check_time = 0;
- unsigned long current_power_check_time = 0;
- // hard drive monitoring variables
- int hardDriveCheck_value = 0;
- int hardDrive_pin_value = 0;
- //float hardDrive_pin_measured_volts = 0;
- float hardDrive_pin_positive_volts = 0;
- float hardDrive_pin_negative_volts = 0;
- float hardDrive_pin_minimum_volts = 1;
- int hardDrive_check_interval_milliseconds = 20; // This is the time interval that the power activity pin is checked. 20 milliseconds = fifty times per second.
- int hardDrive_transition_interval_milliseconds = 100; // This is the time interval that the hard drive level stays "high" once it is found to be high.
- boolean hardDrive_delay_active = false;
- /*
- This program uses two different time intervals for the hard drive check, since it tends to blink on and off very rapidly.
- Normally the hard drive is checked at a rate of 50 times per second (20 milliseconds).
- If the hard drive activity signal is found to be high, then a second time delay of 100 milliseconds is performed (one tenth of a second).
- */
- unsigned long previous_hardDrive_check_time = 0;
- unsigned long current_hardDrive_check_time = 0;
- unsigned long LED_update_interval_previousTime = 0;
- unsigned long LED_update_interval_currentTime = 0;
- int LED_update_interval_milliseconds = 100;
- // these are function declarations, for functions written further below
- void check_power_pin_state();
- void advance_power_array_values();
- void get_power_pin_input();
- void get_power_array_total();
- void check_hardDrive_pin_state();
- void advance_hardDrive_array_values();
- void get_hardDrive_pin_input();
- void set_LED_button_colors();
- void transition_LED_power_down();
- void transition_to_power_LED_colors();
- void transition_to_hardDrive_LED_colors();
- void case_power_LED_turnOn();
- void case_power_LED_turnOff();
- void check_case_power_LED_value();
- void write_to_case_power_LED_pin();
- void case_hardDrive_LED_turnOn();
- void case_hardDrive_LED_turnOff();
- void check_case_hardDrive_LED_value();
- void write_to_case_hardDrive_LED_pin();
- void check_LED_values();
- void write_to_LED_pins();
- void setup() {
- Serial.begin(115200); // This is needed for serial debug messaging. Also you cannot use pins 30 or 31 (on the Nano) or else the serial debugging messages will not work.
- /*
- Normally you would declare the input/output pins with their desired settings, but in this case we don't need to.
- This sketch uses analogread() for the two inputs, and the analogread() function doesn't require a delaration to use.
- This sketch also uses analogwrite() for the three PWM outputs to run the LED, and that doesn't need to be declared in advance either.
- */
- //pinMode(power_indicator_pin, INPUT);
- //pinMode(hard_drive_indicator_pin, INPUT);
- //pinMode(LED_red_pin, OUTPUT);
- //pinMode(LED_green_pin, OUTPUT);
- //pinMode(LED_blue_pin, OUTPUT);
- // The lines below write the LED pins to zero value to start, else they may begin at random values.
- current_LED_red_PWM_level = 0;
- analogWrite(LED_red_pin, current_LED_red_PWM_level);
- current_LED_green_PWM_level = 0;
- analogWrite(LED_green_pin, current_LED_green_PWM_level);
- current_LED_blue_PWM_level = 0;
- analogWrite(LED_blue_pin, current_LED_blue_PWM_level);
- // below initializes the power-check array to all-zero-values to begin.
- for (int i = 0; i <= 19; i++) {
- array_powerChecks[i] = 0;
- }
- hardDriveCheck_value = 0;
- } // --------- end of setup() function
- void loop() {
- // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- // This section checks the power pin state, at the specified time interval.
- current_power_check_time = millis();
- if (current_power_check_time > previous_power_check_time) {
- if (current_power_check_time >= (previous_power_check_time + power_check_interval_milliseconds)) {
- previous_power_check_time = millis();
- check_power_pin_state();
- }
- }
- else {
- previous_power_check_time = millis(); // rollover condition: probably not necessary but good practice
- }
- // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- // This section checks the hard drive pin state, at the specified time interval.
- if (hardDrive_delay_active == false) {
- current_hardDrive_check_time = millis();
- if (current_hardDrive_check_time > previous_hardDrive_check_time) {
- if (current_hardDrive_check_time >= (previous_hardDrive_check_time + hardDrive_check_interval_milliseconds)) {
- hardDrive_delay_active = true;
- previous_hardDrive_check_time = millis();
- check_hardDrive_pin_state();
- }
- }
- else {
- previous_hardDrive_check_time = millis(); // rollover condition: probably not necessary but good practice
- }
- }
- // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- // This sets the LED RGB values
- //set_LED_button_colors();
- LED_update_interval_currentTime = millis();
- if (LED_update_interval_currentTime > LED_update_interval_previousTime) {
- if (LED_update_interval_currentTime >= (LED_update_interval_previousTime + LED_update_interval_milliseconds)) {
- set_LED_button_colors();
- hardDrive_delay_active = false;
- LED_update_interval_previousTime = millis();
- }
- }
- else {
- LED_update_interval_previousTime = millis(); // rollover condition: probably not necessary but good practice
- }
- } //----------- end of (main) loop
- void check_power_pin_state() {
- advance_power_array_values();
- get_power_pin_input();
- }
- void advance_power_array_values() {
- for (int i = 19; i >= 1; i--) {
- array_powerChecks[i] = array_powerChecks[i - 1];
- }
- }
- void get_power_pin_input() {
- power_pin_value = analogRead(power_indicator_pin_positive);
- power_pin_positive_volts = (5.0 / 1024) * power_pin_value;
- power_pin_value = analogRead(power_indicator_pin_negative);
- power_pin_negative_volts = (5.0 / 1024) * power_pin_value;
- if ((power_pin_positive_volts - power_pin_negative_volts) >= power_pin_minimum_volts) {
- array_powerChecks[0] = 1;
- }
- else {
- array_powerChecks[0] = 0;
- }
- }
- void get_power_array_total() {
- power_check_total = 0;
- for (int i = 0; i <= 19; i++) {
- power_check_total = power_check_total + array_powerChecks[i];
- }
- }
- void check_hardDrive_pin_state() {
- get_hardDrive_pin_input();
- }
- void get_hardDrive_pin_input() {
- hardDrive_pin_value = analogRead(hard_drive_indicator_pin_positive);
- hardDrive_pin_positive_volts = (5.0 / 1024) * hardDrive_pin_value;
- hardDrive_pin_value = analogRead(hard_drive_indicator_pin_negative);
- hardDrive_pin_negative_volts = (5.0 / 1024) * hardDrive_pin_value;
- if ((hardDrive_pin_positive_volts - hardDrive_pin_negative_volts) >= hardDrive_pin_minimum_volts) {
- hardDriveCheck_value = 1;
- hardDrive_delay_active = true;
- }
- else {
- hardDriveCheck_value = 0;
- }
- }
- void set_LED_button_colors() {
- get_power_array_total();
- if (hardDriveCheck_value == 1) { // This checks if the hard drive is active.
- if (power_check_total == 20) { // This checks if the power has been on constantly at least ~2 seconds.
- if (use_RGB_output == true) {
- transition_to_hardDrive_LED_colors();
- }
- if (use_case_hardDrive_LED == true) {
- case_hardDrive_LED_turnOn();
- }
- }
- }
- else {
- // If the first power check is not zero, but all 20 power checks are not 1, then call the power-color-transition function.
- if (array_powerChecks[0] == 0) {
- // If the first power check is zero, then the power-color_transition function is called, because the computer is sleeping and the LED signal is 'off'.
- if (use_RGB_output == true) {
- transition_LED_power_down();
- }
- if (use_case_power_LED == true) {
- case_power_LED_turnOff();
- }
- }
- else {
- // If (array_powerChecks[0] = 1 then turn the LED power colors on.
- if (use_RGB_output == true) {
- transition_to_power_LED_colors();
- }
- if (use_case_power_LED == true) {
- case_power_LED_turnOn();
- }
- }
- if (use_case_hardDrive_LED == true) {
- case_hardDrive_LED_turnOff();
- }
- }
- }
- void transition_LED_power_down() {
- current_LED_red_PWM_level = current_LED_red_PWM_level - power_indicator_red_decay_value;
- current_LED_green_PWM_level = current_LED_green_PWM_level - power_indicator_green_decay_value;
- current_LED_blue_PWM_level = current_LED_blue_PWM_level - power_indicator_blue_decay_value;
- // The LED's PWM values are checked to make sure they are valid (must be from zero to 255).
- check_LED_values();
- // The PWM values are written to the three pins controlling the three primary-color LEDs.
- write_to_LED_pins();
- }
- void transition_to_power_LED_colors() {
- // The LED's PWM values are incremented with the power-color-rise values.
- // In this function, it doesn't matter if each current color value is above or below the power_indicator_maximum values; it is moved towards that value either way by the rising value or the decay value.
- // The variable temp_difference is used to make certain that the incremental value does not overshoot the desired maximum value.
- if (current_LED_red_PWM_level < power_indicator_red_maximum_value) {
- temp_difference = power_indicator_red_maximum_value - current_LED_red_PWM_level;
- if (temp_difference > power_indicator_red_rise_value) {
- current_LED_red_PWM_level = current_LED_red_PWM_level + power_indicator_red_rise_value;
- }
- else {
- current_LED_red_PWM_level = power_indicator_red_maximum_value;
- }
- }
- else if (current_LED_red_PWM_level > power_indicator_red_maximum_value) {
- temp_difference = current_LED_red_PWM_level - power_indicator_red_maximum_value;
- if (temp_difference > power_indicator_red_decay_value) {
- current_LED_red_PWM_level = current_LED_red_PWM_level - power_indicator_red_decay_value;
- }
- else {
- current_LED_red_PWM_level = power_indicator_red_maximum_value;
- }
- }
- if (current_LED_green_PWM_level < power_indicator_green_maximum_value) {
- temp_difference = power_indicator_green_maximum_value - current_LED_green_PWM_level;
- if (temp_difference > power_indicator_green_rise_value) {
- current_LED_green_PWM_level = current_LED_green_PWM_level + power_indicator_green_rise_value;
- }
- else {
- current_LED_green_PWM_level = power_indicator_green_maximum_value;
- }
- }
- else if (current_LED_green_PWM_level > power_indicator_green_maximum_value) {
- temp_difference = current_LED_green_PWM_level - power_indicator_green_maximum_value;
- if (temp_difference > power_indicator_green_decay_value) {
- current_LED_green_PWM_level = current_LED_green_PWM_level - power_indicator_green_decay_value;
- }
- else {
- current_LED_green_PWM_level = power_indicator_green_maximum_value;
- }
- }
- if (current_LED_blue_PWM_level < power_indicator_blue_maximum_value) {
- temp_difference = power_indicator_blue_maximum_value - current_LED_blue_PWM_level;
- if (temp_difference > power_indicator_blue_rise_value) {
- current_LED_blue_PWM_level = current_LED_blue_PWM_level + power_indicator_blue_rise_value;
- }
- else {
- current_LED_blue_PWM_level = power_indicator_blue_maximum_value;
- }
- }
- else if (current_LED_blue_PWM_level > power_indicator_blue_maximum_value) {
- temp_difference = current_LED_blue_PWM_level - power_indicator_blue_maximum_value;
- if (temp_difference > power_indicator_blue_decay_value) {
- current_LED_blue_PWM_level = current_LED_blue_PWM_level - power_indicator_blue_decay_value;
- }
- else {
- current_LED_blue_PWM_level = power_indicator_blue_maximum_value;
- }
- }
- // The LED's PWM values are checked to make sure they are valid (must be from zero to 255).
- check_LED_values();
- // The PWM values are written to the three pins controlling the three primary-color LEDs.
- write_to_LED_pins();
- }
- void transition_to_hardDrive_LED_colors() {
- // This function does the same thing as transition_to_power_LED_colors(), but for the hardDrive indicator values.
- if (current_LED_red_PWM_level < hardDrive_indicator_red_maximum_value) {
- temp_difference = hardDrive_indicator_red_maximum_value - current_LED_red_PWM_level;
- if (temp_difference > hardDrive_indicator_red_rise_value) {
- current_LED_red_PWM_level = current_LED_red_PWM_level + hardDrive_indicator_red_rise_value;
- }
- else {
- current_LED_red_PWM_level = hardDrive_indicator_red_maximum_value;
- }
- }
- else if (current_LED_red_PWM_level > hardDrive_indicator_red_maximum_value) {
- temp_difference = current_LED_red_PWM_level - hardDrive_indicator_red_maximum_value;
- if (temp_difference > hardDrive_indicator_red_decay_value) {
- current_LED_red_PWM_level = current_LED_red_PWM_level - hardDrive_indicator_red_decay_value;
- }
- else {
- current_LED_red_PWM_level = hardDrive_indicator_red_maximum_value;
- }
- }
- if (current_LED_green_PWM_level < hardDrive_indicator_green_maximum_value) {
- temp_difference = hardDrive_indicator_green_maximum_value - current_LED_green_PWM_level;
- if (temp_difference > hardDrive_indicator_green_rise_value) {
- current_LED_green_PWM_level = current_LED_green_PWM_level + hardDrive_indicator_green_rise_value;
- }
- else {
- current_LED_green_PWM_level = hardDrive_indicator_green_maximum_value;
- }
- }
- else if (current_LED_green_PWM_level > hardDrive_indicator_green_maximum_value) {
- temp_difference = current_LED_green_PWM_level - hardDrive_indicator_green_maximum_value;
- if (temp_difference > hardDrive_indicator_green_decay_value) {
- current_LED_green_PWM_level = current_LED_green_PWM_level - hardDrive_indicator_green_decay_value;
- }
- else {
- current_LED_green_PWM_level = hardDrive_indicator_green_maximum_value;
- }
- }
- if (current_LED_blue_PWM_level < hardDrive_indicator_blue_maximum_value) {
- temp_difference = hardDrive_indicator_blue_maximum_value - current_LED_blue_PWM_level;
- if (temp_difference > hardDrive_indicator_blue_rise_value) {
- current_LED_blue_PWM_level = current_LED_blue_PWM_level + hardDrive_indicator_blue_rise_value;
- }
- else {
- current_LED_blue_PWM_level = hardDrive_indicator_blue_maximum_value;
- }
- }
- else if (current_LED_blue_PWM_level > hardDrive_indicator_blue_maximum_value) {
- temp_difference = current_LED_blue_PWM_level - hardDrive_indicator_blue_maximum_value;
- if (temp_difference > hardDrive_indicator_blue_decay_value) {
- current_LED_blue_PWM_level = current_LED_blue_PWM_level - hardDrive_indicator_blue_decay_value;
- }
- else {
- current_LED_blue_PWM_level = hardDrive_indicator_blue_maximum_value;
- }
- }
- //hardDrive_delay_active = false;
- // The LED's PWM values are checked to make sure they are valid (must be from zero to 255).
- check_LED_values();
- // The PWM values are written to the three pins controlling the three primary-color LEDs.
- write_to_LED_pins();
- }
- void case_power_LED_turnOn() {
- /*
- int current_case_LED_power_level = 0;
- int previous_case_LED_power_level = 0;
- int case_LED_power_indicator_rising_rate = 20;
- int case_LED_power_indicator_decay_rate = 5;
- */
- current_case_LED_power_level = current_case_LED_power_level + case_LED_power_indicator_rising_rate;
- check_case_power_LED_value();
- write_to_case_power_LED_pin();
- }
- void case_power_LED_turnOff() {
- current_case_LED_power_level = current_case_LED_power_level - case_LED_power_indicator_decay_rate;
- check_case_power_LED_value();
- write_to_case_power_LED_pin();
- }
- void check_case_power_LED_value() {
- if (current_case_LED_power_level > 255) {
- current_case_LED_power_level = 255;
- }
- if (current_case_LED_power_level < 0) {
- current_case_LED_power_level = 0;
- }
- }
- void write_to_case_power_LED_pin() {
- if (current_case_LED_power_level != previous_case_LED_power_level) {
- previous_case_LED_power_level = current_case_LED_power_level;
- analogWrite(case_power_LED_pin, current_case_LED_power_level);
- }
- }
- void case_hardDrive_LED_turnOn() {
- /*
- int current_case_LED_hardDrive_level = 0;
- int previous_case_LED_hardDrive_level = 0;
- int case_LED_hardDrive_indicator_maximum_brightness = 100;
- int case_LED_hardDrive_indicator_rising_rate = 100;
- int case_LED_hardDrive_indicator_decay_rate = 10;
- */
- current_case_LED_hardDrive_level = current_case_LED_hardDrive_level + case_LED_hardDrive_indicator_rising_rate;
- check_case_hardDrive_LED_value();
- write_to_case_hardDrive_LED_pin();
- }
- void case_hardDrive_LED_turnOff() {
- current_case_LED_hardDrive_level = current_case_LED_hardDrive_level - case_LED_hardDrive_indicator_decay_rate;
- check_case_hardDrive_LED_value();
- write_to_case_hardDrive_LED_pin();
- }
- void check_case_hardDrive_LED_value() {
- if (current_case_LED_hardDrive_level > 255) {
- current_case_LED_hardDrive_level = 255;
- }
- if (current_case_LED_hardDrive_level < 0) {
- current_case_LED_hardDrive_level = 0;
- }
- }
- void write_to_case_hardDrive_LED_pin() {
- if (current_case_LED_hardDrive_level != previous_case_LED_hardDrive_level) {
- previous_case_LED_hardDrive_level = current_case_LED_hardDrive_level;
- analogWrite(case_hardDrive_LED_pin, current_case_LED_hardDrive_level);
- }
- }
- void check_LED_values() {
- /*
- The LED PWM primary color values must be a number from zero to 255.
- If they fall outside of that range, they must be corrected first, before calling the PWM command.
- This is done for all three primary color values.
- */
- if (current_LED_red_PWM_level > 255) {
- current_LED_red_PWM_level = 255;
- }
- if (current_LED_red_PWM_level < 0) {
- current_LED_red_PWM_level = 0;
- }
- if (current_LED_green_PWM_level > 255) {
- current_LED_green_PWM_level = 255;
- }
- if (current_LED_green_PWM_level < 0) {
- current_LED_green_PWM_level = 0;
- }
- if (current_LED_blue_PWM_level > 255) {
- current_LED_blue_PWM_level = 255;
- }
- if (current_LED_blue_PWM_level < 0) {
- current_LED_blue_PWM_level = 0;
- }
- }
- void write_to_LED_pins() {
- /*
- This function contains some code so that the PWM values are only set if they are different than the previous values.
- Calling them every time might cause the LED to blink undesireably, so this only calls the change when it is necessary for each primary color.
- */
- if (current_LED_red_PWM_level != previous_LED_red_PWM_level) {
- previous_LED_red_PWM_level = current_LED_red_PWM_level;
- analogWrite(LED_red_pin, current_LED_red_PWM_level);
- }
- if (current_LED_green_PWM_level != previous_LED_green_PWM_level) {
- previous_LED_green_PWM_level = current_LED_green_PWM_level;
- analogWrite(LED_green_pin, current_LED_green_PWM_level);
- }
- if (current_LED_blue_PWM_level != previous_LED_blue_PWM_level) {
- previous_LED_blue_PWM_level = current_LED_blue_PWM_level;
- analogWrite(LED_blue_pin, current_LED_blue_PWM_level);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement