Created
August 29, 2019 02:50
-
-
Save carneeki/f15b4558801f91f92a16c96252ca4fc1 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* Arduino Pulsinator for Andre by Adam | |
* Direction pin is controlled directly by a switch, no code needed | |
*/ | |
#define A_IN A0 // 10K linear pot wiper | |
#define P_OUT 5 // pulse output pin (digital 5) | |
bool pulseState = false; // pulse pin will be one of high or low | |
unsigned long nextUpdate = 0; // schedule variable to track when tasks | |
// should be done (in milliseconds) | |
// setup() happens only once when | |
// the arduino is first turned on | |
void setup() { | |
pinMode(A_IN, INPUT); // setup analog input | |
pinMode(P_OUT, OUTPUT); // setup digital output | |
} | |
// loop() happens over and over | |
void loop() { | |
if(nextUpdate <= millis()) { // Do we need to do tasks? | |
pulseState != pulseState; // Toggle the pin state | |
digitalWrite(P_OUT, pulseState); // Send the new pin state | |
nextUpdate = millis() + (analogRead(A_IN)/4096); // schedule the next | |
// time to do stuff | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment