const byte Q1; // PWM pin
const byte Q2; // PWM pin
const byte Q3; // PWM pin
const float pi = 3.1415;
float x = 0;
const byte enable = 8;
const byte freqpin = A0; // Freq adjust pot
unsigned char p1 = 0;
unsigned char pp1 = 0;
unsigned char pp2 = 0;
unsigned char pp3 = 0;
unsigned char p2 = 0;
unsigned char p3 = 0;
const float y = pi/30;
const float ph1 = 2*pi/3;
const float ph2 = 4*pi/3;
const float ph3 = 2*pi;
// int q1 = 0;
void setup() {
Serial.begin(9600);
pinMode(Q1, OUTPUT);
pinMode(Q2, OUTPUT);
pinMode(Q3, OUTPUT);
pinMode(enable, INPUT);
pinMode(freqpin, INPUT);
}
void loop() {
while(1) {
x = x + y;
analogWrite(Q1, p1);
analogWrite(Q2, p2);
analogWrite(Q3, p3);
Serial.print(p2);
Serial.print(" ");
Serial.println(p3);
pp1 = 126*sin(x+ph1);
p1 = pp1+128;
pp2 = 126*sin(x+ph2);
p2 = pp2+128;
pp3 = 126*sin(x+ph3);
p3 = pp3+128;
if(x >= 2*pi) x = 0;
delay(analogRead(freqpin));
}
analogWrite(Q1, p1);
Serial.print(Q1);
Serial.print(" ");
analogWrite(Q2, 0);
analogWrite(Q3, 0);
x = 0;
}
// unsigned long Phase_1;
// bool running = false;
// //anologWrite = (Q1, 0);
// void setup() {
// Serial.begin(9600);
// for(Phase_1 = 0; Phase_1 <= 255; ){
// delayMicroseconds(100);
// Phase_1++;
// if(Phase_1 == 255){
// for(Phase_1 = 255; Phase_1 >= 0; ){
// delayMicroseconds(100);
// Phase_1--;
// // Serial.println(running);
// // running = !running;
// // break;
// }
// }
// }
// void loop(){
// }