Skip to content

Instantly share code, notes, and snippets.

@mqu
Last active August 29, 2015 14:10
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 mqu/1c3f42b5c3c0d3f636b4 to your computer and use it in GitHub Desktop.
Save mqu/1c3f42b5c3c0d3f636b4 to your computer and use it in GitHub Desktop.
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