ScAlAn

Arduino fast sin function

Task: Create fast function to get math sinus.

One of implementation – create array for each degree values:

float sin[91] = {
  0.00,  0.84,  0.91,  0.14, -0.76, -0.96, -0.28,
  0.66,  0.99,  0.41, -0.54, -1.00, -0.54,  0.42,
  0.99,  0.65, -0.29, -0.96, -0.75,  0.15,  0.91,
  0.84, -0.01, -0.85, -0.91, -0.13, -0.76,  0.96,
  0.27, -0.66, -0.99, -0.40,  0.55,  1.00,  0.53, 
 -0.43, -0.99, -0.64,  0.30,  0.96,  0.75, -0.16,
 -0.92, -0.83, -0.02,  0.85,  0.90,  0.12, -0.77,
 -0.95, -0.26,  0.67,  0.99,  0.39, -0.56, -1.00,
 -0.52,  0.44,  0.99,  0.64, -0.30, -0.97, -0.74,
  0.17,  0.92,  0.83, -0.03, -0.86, -0.90, -0.11,
  0.77,  0.95,  0.25, -0.68, -0.99, -0.39,  0.57,
  1.00,  0.51, -0.44, -0.99, -0.63,  0.31,  0.97,
  0.73, -0.18, -0.92, -0.82,  0.04,  0.86,  0.89 
};

Example:

for( x = 0; x <= 90; x++){
        sinValue = sin[x];
}

This solution is very fast and simple.

Leave a Reply

Your email address will not be published. Required fields are marked *