Browse files

Initial Commit

  • Loading branch information...
0 parents commit 135a0e591a220cd8f67905c45727903d5ee07af1 @chalkers committed Jul 14, 2013
Showing with 97 additions and 0 deletions.
  1. +32 −0 AnalogPin.cpp
  2. +17 −0 AnalogPin.h
  3. +24 −0 DigitalPin.cpp
  4. +16 −0 DigitalPin.h
  5. +8 −0 keywords.txt
32 AnalogPin.cpp
@@ -0,0 +1,32 @@
+#include "Arduino.h"
+#include "AnalogPin.h"
+
+AnalogPin::AnalogPin(int pin)
+{
+ pinMode(pin, OUTPUT);
+ _pin = pin;
+ _intensity = 0;
+}
+
+void AnalogPin::increase()
+{
+ _intensity = _intensity + 51;
+ setIntensity(_intensity);
+}
+
+void AnalogPin::decrease()
+{
+ _intensity = _intensity - 51;
+ setIntensity(_intensity);
+}
+
+void AnalogPin::setIntensity(int intensity)
+{
+ _intensity = intensity;
+ if(_intensity > 255) {
+ _intensity = 255;
+ } else if(intensity < 0) {
+ _intensity = 0;
+ }
+ analogWrite(_pin, _intensity);
+}
17 AnalogPin.h
@@ -0,0 +1,17 @@
+#ifndef AnalogPin_h
+#define AnalogPin_h
+
+#include "Arduino.h"
+
+class AnalogPin
+{
+ public:
+ AnalogPin(int pin);
+ void increase();
+ void decrease();
+ void setIntensity(int intensity);
+ private:
+ int _pin;
+ int _intensity;
+ };
+#endif
24 DigitalPin.cpp
@@ -0,0 +1,24 @@
+#include "Arduino.h"
+#include "DigitalPin.h"
+
+DigitalPin::DigitalPin(int pin)
+{
+ pinMode(pin, OUTPUT);
+ _pin = pin;
+ off();
+}
+
+void DigitalPin::on()
+{
+ write(HIGH);
+}
+
+void DigitalPin::off()
+{
+ write(LOW);
+}
+
+void DigitalPin::write(boolean onOff)
+{
+ digitalWrite(_pin, onOff);
+}
16 DigitalPin.h
@@ -0,0 +1,16 @@
+#ifndef DigitalPin_h
+#define DigitalPin_h
+
+#include "Arduino.h"
+
+class DigitalPin
+{
+ public:
+ DigitalPin(int pin);
+ void on();
+ void off();
+ void write(boolean onOff);
+ private:
+ int _pin;
+ };
+#endif
8 keywords.txt
@@ -0,0 +1,8 @@
+AnalogPin KEYWORD1
+increase KEYWORD2
+decrease KEYWORD2
+setIntensity KEYWORD2
+
+DigitalPin KEYWORD1
+on KEYWORD2
+off KEYWORD2

0 comments on commit 135a0e5

Please sign in to comment.