#define enablePin 3
#define in1Pin 9
#define in2Pin 10
#define in3Pin 11
#define in4Pin 6 // másik PWM láb

#define pwmResolution 255
#define numSamples 256

int sinTable[numSamples];
int cosTable[numSamples];

void setupTable() {
  for (int i = 0; i < numSamples; i++) {
    sinTable[i] = pwmResolution / 2 + (sin(i * 2 * PI / numSamples) * (pwmResolution / 2));
    cosTable[i] = pwmResolution / 2 + (cos(i * 2 * PI / numSamples) * (pwmResolution / 2));
  }
}

void setupTimer1() {
  // Set timer1 to fast PWM mode
  TCCR1A = _BV(WGM11) | _BV(WGM10) | _BV(COM1A1) | _BV(COM1B1);
  TCCR1B = _BV(WGM12) | _BV(CS11); // prescaler = 8
  OCR1A = 0;
  OCR1B = 0;
}

void setup() {
  pinMode(enablePin, OUTPUT);
  pinMode(in1Pin, OUTPUT);
  pinMode(in2Pin, OUTPUT);
  pinMode(in3Pin, OUTPUT);
  pinMode(in4Pin, OUTPUT);
  
  setupTable();
 // setupTimer1();
  
  digitalWrite(enablePin, HIGH);  // Enable H-bridge
}

void loop() {
  for (int i = 0; i < numSamples; i++) {
    analogWrite(in1Pin, sinTable[i]);
    analogWrite(in2Pin, pwmResolution - sinTable[i]);
    analogWrite(in3Pin, cosTable[i]);
    analogWrite(in4Pin, pwmResolution - cosTable[i]);
    delay(10);
  }
}