Program for testing the mRoteryEncoder as well as Switch ISR

Dependencies:   mRotaryEncoder mbed

Files at this revision

API Documentation at this revision

Comitter:
ostlerkd13
Date:
Sun Mar 06 06:58:22 2016 +0000
Commit message:
Test program with function for Min and Max value returned from encoder.; ISR for switch-press that that toggles resolution from 1X to 10X.

Changed in this revision

mRotaryEncoder.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/mRotaryEncoder.lib	Sun Mar 06 06:58:22 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/charly/code/mRotaryEncoder/#2502b829d452
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Mar 06 06:58:22 2016 +0000
@@ -0,0 +1,57 @@
+/**************************************************************************************/
+/**************************************************************************************/
+/*SMART Remote Controller
+ 
+ Kevin D. Ostler copyright 2016 */
+/**************************************************************************************/
+/**************************************************************************************/
+#include "mbed.h"
+#include "mRotaryEncoder.h"
+#define MAX 100
+#define MIN 0
+
+mRotaryEncoder adjust_enc(p9, p10, p11);//pinA,pinB,pinSW
+
+float resolution = 1.0;
+float adjust_set = 0.0;
+float adjust_last = 0.0;
+bool button = 1;
+
+float AdjustVal(float adjust_val){
+    adjust_val += (adjust_enc.Get() * resolution);    
+    if( adjust_val >= MAX){ 
+        adjust_val = MAX;
+        }else if(adjust_val <= MIN){ 
+            adjust_val = MIN;         
+        }
+        adjust_enc.Set(0);
+    return adjust_val;
+}
+void Set_Resolution(void){
+    button = !button;
+    if( resolution == 1.0 ){
+        resolution = 0.1;
+        }else{
+            resolution = 1.0;
+            }
+}           
+
+DigitalOut myled(LED1);
+Serial pc(USBTX, USBRX); // tx, rx
+
+int main() {
+    pc.baud(921600);
+    pc.format(8,Serial::None,1);
+    wait(0.1);
+    adjust_enc.attachSW( &Set_Resolution);
+    while(1) {
+        myled = 1;
+        adjust_set = AdjustVal(adjust_set);
+        //adjust_last = adjust_set;
+        pc.printf("Adjust Level =  %f Resolution = %f Button = %d\n\r" ,adjust_set/100, resolution, button);
+        wait(0.2);
+        myled = 0;
+        pc.printf("Adjust Level =  %f Resolution = %f Button = %d\n\r" ,adjust_set/100, resolution, button);
+        wait(0.2);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Mar 06 06:58:22 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb
\ No newline at end of file