Skip to content

Instantly share code, notes, and snippets.

@mqu

mqu/Blink.ino

Last active Aug 29, 2015
Embed
What would you like to do?
Arduino NANO blinking LED - object oriented version
/*
Blink.ino - Marc Quinton
object oriented version of the classical blinking LED
*/
class Pin {
protected:
int _pin;
int _status = LOW;
public:
Pin(int pin) {
_pin = pin;
}
void low(){
_status=LOW;
digitalWrite(_pin, LOW); // turn the LED off by making the voltage LOW
}
void high(){
_status=HIGH;
digitalWrite(_pin, HIGH); // turn the LED off by making the voltage LOW
}
void setup(void) {
pinMode(_pin, OUTPUT);
}
};
// Led is connected to a Pin.
class Led : public Pin {
public:
Led(int pin) : Pin(pin){
_pin = pin;
}
void blink(int _delay=1000){
this->high();
delay(_delay);
this->low();
delay(_delay);
}
};
// Pin 13 has an LED connected on most Arduino boards ; give it a name:
Led led(13);
// the setup routine runs once when you press reset:
void setup() {
led.setup();
}
// the loop routine runs over and over again forever:
void loop() {
led.blink(100);
led.blink(100);
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.