well there are some examples built into the IDE.
File -> Examples -> 02 Digital -> StateChangeDetection
will show you how to detect the rising and falling edges of pulses.File -> Examples -> 02 Digital -> BlinkWithoutDelay
will show you how to use the millis timer. In your case you want to record the values given at the state change rather than using the timer to detect when to do something.
I think I understand how it works, but do not understand how can make it work
const int buttonPin = 6; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to
int buttonPushCounter = 0; // counter for the number of button presses
int lastButtonState = 0; // previous state of the button
long previousMillis = 0;
int buttonState=0;
long interval = 1000;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
buttonPushCounter=0;
}
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
buttonPushCounter++;
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
else {}
}
lastButtonState = buttonPin;
}
i make this "shit" it doesnt work exactly, if the black lane of the disk stop on the LED doesnt stop the counting and something last the biggest value is 29 /sec this mean delay ?