Thank you very much, folks. Renaming the file and #include-ing it were the secret sauce I needed. For the sake of others that may search for something similar, I have made some examples that others may learn from. I have used Bill Earl's Flasher class along with Examples -> 02. Digital -> Button for the demo.
Here is the basic, monolithic version:
/*
Classes demo
Change flash rate by pressing a button
*/
/*
Flash Without Delay - Class
From: https://learn.adafruit.com/multi-tasking-the-arduino-part-1/a-classy-solution
*/
class Flasher
{
// We start by declaring a “Flasher” class:
// Then we add in all the variables from FlashWithoutDelay. Since they are part of
// the class, they are known as member variables.
// Class Member Variables
// These are initialized at startup
int ledPin; // the number of the LED pin
long OnTime; // milliseconds of on-time
long OffTime; // milliseconds of off-time
// These maintain the current state
int ledState; // ledState used to set the LED
unsigned long previousMillis; // will store last time LED was updated
// Next we add a constructor. The constructor has the same name as the class
// and its job is to initialize all the variables.
// Constructor - creates a Flasher
// and initializes the member variables and state
public:
Flasher(int pin, long on, long off)
{
ledPin = pin;
OnTime = on;
OffTime = off;
ledState = LOW;
previousMillis = 0;
}
void begin()
{
// Set the pinmode in setup() to give the hardware a chance to settle on startup
pinMode(ledPin, OUTPUT);
}
// Finally we take our loop and turn it into a member function called “Update()”.
// Note that this is identical to our original void loop(). Only the name has changed.
void Update()
{
// check to see if it's time to change the state of the LED
unsigned long currentMillis = millis();
if ((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
{
ledState = LOW; // Turn it off
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED
}
else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
{
ledState = HIGH; // turn it on
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED
}
}
// Now, for every LED that we want to flash, we create an instance of the Flasher class
// by calling the constructor. And on every pass through the loop we just need to call
// Update() for each instance of Flasher.
// Examples:
//Flasher led1(12, 100, 400); // pin number, on time, off time
//Flasher led2(13, 350, 350); // pin number, on time, off time
// Then, in setup(), call the begin() method to set the pinmode.
// void setup() {
// led1.begin();
// led2.begin();
// }
}; // end of Flasher class
// Instantiate two LEDs
Flasher led1(LED_BUILTIN, 100, 600);
Flasher led2(LED_BUILTIN, 350, 350);
/* Configure the button */
const int buttonPin = 4; // D4.
int buttonState = 0; // the pushbutton status
void setup() {
// Sets the LED's pinMode
led1.begin();
led2.begin();
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is LOW:
if (buttonState == LOW) {
led1.Update();
} else if (buttonState == HIGH) {
led2.Update();
}
}
And here are the two three files for the tabbed version: base_sketch_name.ino, flasher.h, and flasher.cpp
/*
Tabs with class demo
Change flash rate by pressing a button
This is the base sketch
*/
#include "flasher.h"
// Instantiate two LEDs
Flasher led1(LED_BUILTIN, 100, 600);
Flasher led2(LED_BUILTIN, 350, 350);
/* Configure the button */
const int buttonPin = 4; // D4.
int buttonState = 0; // the pushbutton status
void setup() {
led1.begin();
led2.begin();
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is LOW:
if (buttonState == LOW) {
led1.Update();
} else if (buttonState == HIGH) {
led2.Update();
}
}
And the class broken into its own tabs/files, flasher.h and flasher.cpp:
/*
Flash Without Delay - Class
From: https://learn.adafruit.com/multi-tasking-the-arduino-part-1/a-classy-solution
This is flasher.h
*/
#ifndef FLASHER_H
#define FLASHER_H
class Flasher
{
private:
// Class Member Variables
int ledPin; // the number of the LED pin
long OnTime; // milliseconds of on-time
long OffTime; // milliseconds of off-time
// These maintain the current state
int ledState; // ledState used to set the LED
unsigned long previousMillis; // will store last time LED was updated
public:
// Constructor
Flasher(int pin, long on, long off);
// Member functions
void begin();
void Update();
};
#endif
and flasher.cpp
/*
Flash Without Delay - Class
From: https://learn.adafruit.com/multi-tasking-the-arduino-part-1/a-classy-solution
This is flasher.cpp
*/
#include "flasher.h"
#include "Arduino.h"
// Constructor
Flasher::Flasher(int pin, long on, long off)
{
ledPin = pin;
OnTime = on;
OffTime = off;
ledState = LOW;
previousMillis = 0;
}
// Member functions
void Flasher::begin()
{
// Set the pinmode in setup() to give the hardware a chance to settle on startup
pinMode(ledPin, OUTPUT);
}
void Flasher::Update()
{
// check to see if it's time to change the state of the LED
unsigned long currentMillis = millis();
if ((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
{
ledState = LOW; // Turn it off
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED
}
else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
{
ledState = HIGH; // turn it on
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED
}
}