Lab 1 Part 2

Dependencies:   mbed PinDetect

Files at this revision

API Documentation at this revision

Comitter:
glanier9
Date:
Mon Feb 01 20:01:58 2021 +0000
Commit message:
Final code

Changed in this revision

PinDetect.lib 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	Mon Feb 01 20:01:58 2021 +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/main.cpp	Mon Feb 01 20:01:58 2021 +0000
@@ -0,0 +1,48 @@
+ //  4180 Lab 1, Part 2
+//  Gregory Lanier
+
+#include "mbed.h"
+#include "PinDetect.h"
+
+/*
+    This program lights up a built in LED and enables dimming with two push buttons.
+*/
+
+// Global Vars
+float brightness = 0.5f;   // Initial brightness 1/2 power
+
+// I/O
+PinDetect   dimButton(p8);      // Make LED dimmer with p8 button
+PinDetect   brightButton(p9);   // Make LED brighter with p9 button
+PwmOut  mbedLED(LED1);          // LED1 built into Mbed
+
+// Dim Callback
+void dim_callback(void) {
+    brightness -= 0.1f;
+}
+
+// Brighten Callback
+void bright_callback(void) {
+    brightness += 0.1f;
+}
+
+int main()
+{
+    // Button Mode Set
+    dimButton.mode(PullUp);    
+    brightButton.mode(PullUp);
+    wait(0.01);
+    
+    // Setuo button callbacks
+    dimButton.attach_deasserted(&dim_callback);    
+    brightButton.attach_deasserted(&bright_callback);
+    
+    // Start sampling button inputs using interrupts
+    dimButton.setSampleFrequency();
+    brightButton.setSampleFrequency();
+    
+    // Logic Loop
+    while(1) {
+        mbedLED = brightness;   // Update brightness
+        }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Feb 01 20:01:58 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file