Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define pulseLength 50 // Set the length of a pulse
- #define numOfPins 8 // Set the number of pins the microcontroller got
- int stepsLeft[numOfPins]; //Array to store how many times it should flash the pin
- int stepDelay[numOfPins]; //Array to store how long a delay there should be between the pin state changing
- unsigned long lastStep[numOfPins]; //Array to store when the pin was changed last
- void cyclePins()
- {
- unsigned long now = millis();
- for (int i = 0; i <= numOfPins; i++) // Run through the arrays to see if any pin should be changed
- {
- if (stepsLeft[i] > 0) // Do we have to do any steps on this pin?
- {
- if (now - lastStep[i] >= stepDelay[i]) // Calculate if we are at, or passed the set delay time between pulses
- {
- lastStep[i] = now; // Set when we set the pin HIGH, so we can calculate when to set it LOW again
- digitalWrite(i, HIGH); // Set pin to HIGH
- }
- if (now - lastStep[i] >= pulseLength) // Check if pin has been HIGH long enough
- {
- digitalWrite(i, LOW); // Set pin to LOW
- stepsLeft[i]--; // Remove one step
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement