Last active
August 29, 2015 14:20
-
-
Save RickKimball/c19fd63c9d2a65e523a2 to your computer and use it in GitHub Desktop.
simple blink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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