32 lines
565 B
C++
32 lines
565 B
C++
const int HALL_PIN = 2;
|
|
const int ROUND_COUNT = 2;
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
|
pinMode(HALL_PIN, INPUT);
|
|
}
|
|
|
|
void loop() {
|
|
float start = micros();
|
|
int count = 0;
|
|
bool change = false;
|
|
while (count < ROUND_COUNT) {
|
|
if (digitalRead(HALL_PIN) == LOW) {
|
|
if(!change) {
|
|
change = true;
|
|
count++;
|
|
}
|
|
} else {
|
|
change = false;
|
|
}
|
|
}
|
|
|
|
float end = micros();
|
|
float passed = (end - start);
|
|
Serial.print("Diff: ");
|
|
Serial.print(passed);
|
|
Serial.println("micro seconds");
|
|
|
|
}
|