Skip to content

Instantly share code, notes, and snippets.

@carneeki
Created August 29, 2019 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carneeki/f15b4558801f91f92a16c96252ca4fc1 to your computer and use it in GitHub Desktop.
Save carneeki/f15b4558801f91f92a16c96252ca4fc1 to your computer and use it in GitHub Desktop.
/*
* 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