#include <Arduino.h>

const int hallSensorPin = D1; // The Hall sensor on D1
const int outputPin = D2; // The coil driver on D2

const float wheelCircumference = 2.094; // Circumference of the bike wheel in meters (adjust this based on your wheel size)
const unsigned long debounceDelay = 50; // Debounce delay in milliseconds

volatile unsigned long lastHallPulseTime = 0;
volatile unsigned long timeBetweenPulses = 3001;
volatile unsigned long targettimeBetweenPulses = 3001;
volatile float speedKmh = 0.0;
volatile float lastspeedKmh = 100.0;

volatile unsigned long lastOutputTime = 0;

void setup() {
  pinMode(hallSensorPin,INPUT_PULLUP); // Set the Hall sensor pin as input with internal pullup resistor
  pinMode(outputPin, OUTPUT);

  Serial.begin(115200); // Start the Serial communication for debugging
}

void loop() {
  delay(500);
  //turn pin high
  digitalWrite(outputPin, HIGH);
  Serial.println("HIGH");
  //pulse width
  delay(500 * 0.0124);
  //turn pin down
  digitalWrite(outputPin, LOW);
  Serial.println("LOW");
}
