This project is an attempt to implement C++ class with digitalWrite. It can do the following:
- Set the output to LOW or HIGH
- Invert the output
- Get timestamp since the last time the Pin change state
Here are the steps to install the library:
- Download ZIP of the project
- Open Arduino IDE
- Navigate to Sketch -> Include Library -> Add .ZIP Library...
- Browse for the downloaded .ZIP file
#include <OutputDigital.h>
#define LED_PIN 2
OutputDigital led(LED_PIN);
void setup() {
}
void loop() {
// This program uses Delay which is not good, see Advance Blink for better way
led.set_high(); // Set to HIGH logic (3.3V or 5V)
delay(1000);
led.set_low(); // Set to LOW logic (0V)
delay(1000);
led.invert(); // Set to opposite logic
delay(1000);
led.invert(); // Set to opposite logic
delay(1000);
}#include <OutputDigital.h>
#define LED_PIN 2
OutputDigital led(LED_PIN);
void setup() {
Serial.begin(115200);
}
void loop() {
if (millis() - led.get_timestamp_since_last_change() >= 1000) { // If the Pin has changed state for 1000 milli-seconds
led.invert();
if (led.is_high())
Serial.println("LED is on");
else if (led.is_low())
Serial.println("LED is off");
}
}