Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int PUMP_PIN = 9; // output to mosfet driving the pump
- const int BUTTON_PIN = 2; // input from start button
- const int LED_PIN = 13; // status led
- const int PULSE_COUNT = 1000; // number of pulses to generate
- const int PULSE_WIDTH = 22; // pulse width in milliseconds
- const int PERIOD = 200; // total period in milliseconds (5hz = 200ms)
- void setup() {
- // set up pin modes
- pinMode(PUMP_PIN, OUTPUT);
- pinMode(LED_PIN, OUTPUT);
- pinMode(BUTTON_PIN, INPUT_PULLUP);
- // ensure pump is off at startup
- digitalWrite(PUMP_PIN, LOW);
- // initialise serial for debugging
- Serial.begin(9600);
- Serial.println("diesel pump calibration system");
- Serial.println("press button to start 1000 pulses at 5hz");
- }
- void loop() {
- // wait for button press (active low due to pull-up)
- while (digitalRead(BUTTON_PIN) == HIGH) {
- // blink led while waiting
- digitalWrite(LED_PIN, !digitalRead(LED_PIN));
- delay(100);
- }
- // debounce button
- delay(50);
- // turn on led to indicate running
- digitalWrite(LED_PIN, HIGH);
- Serial.println("starting 1000 pulses sequence...");
- // generate 1000 pulses
- for (int i = 0; i < PULSE_COUNT; i++) {
- // turn on pump
- digitalWrite(PUMP_PIN, HIGH);
- // keep on for pulse width duration
- delay(PULSE_WIDTH);
- // turn off pump
- digitalWrite(PUMP_PIN, LOW);
- // wait for remainder of period
- delay(PERIOD - PULSE_WIDTH);
- // print progress every 100 pulses
- if (i % 100 == 0) {
- Serial.print("pulses completed: ");
- Serial.println(i);
- }
- }
- // turn off led when complete
- digitalWrite(LED_PIN, LOW);
- Serial.println("sequence complete! 1000 pulses delivered.");
- Serial.println("check if you have 65ml in the measuring flask.");
- // wait for button release before allowing another cycle
- while (digitalRead(BUTTON_PIN) == LOW) {
- delay(10);
- }
- // debounce button release
- delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement