lab1

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
mbarros7
Date:
Tue Feb 02 20:18:27 2021 +0000
Commit message:
kk

Changed in this revision

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
diff -r 000000000000 -r 5af73d509412 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 02 20:18:27 2021 +0000
@@ -0,0 +1,71 @@
+#include "mbed.h"
+
+// Define buttons
+InterruptIn button_red(p16);
+InterruptIn button_green(p17);
+InterruptIn button_blue(p18);
+
+// Define LED colors
+PwmOut led_red(p21);
+PwmOut led_green(p22);
+PwmOut led_blue(p23);
+
+// Interrupt Service Routine to increment the red color
+void inc_red() {
+
+    float pwm;
+
+    // Read in current PWM value and increment it
+    pwm = led_red.read();
+    pwm += 0.1f;
+    if (pwm > 1.0f) {
+        pwm = 0.0f;
+    }
+    led_red.write(pwm);
+}
+
+// Interrupt Service Routine to increment the green color
+void inc_green() {
+
+    float pwm;
+
+    // Read in current PWM value and increment it
+    pwm = led_green.read();
+    pwm += 0.1f;
+    if (pwm > 1.0f) {
+        pwm = 0.0f;
+    }
+    led_green.write(pwm);
+}
+
+// Interrupt Service Routine to increment the blue color
+void inc_blue() {
+
+    float pwm;
+
+    // Read in current PWM value and increment it
+    pwm = led_blue.read();
+    pwm += 0.1f;
+    if (pwm > 1.0f) {
+        pwm = 0.0f;
+    }
+    led_blue.write(pwm);
+}
+
+// Main loop
+int main() {
+
+    // Initialize all LED colors as off
+    led_red.write(0.0f);
+    led_green.write(0.0f);
+    led_blue.write(0.0f);
+
+    // Define three interrupts - one for each color
+    button_red.fall(&inc_red);
+    button_green.fall(&inc_green);
+    button_blue.fall(&inc_blue);
+
+    // Do nothing! We wait for an interrupt to happen
+    while(1) {
+    }
+}
diff -r 000000000000 -r 5af73d509412 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Feb 02 20:18:27 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file