Author Options:

Can someone make me some code for an arduino? Answered

I need the code to make a white LED pulsate, reaching the peak every one second, and and the other way around. I need it for a night light i am making with an ARDUINO duemilanove. If someone wants to be really helpful, write me some code like this, only the throbbing starts at 10 at night and stops at 6 in the morning. Then i can make a throbbing apple logo to put on my door to show that i am sleeping! :-)


Excellent idea for a project.

You're going to wire up the led, or a power transistor to one of the analogue out (pwm) pins. I made code exactly like this for a valentine last year.

pseudocode (as I forget the sketch)

constant delay; //the delay for each 'frame' of the animation
constant delay2; //the delay at full brightness
constant delay3; //the delay at off

for i = 0,255,1; //ramp up
analogue out pin = i
wait(delay); //slow the animation
next i

wait(delay2); //wait at full on

for i = 254,0,-1;
analougeout pin = i
wait(delay); //slow down animation
next i

wait(delay3); //wait a bit with led off

end loop //start all over again

Maintaining a realtime clock in an arduino is tricky, as it forgets every time it turns off. There are sketch examples of using a real clock and configuring code interrupts for starting within your interval. I'd definitely say use a switch or sensor that knows if you're in bed :D check http://www.arduino.cc for code examples, and the forums are infinitely helpful.

Post an ible when you're done!

Thanks :D I found the old sketches -started working with my duino again, this time having a shift register output 8, 4-bit 16 level brightness pwm :D It takes a lot of shifting to fake brightness on a digital line.

Lastly, that guy uses a gamma-corrected exponential brightness for his levels to better match the pulse on a mac...

note that is NOT the C code for a real arduino, thats just the pseudocode to get the idea across.