PWM Steuerung für LED Riffaquarium Sonnenauf bzw Untergang

vor 27 weeks 4 days von acoolio

Hallo,
leider brauche ich Hilfe, da ich nicht selber drauf komme.
Ich habe div.Steuerungen für mein Salzwasserbecken programmiert, soweit funktioniert auch alles, bis auf die Anzeige im LCD Display für den PWM Wert d.h ich möchte gerne den Wert von dem
byte whiteLeds[96] aufgreifen, durch 255 teilen und mal 100 multiplizieren, so das im Display angezeigt wird bei wieviel % die LED Steuerung ist.Ich komme aber nicht an diesen Wert von 0-255 ran.
Für eure Hilfe wäre ich dankbar

CODE
#include
#include
#include

// Next comes variables for white leds, you have to do the same for blues too.
byte pwmWhite = 0;

// Next idea from Dave_uk, thanks (http://www.nano-reef.com/forums/index.php?showtopic=206246)
// Array of pwm values for 15 minute sections
byte whiteLeds[96] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00-03
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00-06
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 06-09
20, 30, 40, 50, 60, 80, 100, 120, 140, 160, 180, 200, // 09-12
220, 240, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // 12-15
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // 15-18
240, 220, 200, 180, 160, 140, 120, 100, 80, 80, 80, 60, // 18-21
60, 40, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0 // 21-24
};

byte whiteMaxCurrent = 70; // Percentage of, 70 is 70%, so 1000mA puckbuck is driven at 700mA

// Next the pin for writing
byte whitePin = 11;

void setup() {
// Setup stuff, LCD, pins, RTC etc.
}

void loop() {
// Main loop
getWhitePwm();
analogWrite(whitePin, pwmWhite);
}

void getWhitePwm() {
int tempIndex = 0; // Index for the array containing dimming values for the leds, calculated in 15 mins sectors
long tempTime = 0; // Used to store number of seconds since last midnight

pwmWhite = 0; // Public variable. Reset the value (just to be sure)

tempTime = elapsedSecsToday(now()); // From Time.h, seconds since last midnight, now() is current time

// Check out what is the index of 15 min sections
tempIndex = (tempTime / (SECS_PER_HOUR / 4)); // macro SECS_PER_HOUR from Time.h

// Calculate the PWM value according the index and maximum power we have defined.
pwmWhite = ( whiteLeds[tempIndex] * (whiteMaxCurrent) /100 );

}

Ähnliche Posts

1 Antwort auf “PWM Steuerung für LED Riffaquarium Sonnenauf bzw Untergang”


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
  1. uwe sagt:

    Du brauchst nur die Variable
    pwmWhite = ( whiteLeds[tempIndex] * (whiteMaxCurrent) /100 );
    mit 1000 mutiplizieren und durch 255 teilen.
    Zum vereinfachen kannst Du schreiben:
    pwmpercent = (whiteLeds[tempIndex] * (whiteMaxCurrent))/255;
    oder wenn Du den relativen Wert haben willst (also ohne generelles Dimmen)
    pwmpercent = (whiteLeds[tempIndex]*100)/255;
    Grüße Uwe

    Login or register to post comments