FSLP_Controls_RGB_LEDs

Files at this revision

API Documentation at this revision

Comitter:
sethnuon
Date:
Tue Oct 20 00:13:03 2015 +0000
Commit message:
FSLP Controls RGBs

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r d56a10dcfd53 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 20 00:13:03 2015 +0000
@@ -0,0 +1,81 @@
+#include "mbed.h"
+Serial pc(USBTX, USBRX);
+
+DigitalInOut pinReference(p13);
+DigitalOut driveLine2(p14);
+AnalogIn senseLine3(p15);
+
+DigitalOut red1(p21);
+DigitalOut red2(p22);
+DigitalOut red3(p23);
+DigitalOut red4(p24);
+
+DigitalOut blue1(p28);
+DigitalOut blue2(p27);
+DigitalOut blue3(p26);
+DigitalOut blue4(p25);
+
+int main() {
+    while(1) {
+
+       pinReference.output();
+       pinReference = 0;
+       driveLine2 = 1;
+       float force = 0;
+       force = senseLine3.read();
+       wait(0.001);
+       pinReference.input();
+       driveLine2 = 0;
+       float position = 0;
+       position = senseLine3.read();
+       pc.printf("Force: %f", force);
+       pc.printf("     Position: %f\r\n", position);
+       wait(0.001);
+       
+       if( position ==0 ) {
+           red1 = red2 = red3 = red4 = 0;
+            wait(0.001);
+           }else if( position < 0.35 ) {
+           red1 = 1;        
+           red2 = red3 = red4 = 0;
+            wait(0.001);
+           } else if (position >= 0.35 && position < 0.62 ) {
+               red1 = red2 = 1;
+               red3 = red4 = 0;
+                wait(0.001);
+               } else if (position >= 0.62 && position < 0.9 ) {
+                   red1 = red2 = red3 = 1;
+                   red4 = 0;
+                    wait(0.001);
+                   } else if ( position >= 0.9) {
+                       red1 = red2 = red3 = red4 = 1;
+                        wait(0.001);
+                        
+                       }
+        if ( position ==0 ) {
+           red1 = red2 = red3 = red4 = blue1 = blue2 = blue3 = blue4 = 0;
+            wait(0.001);
+           }else if( position < 0.35 && force >=0.8) {
+           red1 = red2 = red3 = red4 = 0;
+           blue2 = blue3 = blue4 = 0;
+           blue1 = 1;
+            wait(0.001);
+           } else if (position >= 0.35 && position < 0.62 && force >=0.8 ) {
+                red1 = red2 = red3 = red4 = 0;
+                blue3 = blue4 = 0;
+                blue1 = blue2 = 1;
+                wait(0.001);
+               } else if (position >= 0.62 && position < 0.9 && force >=0.8) {
+                   red1 = red2 = red3 = red4 = 0;
+                   blue4 = 0;
+                   blue1 = blue2 = blue3 = 1;                 
+                    wait(0.001);
+                   } else if ( position >= 0.9 && force >=0.8) {
+                       red1 = red2 = red3 = red4 = 0;
+                       blue1 = blue2 = blue3 = blue4 = 1;   
+                        wait(0.001);
+                       }
+        wait(0.3);
+        
+    }
+}