void setup()
{
 Serial.begin(9600);
 int i;
 for (i=0; i < 8; i++)
   pinMode(i,OUTPUT);
}

/*
without volatile approx 60 usec /256 but some glitches
volatile unsigned char j 150 usec for 256 loops
with arduino loop (without goto) ~ 300usec/256
*/

double sinV;
float rads=0.0;

int i;
volatile unsigned int j=0;
void loop()
{
  sinV = sin(rads);
  rads += 0.314159265;  // 1/20 af 2*pi
  i = 127.0*sinV;  // [-1; 1] -> [-127;127]
  i+= 127;  // [-127;127] -> [0;255]
  
  // clip just in case
  if (255 < i)
    i = 255;
  else if (i < 0)
    i = 0;
 
   PORTD=i;
   delay(47); // 1 Hz sampled 20 times a second
   // which means code in loop takes 50-47 msec = 3 msec
   // found by measuring - so it is only approximative
   
 }
