Last active
January 11, 2018 08:02
-
-
Save sourceperl/c87107bccb78ee941a864712604a14e2 to your computer and use it in GitHub Desktop.
Super simple 1000 pulses generator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
1000 pulses generator (100ms width/5 Hz) | |
Send pulseCount to MOSFET transitor connect to D2 pin. | |
Push FLASH button (link to D3) to start generator. | |
Push RST button to stop generator and clear counter. | |
Test with ESP-12 on nodemcu. | |
This example code is in the public domain. | |
*/ | |
// const | |
#define PIN_PULSE D2 | |
#define PIN_FLASH_BUTTON D3 | |
#define PULSE_NB 1000 | |
#define PULSE_WIDTH_MS 100 | |
// vars | |
bool do_pulse = false; | |
uint32_t pulseCount = PULSE_NB; | |
void setup() { | |
// initialize digital pin LED_BUILTIN as an output. | |
pinMode(PIN_PULSE, OUTPUT); | |
digitalWrite(PIN_PULSE, LOW); | |
// flash button | |
pinMode(PIN_FLASH_BUTTON, INPUT); | |
} | |
void loop() { | |
// wait button press | |
if(digitalRead(PIN_FLASH_BUTTON) == LOW) | |
do_pulse = true; | |
// pulse generator | |
if(do_pulse and pulseCount > 0) { | |
digitalWrite(PIN_PULSE, HIGH); | |
delay(PULSE_WIDTH_MS); | |
digitalWrite(PIN_PULSE, LOW); | |
delay(PULSE_WIDTH_MS); | |
pulseCount--; | |
} | |
// reset value for next loop | |
if(pulseCount == 0) { | |
pulseCount = PULSE_NB; | |
do_pulse = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment