//
// Array of sine raised to the power of 4 and scaled to the range 0 to 255 in fixed point Q15 notation.
// Range: 0 to 90 degrees.
// Resolution: 1 degree per step.
//
const int32_t sin4[] =
{
0,
1,
12,
63,
198,
482,
998,
1843,
3135,
5004,
7598,
11076,
15614,
21396,
28621,
37495,
48233,
61056,
76194,
93877,
114340,
137818,
164548,
194761,
228688,
266553,
308573,
354958,
405908,
461610,
522240,
587960,
658914,
735233,
817028,
904389,
997390,
1096080,
1200489,
1310622,
1426462,
1547967,
1675073,
1807688,
1945697,
2088960,
2237312,
2390562,
2548496,
2710875,
2877438,
3047898,
3221949,
3399262,
3579486,
3762255,
3947180,
4133860,
4321873,
4510789,
4700160,
4889530,
5078434,
5266398,
5452942,
5637583,
5819836,
5999215,
6175236,
6347418,
6515284,
6678368,
6836210,
6988362,
7134387,
7273865,
7406390,
7531576,
7649053,
7758476,
7859519,
7951880,
8035284,
8109479,
8174242,
8229378,
8274719,
8310129,
8335498,
8350751,
8355840 // sin(0.5 * PI)^4 x 255 x 2^15
};
const int32_t Q15_HALF = 2 ^ 14;
void setup()
{
Serial.begin(115200);
}
void loop()
{
for (int x = 0; x <= 90; x++)
{
int absX = abs(x);
int32_t sin4AbsX = sin4[absX];
int32_t brightness = (sin4AbsX + Q15_HALF) >> 15;
Serial.println(brightness);
analogWrite(3, brightness);
delay(100);
}
}