Make a led blink or turn on/off using ctgα

Hello,

I need help with a code to make a two LED lights blink or turn on/off evenly using ctgα trigonometric function.
Maybe someone have done this already and could give an example or something?

Thanks

How are you hoping to make use of this function in blinking an LED ? What will it bring to the BlinkWithoutDelay party ?

I'm sorry for being not clear, I've edited my post. :slight_smile:

Sorry, but I don't find that any clearer. What does "evenly" mean ?

That the LED's should turn on/off gradualy.

Do you need to use that specific function, bearing in mind that the LED output and the human perception of levels is not very linear.

It sounds like a for loop containing the function to calculate the output value would be simple.

Well, I have to do it for school, I must use that exact function and show how the code works, but I have no idea how to write the code, I suppose it must be for loop but again I don't know much about programming.

I don't know much about programming.

It seems a strange assignment to give someone who doesn't know much about programming. Are you supposed to know the basics of programming the Arduino but have not been paying attention or has this been dumped on you ?

Either way it is unlikely that anyone here will do your homework for you. Start by looking at, running and understanding the for loop example in the IDE.

I know the basics, but I have problem with ctgα, I don't know how to use it.

Thanks anyway. :slight_smile:

I don't know how to use it either, but I bet that Google does.
For instance, what are the inputs to the function and what range of values does it produce ?

1/tan(x)

Thanks. I've tried it like that:

int ledPin = 9;
void setup ()
{
pinMode (ledPin, OUTPUT);
}

void loop ()
{
for (int x=0; x<90; x++)
{
double y;
y = (x*3.14)/90;
double v;
v = 1/tan(x);
analogWrite (ledPin, int(v));
delay(1000);
}
}

It seems to blink.

What range of values are you getting for v ?
HINT : try printing them

Does the tan() function use degrees or radians I wonder ....
Why do you calculate a value for y then never use it ?

Proving yet again that meaningless variable names are poison.