Counting with a phototransistor.

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;
}
}

if(y=0){

Been there, done that , repeatedly kicked myself :slight_smile:

if you say if( y=0) it will make it so, you need to say if( y==0 ) ( is equal to )

If you write it if (0 == y( then if you forget one of the =, the compiler wil give you an error message

Thanks so much, it's working perfectly now. The == and = always throw me for a loop(no pun intended)