satbir panesar / Mbed 2 deprecated elec350

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
spanesar
Date:
Thu Oct 06 09:40:57 2016 +0000
Parent:
0:c2221c47a1f8
Child:
2:3528eaaf5319
Commit message:
added Led classes

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 06 09:40:57 2016 +0000
@@ -0,0 +1,17 @@
+#include "Led.h"
+
+Led::Led(PinName pinName):
+pin(pinName)
+{
+}
+void Led::switchOn(){
+    this->pin = 1;
+    }
+void Led::switchOff(){
+    this->pin = 0;
+    }
+void Led::flash(float time){
+    this->pin = 1;
+    wait(time);
+    this->pin = 0;
+    }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Led.h	Thu Oct 06 09:40:57 2016 +0000
@@ -0,0 +1,15 @@
+#ifndef _LED_H_
+#define _LED_H_
+#include "mbed.h"
+
+class Led
+{
+    public:
+    Led(PinName pinName);
+    void switchOn();
+    void switchOff();
+    void flash(float time);
+    private:
+    DigitalOut pin;
+    };
+    #endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 06 09:40:57 2016 +0000
@@ -0,0 +1,16 @@
+#include "mbed.h"
+#include "Led.h"
+
+Led greenLed(PD_12);
+Led orangeLed(PD_13);
+Led redLed(PD_14);
+Led blueLed(PD_15);
+
+int main(){
+    while(1){
+        greenLed.flash(0.1);
+        orangeLed.flash(0.1);
+        redLed.flash(0.1);
+        blueLed.flash(0.1);
+        }
+}
\ No newline at end of file