Skip to content

Instantly share code, notes, and snippets.

@RickKimball RickKimball/ActiveLowLED.h
Last active Aug 29, 2015

Embed
What would you like to do?
simple blink
/*
* ActiveLowLED - class for leds that light up when they are grounded
*/
#include <Arduino.h>
#pragma once
class ActiveLowLED {
private:
const int _pin;
int _initialized;
public:
ActiveLowLED(const int pin) : _pin(pin), _initialized(0) {
begin();
}
void begin() {
if ( !_initialized ) {
pinMode(_pin, OUTPUT); // make it an output
off();
_initialized=1;
}
}
void on() {
digitalWrite(_pin,LOW);
}
void off() {
digitalWrite(_pin,HIGH);
}
void toggle() {
digitalWrite(_pin,!digitalRead(_pin));
}
void blink(int msecOn=100, int msecOff=400) {
on();
delay(msecOn);
off();
delay(msecOff);
}
};
#include "ActiveLowLED.h"
ActiveLowLED led(PC13); // contructor that uses a pinMode call
void setup() {
}
void loop() {
unsigned x;
x = 3;
do {
led.blink(500,1000);
} while(--x);
delay(1000);
x = 30;
do {
led.toggle();
delay(50);
} while(--x);
led.off();
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.