Juraj:
not true. the do_spm function of Optiboot 8 mediates the ability of bootloader to write to flash.
Yeah, I was assuming stock bootloaders
And I would get something like:
#include <avr/pgmspace.h>
const int SinTable[] PROGMEM = {0, 572, 1144, 1715, 2286, 2856, 3425, 3993, 4560, 5126, 5690, 6252, 6813, 7371, 7927, 8481, 9032, 9580, 10126, 10668, 11207, 11743, 12275, 12803, 13328, 13848, 14364, 14876, 15383, 15886, 16384, 16876, 17364, 17846, 18323, 18794, 19260, 19720, 20173, 20621, 21062, 21497, 21925, 22347, 22762, 23170, 23571, 23964, 24351, 24730, 25101, 25465, 25821, 26169, 26509, 26841, 27165, 27481, 27788, 28087, 28377, 28659, 28932, 29196, 29451, 29697, 29934, 30162, 30381, 30591, 30791, 30982, 31163, 31335, 31498, 31650, 31794, 31927, 32051, 32165, 32269, 32364, 32448, 32523, 32587, 32642, 32687, 32722, 32747, 32762, 32767};
void setup() {
Serial.begin(115200);
Serial.println(F("===Sin==="));
for(unsigned int i = 0; i <= 360; i++){
Serial.println(sinLookup(i));
}
Serial.println(F("===Cos==="));
for(unsigned int i = 0; i <= 360; i++){
Serial.println(cosLookup(i));
}
}
void loop() {
// put your main code here, to run repeatedly:
}
int sinLookup(unsigned int n){
if(n <= 90){
return SinTable[n];
}
if(n <= 180){
return SinTable[90 - (n - 90)];
}
if(n <= 270){
return -SinTable[n - 180];
}
if(n <= 360){
return -SinTable[90 - (n - 270)];
}
else{
return 0;
}
}
int cosLookup(unsigned int n){
if(n <= 270){
return sinLookup(n + 90);
}
if(n <= 360){
return sinLookup(n - 270);
}
else{
return 0;
}
}
Compiles but untested
And I just assumed a full scale 16-bit signed sin/cos. Note, sinLookup() and cosLookup() only work for 0 <= angle <= 360. You could make them work for higher and negative as well but was more work