I have a small code that takes a clock signal input ( 50 - 1000 Hz) and divides it sequentially over 4 outputs, like a shift register, using the Arduino Nano. No output can stay HIGH for any length of time, i.e. in the absence of a clock signal. Any output being high for more than .5 seconds would cause overheating on the external circuit that is driven from this Arduino.
The external circuit which generates the clock signal has an output that goes HIGH during clock being present, but I cannot find a reliable way to use that, because so far in my code, it is a brute force reset of the whole code using another ISR.
I would really like a safe and elegant solution to my code problem.
Thanks.
// Slave unit using IR LED as input from Master unit.
int clock = 3 ;
int PwrOn = 2 ;
int powerReset = 12 ;
int h = 4 ;
int k = 8 ;
int d = 0 ;
void setup()
{
for (int i = 4; i<12; i=i+1)
{
pinMode (i, OUTPUT) ; // Make pins 4-11 outputs
digitalWrite (i, LOW) ; // Set all outputs to LOW.
digitalWrite (powerReset, HIGH) ; // Set reset output to high, set to low via runReset void
}
pinMode (clock, INPUT) ; // Clock signal from IR LED
pinMode (PwrOn, INPUT) ; // Check for signal presence using AC to DC Detctor circuit
attachInterrupt (digitalPinToInterrupt (clock), Shift, RISING) ; // detect clock rising edge to run
// shift (void) output to next pin
attachInterrupt (digitalPinToInterrupt (PwrOn), runReset, LOW) ; //Reset program if PwrOn pin is high
// wire pin 12 to pin RST, locations next to GND
}
void loop()
{
if (digitalRead (PwrOn) == HIGH ) ;
{
Shift () ;
}
digitalWrite (h, LOW) ;
digitalWrite (k, LOW) ;
}
void Shift () // Sequentially make the outputs go high
{
digitalWrite (h, LOW) ; // Because of dual pwr supplies,
digitalWrite (k, LOW) ; // two outputs will be high at the same time
delayMicroseconds(1);
h = h + 1 ;
k = k + 1 ;
if ( h > 7 )
{
h = 4 ;
k = 8 ;
}
digitalWrite (h, HIGH) ;
digitalWrite (k, HIGH) ;
}
void runReset ()
{
digitalWrite (powerReset, LOW) ;
}