Hi all,
My google-fu is failing me today. I'm trying to execute a function that is declared outside of a class from within a class. Here is a simple example of my code:
#include <LiquidCrystal.h>
class Flasher
{
// 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
// Constructor - creates a Flasher
// and initializes the member variables and state
public:
Flasher(int pin, long on, long off)
{
ledPin = pin;
pinMode(ledPin, OUTPUT);
OnTime = on;
OffTime = off;
ledState = LOW;
previousMillis = 0;
}
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
lcd_out(ledState); // errors right here
}
}
};
// LCD display setup
// BS E D4 D5 D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // digital pins
Flasher led1(12, 100, 400);
Flasher led2(13, 350, 350);
void setup()
{
lcd.begin(16, 2);
lcd.clear();
}
void loop()
{
led1.Update();
led2.Update();
}
void lcd_out(int state)
{
lcd.setCursor(0,0);
lcd.print(state);
}
So I've got a 16x2 lcd character display and a function that outputs data to the display. How do I access that lcd_out function from within the class?
Line 47 causes an error - 'lcd_out' was not declared in this scope
How do I gain access to the lcd_out function from within the class Flasher?
Thanks for any help,
Randy