Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed DebounceIn PinDetect
Revision 0:a331bf280a04, committed 2019-02-23
- Comitter:
- kanicolaus
- Date:
- Sat Feb 23 20:35:51 2019 +0000
- Commit message:
- 1;
Changed in this revision
diff -r 000000000000 -r a331bf280a04 DebounceIn.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DebounceIn.lib Sat Feb 23 20:35:51 2019 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/AjK/code/DebounceIn/#31ae5cfb44a4
diff -r 000000000000 -r a331bf280a04 PinDetect.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PinDetect.lib Sat Feb 23 20:35:51 2019 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
diff -r 000000000000 -r a331bf280a04 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat Feb 23 20:35:51 2019 +0000
@@ -0,0 +1,117 @@
+#include "mbed.h"
+#include "PinDetect.h"
+
+// THIS PROGRAM IS FOR DEMONSTRATING PROBLEMS 1 - 3 OF LAB #1
+// NOW INCLUDES PARTS 8
+
+// Input declarations
+// Input/output type yourvariable(physical pin)
+DigitalIn pb_1(p5);
+DigitalIn dip1(p8);
+DigitalIn dip2(p9);
+DigitalIn dip3(p10);
+PinDetect pb_2_up(p6);
+PinDetect pb_2_down(p7);
+PinDetect pb_3_up(p11);
+PinDetect pb_3_down(p12);
+AnalogIn pot8(p20);
+
+
+// Output declarations
+DigitalOut redLED(p30);
+DigitalOut mbedLED2(LED2);
+DigitalOut mbedLED3(LED3);
+DigitalOut mbedLED4(LED4);
+PwmOut pwmLED(LED1);
+PwmOut redPwm(p23);
+PwmOut greenPwm(p22);
+PwmOut bluePwm(p21);
+PwmOut greenLED(p24);
+//AnalogOut aout(p18);
+
+// Global variables for pwm changes
+// duty_cycle_2 ranges from 0.0f - 1.0f
+float volatile duty_cycle_2 = 0.5f;
+float volatile duty_cycle_3 = 0.5f;
+
+// Callback routine is interrupt activated by a debounced pb_2_up hit
+void pb2up_hit_callback (void) {
+ if(duty_cycle_2 < 1.0f) {
+ duty_cycle_2 += 0.1f;
+ } else if(duty_cycle_2 > 1.0f) {
+ duty_cycle_2 = 1.0f;
+ }
+}
+// Callback routine is interrupt activated by a debounced pb_2_down hit
+void pb2down_hit_callback (void) {
+ if(duty_cycle_2 > 0.0f) {
+ duty_cycle_2 -= 0.1f;
+ } else if(duty_cycle_2 < 0.0f) {
+ duty_cycle_2 = 0.0f;
+ }
+}
+// Callback routine is interrupt activated by a debounced pb_2_up hit
+void pb3up_hit_callback (void) {
+ if(duty_cycle_3 < 1.0f) {
+ duty_cycle_3 += 0.1f;
+ } else if(duty_cycle_3 > 1.0f) {
+ duty_cycle_3 = 1.0f;
+ }
+}
+// Callback routine is interrupt activated by a debounced pb_2_down hit
+void pb3down_hit_callback (void) {
+ if(duty_cycle_3 > 0.0f) {
+ duty_cycle_3 -= 0.1f;
+ } else if(duty_cycle_3 < 0.0f) {
+ duty_cycle_3 = 0.0f;
+ }
+}
+
+int main() {
+ //duty_cycle_2 = 0.5f;
+
+ // Variable Declarations
+ pb_2_up.mode(PullUp);
+ pb_2_down.mode(PullUp);
+ pb_3_up.mode(PullUp);
+ pb_3_down.mode(PullUp);
+ dip1.mode(PullUp);
+ dip2.mode(PullUp);
+ dip3.mode(PullUp);
+
+ wait(0.1);
+ // Setup Interrupt callback functions for pb up and down
+ pb_2_up.attach_deasserted(&pb2up_hit_callback);
+ pb_2_down.attach_deasserted(&pb2down_hit_callback);
+ pb_3_up.attach_deasserted(&pb3up_hit_callback);
+ pb_3_down.attach_deasserted(&pb3down_hit_callback);
+ //Start sampling pb up and down inputs using interrupts
+ pb_2_up.setSampleFrequency();
+ pb_2_down.setSampleFrequency();
+ pb_3_up.setSampleFrequency();
+ pb_3_down.setSampleFrequency();
+ // pwmLED variable declarations
+
+ while(1) {
+ redLED = !pb_1;
+ pwmLED = duty_cycle_2;
+
+ if (!dip1) {
+ redPwm = duty_cycle_3;
+ } else {
+ redPwm = 0.0f;
+ }
+
+ if (!dip2) {
+ greenPwm = duty_cycle_3;
+ } else {
+ greenPwm = 0.0f;
+ }
+ if (!dip3) {
+ bluePwm = duty_cycle_3;
+ } else {
+ bluePwm = 0.0f;
+ }
+ greenLED = pot8;
+ }
+}
\ No newline at end of file
diff -r 000000000000 -r a331bf280a04 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Feb 23 20:35:51 2019 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/a330f0fddbec \ No newline at end of file