I've been trying to set up an infrared phototransistor I have to measure the rotations of a wheel, but I'm stuck on the programming. If I just tell it to add 1 to x if it sees white, then the RPM in the end will be in the 20,000's, but with the current code it is always at 0. I'm expecting the actual results to be in the thousands, but I can't get it to function correctly. Does anyone have an idea of what I can change to get this to work?
#include <Metro.h>
int val=0;
int x=0;
int y=0;
Metro serialMetro=Metro(15000);void setup(){
Serial.begin(9600);
delay(2500);
}void loop(){
val=analogRead(5);
if(y=0){
if(val>1000){
x++;
y=1;
}
}
if(y=1){
if(val<1000){
y=0;
}
}
if(serialMetro.check()==1){
Serial.print("Rpm ~");
Serial.println(x*4);
x=0;
}
}