int tabPulseSinusOn[101];
int tabPulseSinusTotal[101];
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-C3!");
float erreur;
float vrai;
float target;
for (int I = 0; I < 101; I++) {
tabPulseSinusTotal[I] = -1;
tabPulseSinusOn[I] = -1;
target = float(I) / 100.0;
for (int T = 20; T < 101; T++) {
for (int N = 0; N <= T; N++) {
// if (T % 2 == 1 || N % 2 == 0) { // Valeurs impair du total ou pulses pairs pour éviter courant continu
if ((T % 2) ^ (N % 2) == 0){
vrai = float(N) / float(T);
erreur = abs(vrai - target);
if (erreur < 0.004) {
tabPulseSinusTotal[I] = T;
tabPulseSinusOn[I] = N;
N = 101;
T = 101;
}
else{
// N = 83;
// T = 84;
}
}
}
}
}
}
void loop() {
for (int I = 0; I < 101; I++) {
Serial.print (I);
Serial.print(" \t");
Serial.print(tabPulseSinusTotal[I]);
Serial.print(" \t");
Serial.print(tabPulseSinusOn[I]);
Serial.print(" \t");
Serial.print(float(float(tabPulseSinusOn[I])/float(tabPulseSinusTotal[I])),3);
Serial.print(" \t");
Serial.print (float(I) / 100.0);
Serial.print(" \t");
if((tabPulseSinusTotal[I] % 2) ^ (tabPulseSinusOn[I] % 2 )){
Serial.println ("bad");
}
else {
Serial.println ("ok");
}
}
delay(10000); // this speeds up the simulation
}