yajuan yue / Mbed 2 deprecated ele350

Dependencies:   mbed

Fork of ele350 by JIAWEI ZHANG

Files at this revision

API Documentation at this revision

Comitter:
GGHHHH
Date:
Thu Oct 15 10:38:34 2015 +0000
Child:
1:2a1a443f619e
Commit message:
Created library

Changed in this revision

Led.cpp Show annotated file Show diff for this revision Revisions of this file
Led.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Led.cpp	Thu Oct 15 10:38:34 2015 +0000
@@ -0,0 +1,20 @@
+#include "Led.h"        //includes the header with the class definition 
+
+//constructor
+Led::Led(string s)      //contructor implementation
+{
+    if(s== "red")
+         pin= PD_14;    //The pin for the red led
+         
+    l = new DigitalOut(pin);
+}
+
+void Led::On()          //function implementation
+{
+     l->write(1);       //set the value of the pin to l
+}
+
+void Led::Off()
+{
+     l->write(0);       //set the value of the pin to 0
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Led.h	Thu Oct 15 10:38:34 2015 +0000
@@ -0,0 +1,18 @@
+#ifndef LED_H      //
+#define LED_H
+
+#include "mbed.h"
+#include <string>
+
+class Led {
+    private:
+    PinName pin;          //private member object from embed.h
+    DigitalOut *l;        //private member object from embed.h
+    
+    public:
+        Led(string s);       //constructor or the class 
+        void On();           //public member function
+        void Off();          //public member function
+};
+
+#endif /* LED_H */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 15 10:38:34 2015 +0000
@@ -0,0 +1,20 @@
+#include "Led.h"        //includes the header with the class definition 
+
+//constructor
+Led::Led(string s)      //contructor implementation
+{
+    if(s== "yellow")
+         pin= PD_14;    //The pin for the yellow led
+         
+    l = new DigitalOut(pin);
+}
+
+void Led::On()          //function implementation
+{
+     l->write(1);       //set the value of the pin to l
+}
+
+void Led::Off()
+{
+     l->write(0);       //set the value of the pin to 0
+}
\ No newline at end of file