Skip to content

DngQucVng/OutputDigital

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Documentation

A Library for Micro-controllers using Arduino IDE

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

Installation

Here are the steps to install the library:

  1. Download ZIP of the project
  2. Open Arduino IDE
  3. Navigate to Sketch -> Include Library -> Add .ZIP Library...
  4. Browse for the downloaded .ZIP file

Examples

Simple Blink

#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);
}

Advance Blink

#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");
	}
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Languages