I’m just getting back into the swing of using Arduino, and I just thought, why use some stupid direction reversing FOR loop to brighten an LED, when you can use a sine wave(which arguably makes it far more complex).

I just want to share this with beginners, so they can see some different ways to do things, because I don’t think many people will do this.

Sine waves are often used in coding to calculate a natural acceleration, using the positive half of the sin wave period of y=100sin(x/1.2733).

Enter this into the Desmos Graphing calculator.

I’m sure by this point you’ve realized how this works. After the first 1/2 cycle(I only allow the positive half of the cycle, pictured by entering y=100sin(x/1.2733){4>=x>=0}) I restrict the minimum Y value(PWM value) to 10 with y=100sin(x/1.2733){3.8>=x>=.13}*approximate)

Here is the code:

```
float x = 0; //initialize X as 0.0
void setup() {
// Set pin 11 to pwm output
pinMode(11, OUTPUT);
Serial.begin(9600); //For debugging over the COM interface
}
void loop() {
// Brighten and dim the LED over ~4 seconds.
for(x = 0; x < 5; x = x+.05)
{
if(x >= 3.8) //This if statement is the restriction on the X
{ //
x=.13; //
} //
float y=100*sin(x/1.2733);// Updates the value of Y every cycle
analogWrite(11,y); // PWM outout of Half restricted sine wave.
Serial.print(x);
Serial.print(" ");
Serial.println(y);
delay(070); //I had to guess this through trial and error, it makes the cycle around 4 // seconds
}
}
```

Another way, that I only realized would be easier to write, and easier on the processor uses a full cycle, and is probably less convoluted, just use the same formula, but transformed up 110.(y=100sin(x/1.2733)+110) and rest to zero when x = 8. I’m not sure what the timing will be on this. *You will need to use map to make this work!

I hope you all enjoy this.

P.S. You can also sub in tangent and cosine for interesting results.