who can blink LED  like sine wave ???

Can you give me any code????????

my model is duemilanove

I am going to assume you don't actually mean you want to blink an LED but make it's intensity (brightness) change following the curve of a sine wave.

I don't have any code examples. But you should probably do some research on just generating sine waves first. It seems some people use lookup tables that have been pre generated. Essentially you would find the equation for your sine wave. Select 255 (or other depending on resolution) evenly divided points across the sine wave. Get values for these points (should be 0 - 255)... . then store these in the memory of the Arduino.

You would then just loop through these values and apply them to the output the LED is on.

Or just use the sin() function..

void loop()
{
  float something = millis()/1000.0;
  int value = 128.0 + 128 * sin( something * 2.0 * PI  );
  analogWrite(ledPin,value);
}

Where something is from 0 to 1 (ideally, or a multiple of), and is whatever you base the sin on. Note the 1000.0, to make it a float calculation (since we need the decimals).

You might have to restrict the int value in the 0 - 255 range to prevent wrap to 0 instead of 256.

And you must use a PWM output pin for analogWrite to work.

so , how can I generate a sine wave

raron , the led doesn't blink like sine wave

Did you use a PWM output? It works for me.
I don't have a duemilanove, but it should'nt matter.

I forgot to say that the millis() / 1000.0 was for a 1000 ms (as in 1 second) period.

Don't forget to compensate for the eye's logarithmic respose, or you won't perceive a true sine brightnesss curve.

raron, no I haven't connected to pwm,how can I connect it and I'm a beginner

The Duemilanove:

As you can see, not all the pins can provide a PWM output. Only pins 3, 5, 6, 9, 10 and 11. You must use one of these for analogWrite() to work.

That is for a hardware PWM (built-in the arduino). Software PWM is certainly possible too, on any pin, but the program would be more complex and use more processor time. I thought I saw a software PWM library somewhere, but I can't find it at the moment.

Btw, PWM (Pulse Width Modulation) is really a trick, it's not an analogue signal. It's digital, but as the name implies, its pulsing and the width of these pulses are what varies. The frequency on the arduino is about 450-500 Hz, so you wont see any flicker is you connect it to a LED.

Oh and you use a resistor in series with the LED I hope?

Groove:

Don't forget to compensate for the eye's logarithmic respose, or you won't perceive a true sine brightnesss curve.

True, but I think we can forgo that for now? :stuck_out_tongue:

so what is the complete code I can upload to the board??? and how can I connect it ??

Well the only thing missing from the code above is basically the setup() routine, like this: setup() - Arduino Reference
Modify as required (little exercise for you there :wink: ). Then just follow it with the loop() function, as in any arduino sketch: http://arduino.cc/en/Tutorial/Sketch

As for how to connect the LED, do it like this: http://www.makingthings.com/documentation/how-to/connect-an-led-to-a-digital-output
Doesn't matterJust remember to use a PWM output.

int Pin = 3;

void setup()
{
Serial.begin(9600);
pinMode(Pin, INPUT);
}

void loop()
{
float something = millis()/5000.0;
int value = 128.0 + 128 * sin( something * 2.0 * PI );
analogWrite(Pin,value);
}

I got the code, so amazing , thx raron so much

just to comment..

raron-

awesome work !

SO many time do I see beginners talked down to.. or just put off with tech babel or random links with no help explaining what they are being linked to.

KUDOS man!

Delivery of good info..

links to help understand what was just explained to him..

example code

and even a quick 'homework' assignment for him to not be spoon fed as much.

A+ help!!!!!

raron
, how can i contact you??????

@ 875584189:

I got the code, so amazing , thx raron so much

That's great!

One or two little details though:

int Pin = 3;

void setup()
{
 pinMode(Pin, [glow]OUTPUT[/glow]);
}

void loop()
{
 float something = millis()/5000.0;
 int value = 128.0 + 128 * sin( something * 2.0 * PI  );
 analogWrite(Pin,value);
}

I didn't know it would work while the pin was set as an INPUT? (I guess, maybe the internal pullup resistor is turned on and off with PWM and the LED is really dim?) Anyway, it should be an output.
Also, as the serial connection is not used, you don't need a "Serial.begin()" thing.

As for contacting me, you could PM me. Just be "warned" I got pretty weird hours and are not always here, so to speak. Hard to explain. I think you would be better off just posting your questions in the forum somewhere. It's more probable that you get an answer quicker that way.

@ xl97:

A+ help!!!!!

lol thanks! :slight_smile: