Last active
August 29, 2015 14:10
-
-
Save mqu/1c3f42b5c3c0d3f636b4 to your computer and use it in GitHub Desktop.
Arduino NANO blinking LED - object oriented version
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
/* | |
Blink.ino - Marc Quinton | |
object oriented version of the classical blinking LED | |
*/ | |
class Led { | |
private: | |
int _pin; | |
int _status = LOW; | |
public: | |
Led(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); | |
} | |
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); | |
} |
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
/* | |
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