Skip to content

Instantly share code, notes, and snippets.

@RickKimball
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickKimball/c19fd63c9d2a65e523a2 to your computer and use it in GitHub Desktop.
Save RickKimball/c19fd63c9d2a65e523a2 to your computer and use it in GitHub Desktop.
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