Hello and Good Day,
I am using the source code of a binary clock by Tasos Sagiotis. The PWM pins are occupied, and can't be used to fade LEDs. I have found the following sketch which uses the digital pins to "pulse" or fade the LEDs. I would like to pass each pin as it is determined by the BC to pulse 2x before staying HIGH. Can this sketch or any sketch be changed to a function ? Thanks for your consideration.
Pulse sketch:
int ledPin = 13; // LED CONNECTED TO DIGITAL PIN 13
int value = LOW; // PREVIOUS VALUE OF THE LED
long cnt = 0; // WILL STORE LAST TIME LED WAS UPDATED
long low = 0; // INTERVAL AT WHICH TO BLINK (MILLISECONDS)
long high = 1000; // INTERVAL AT WHICH TO BLINK (MILLISECONDS)
int op = 3;
long a = 0;
int count;
void setup()
{
pinMode(ledPin, OUTPUT); // SETS THE DIGITAL PIN AS OUTPUT
}
void loop()
{
a += op;
blinkl( a+30, 10 );
if( a > 200 || a < 0 ) op *= -1;
}
void blinkl(long low, long high )
{
int c = 5;
while ( c > 0 ) {
blink( low, high );
c-=1;
}
}
void blink( long low, long high )
{
long period = 4000;
long pt = period * high / (low + high );
int value = LOW;
digitalWrite(ledPin, value);
while( period > 0 ) {
if (period < pt && value == LOW ) {
value = HIGH;
digitalWrite(ledPin, value);
}
period -= 1;
}
}