I have a very simple test sketch in which I\'m trying to set a pin to HIGH
and then read its state with digitalRead
. Here is my sketch.
<
I wrote a routine for flashing four different LEDs for different purposes but I also wanted to retain their initial state before I flash them, as their steady state also tells me something is occurring in my code, so here is my Flash code, you call it by sending the pin number, the number of times to flash it and how long to flash it for.
inline void Flash (byte pinNum, byte times, byte flashSpeed)
{
bool state; // Local var for State of pin
state = digitalRead(pinNum); // Read the current state as set elsewhere
int x; // Local var for repeat flash
for (x = 0; x < times; x++)
{
digitalWrite(pinNum, HIGH); // Turn on LED
delay(flashSpeed);
digitalWrite(pinNum, LOW); // Turn off LED
delay(flashSpeed * 2); // leave off twice as long as on
} // due to persistence of Vision
digitalWrite(pinNum, state); // Restore the original state of the LED
}