There were some 1s representing the output being high.
To make sure we’re on the same page
int TPS = 0;
//int CPS = 0;
int sequence[48] = {0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0};
//int sequence[48] = {1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1};
//int cam[48] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int tooth = 0;
int low = 0;
int high = 0;
int RPMlow = 0;
int RPMhigh = 0;
int math = 1;
int halfdone = 1;
int done = 1;
int previousmicros = 0;
void setup() {
pinMode(A0, INPUT);
//pinMode(A1, INPUT);
//pinMode(A2, INPUT);
//pinMode(A3, INPUT);
pinMode(0, OUTPUT);
//pinMode(1, OUTPUT);
//pinMode(2, INPUT);
//pinMode(3, INPUT);
Serial.begin(921600);
}
void loop() {
int currentmicros = micros();
if (halfdone == 0) {
if (currentmicros - previousmicros >= RPMlow) {
halfdone = 1;
done = 0;
digitalWrite(0, 0);
previousmicros = currentmicros;
}
}
if (done == 0) {
if (currentmicros - previousmicros >= RPMhigh) {
done = 1;
math = 1;
digitalWrite(0, 1);
previousmicros = currentmicros;
}
}
if (math == 1) {
tooth++;
if (tooth == 48) {
tooth = 0;
}
TPS = analogRead(A0);
if (sequence[tooth] == 0) {
low = 1;
high = 2;
}
else {
low = 2;
high = 1;
}
halfdone = 0;
math = 0;
RPMlow = low * TPS;
RPMhigh = high * TPS;
Serial.print(" TPS=");
Serial.println(TPS);
Serial.print(" tooth=");
Serial.println(tooth);
}
//Serial.print("low");
//Serial.print(RPMlow);
//Serial.print("high");
//Serial.print(RPMhigh);
//Serial.print(" TPS=");
//Serial.print(TPS);
//Serial.print("A1");
//Serial.print(analogRead(A1));
//Serial.print("A2");
//Serial.print(analogRead(A2));
//Serial.print("A3");
//Serial.print(analogRead(A3));
//Serial.print(" D0=");
Serial.println(digitalRead(0));
//Serial.print("D1");
//Serial.print(digitalRead(1));
//Serial.print("D2");
//Serial.print(digitalRead(2));
//Serial.print("D3");
//Serial.print(digitalRead(3));
}