(Another) DIY LED Controller - Simple Arduino Style

I've been following this post and got my last piece this weekend and the controller is up and running. Thanks for everyone's input, especially ketchupoy.

One question. Does anyone know how to program for the "P" and make it smoother (0-255) instead of the steps in the current sketch?
 
I've been following this post and got my last piece this weekend and the controller is up and running. Thanks for everyone's input, especially ketchupoy.

One question. Does anyone know how to program for the "P" and make it smoother (0-255) instead of the steps in the current sketch?

I tried that by breaking down the steps by minutes and failed.

I just tried to rewrite it and now I think I have it:

PHP:
for (int i = 1; i <= whiterampup; i++)

analogWrite(white, int (i/whiterampup*255)) 

int countdown = 60 ;
 
Last edited:
Just ordered a 4 5v relay board off ebay with my ebay bucks ive earned lol good ole ebay paying me back.

the only advantage of these relays are that they run straight from arduino without using transistors.... if you want to run 12v relay coils which you can, you just need to run it thru transistors.
 
PHP:
for (int i = 1; i <= whiterampup; i++)

analogWrite(white, int (i/whiterampup*255)) 

int countdown = 60 ;

RARGH...Does Arduino not know how to handle decimals?

It knows what (i) equals.
It knows what the (whiterampup) time is.
But when it is told to do (i/whiterampup) it equals 0....

Any help please...I just am at a loss...

EDIT:And not until the end of the phase when (i/whiterampup) = 1 did it fire the light up. So basically it has no way to handle decimal/fractions?
 
Last edited:
Molehs, you are casting to integer after the calculation, that's probably why you're getting a 0.

(the 'int' word in your analogWrite)

EDIT: I'm not saying you shouldn't cast, just that you're probably getting some fraction from some miscalculation, thus the 0)

EDIT2: I'd strongly recommend that you look at the map function for sunrise/sunset. It doesn't lock your sketch like your for loops do. You can see examples of it in the other two controller firmwares and the arduino sketches thread.
 
Try (255*i)/whiterampup
Integer math is fun :). There are not fractions so a number divided by a bigger number is always zero. Even if it is 9999/10000. If you want to multiply by a percent X/100 then multiply first.(Y * X) / 100.

Also I always use parentheses. Then I don't have to remember which takes precedent.
 
Molehs, you are casting to integer after the calculation, that's probably why you're getting a 0.

(the 'int' word in your analogWrite)

EDIT: I'm not saying you shouldn't cast, just that you're probably getting some fraction from some miscalculation, thus the 0)

EDIT2: I'd strongly recommend that you look at the map function for sunrise/sunset. It doesn't lock your sketch like your for loops do. You can see examples of it in the other two controller firmwares and the arduino sketches thread.

Lately I tried making the fraction a float:

f
PHP:
or (int i = 1; i <= whiterampup; i++)
float currentramp = float(i/bluerampup);
analogWrite(white, (currentramp*255)) 
int countdown = 60 ;

I've tried both int and no int on the (currentramp*255) and still 0.

Map function? Sorry very new to this where in which thread?
 
Okay (255*i)/whiterampup works (makes no sense as parentheses mean nothing in multiplication/division) but happy it works, but (((100*i)/whiterampup)/100) still comes out 0
 
float(i/bluerampup) does not work because i and bluerampup are integers it does integer math and then cast the result (0) to a float. This should work (float) i / (float)bluerampup in this case they are cast first and then the math is done.

(((100*i)/whiterampup)/100) if i < whiterampup if so using integer math will always give you zero becuase the final answer (even as a float) is less than zero.

(255*i)/whiterampup if i is 10 and whiterampup is 100 works becuase the processor does 255 * 10 = 2550 / 100 = 25 it didn't work before as i / whiterampup*255 because 10/100 = 0 * 255 = 0

What are you trying to do and maybe I can help out.
 
TheFishMan65, actually your first answer had the answer. I go so wrapped up in the math "not working" that I overlooked that I was asking it to do something that wasn't really needed.

You second answer does add some better understanding of how to use the code and numbers thank you.
 
I've been following this post and got my last piece this weekend and the controller is up and running. Thanks for everyone's input, especially ketchupoy.

One question. Does anyone know how to program for the "P" and make it smoother (0-255) instead of the steps in the current sketch?

You can make an experiment, make a small sketch to fadeout/in a led and make it to the Pin where you have your 48P circuit.
Then make lcd.print(fade); to see where it turns ON, dont forget a delay to give you time to see the fade value.
In my case it works better as I post earlier. (better is far from well/smooth)
 
const int ledPin1 = 2; // pin number for relay 1
const int ledPin2 = 8; // pin number for relay 2

int ledState1 = LOW;
int ledState2 = LOW;
long previousMillis1 = 0;
long previousMillis2 = 0;
long interval1 = 30000; // interval at which to blink (milliseconds) for RELAY1
long interval2 = 50000; // interval at which to blink (milliseconds) for RELAY2


Katchupoy, is this relay for the wave mker or for leds?
 
Back
Top