4180 lab 1

Dependencies:   mbed MCP23S17 PinDetect USBDevice

Files at this revision

API Documentation at this revision

Comitter:
emilywilson
Date:
Wed Jan 15 18:13:43 2020 +0000
Child:
1:f121b88d9c85
Commit message:
parts 1-3

Changed in this revision

PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
RGBLed.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Wed Jan 15 18:13:43 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/AjK/code/PinDetect/#cb3afc45028b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RGBLed.h	Wed Jan 15 18:13:43 2020 +0000
@@ -0,0 +1,24 @@
+class RGBLed
+{
+public:
+    RGBLed(PinName redpin, PinName greenpin, PinName bluepin);
+    void write(float red,float green, float blue);
+private:
+    PwmOut _redpin;
+    PwmOut _greenpin;
+    PwmOut _bluepin;
+};
+ 
+RGBLed::RGBLed (PinName redpin, PinName greenpin, PinName bluepin)
+    : _redpin(redpin), _greenpin(greenpin), _bluepin(bluepin)
+{
+    //50Hz PWM clock default a bit too low, go to 2000Hz (less flicker)
+    _redpin.period(0.0005);
+}
+ 
+void RGBLed::write(float red,float green, float blue)
+{
+    _redpin = red;
+    _greenpin = green;
+    _bluepin = blue;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 15 18:13:43 2020 +0000
@@ -0,0 +1,84 @@
+#include "mbed.h"
+#include "RGBLed.h"
+#include "PinDetect.h"
+
+DigitalOut myled(p26);
+DigitalIn pb(p22);
+DigitalIn pb2(p21);
+
+// p10 is most significant bit
+//BusIn ledSelect(p8, p9, p10);
+//
+//PinName redPin = p11;
+//PinName greenPin = p12;
+//PinName bluePin = p13;
+//
+PinDetect pb1(p8);
+PinDetect pb2(p9);
+
+float volatile p;
+
+void pb1_hit_callback() {
+    if (p > 0) {
+        p -= 0.1;
+    }
+}
+
+void pb2_hit_callback() {
+    if (p < 0) {
+        p += 0.1;
+    }
+}
+
+int main() {
+    while(1) {
+        // Part 1
+        myled = !pb;
+        
+        // Part 2
+        float p = 1.0f;
+        pb1.mode(PullUp);
+        pb2.mode(PullUp);
+        wait(0.1)
+        
+        if (pb1) {
+            if (p > 0) {
+                p -= 0.1;
+            }
+        } else if (pb2) {
+            if (p < 1) {
+                p += 0.1;
+            }
+        }
+        myled = p;
+        
+        // Part 3
+//        RGBLed myRBGLed = RGBLed(redPin, greenPin, bluePin);
+//        float redVal = 0.0f;
+//        float greenVal = 0.0f;
+//        float blueVal = 0.0f;
+//        
+//        pb1.mode(PullUp)
+//        pb2.mode(PullUp)
+//        wait(0.1)
+//        
+//        // Possibly try attach_asserted
+//        pb1.attach_deasserted(&pb1_hit_callback);
+//        pb2.attach_deasserted(&pb2_hit_callback);
+//        pb1.setSampleFrequency();
+//        pb2.setSampleFrequency();
+//        
+//        if (ledSelect & 0x1) {
+//            redVal = 1.0 * p;
+//        }
+//        if (ledSelect & 0x2) {
+//            greenVal = 1.0 * p;
+//        }
+//        if (ledselect & 0x4) {
+//            blueVal = 1.0 * p;
+//        }
+//    }
+
+    // Part 4
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jan 15 18:13:43 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file