FSLP_Controls_RGB_LEDs

Committer:
sethnuon
Date:
Tue Oct 20 00:13:03 2015 +0000
Revision:
0:d56a10dcfd53
FSLP Controls RGBs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sethnuon 0:d56a10dcfd53 1 #include "mbed.h"
sethnuon 0:d56a10dcfd53 2 Serial pc(USBTX, USBRX);
sethnuon 0:d56a10dcfd53 3
sethnuon 0:d56a10dcfd53 4 DigitalInOut pinReference(p13);
sethnuon 0:d56a10dcfd53 5 DigitalOut driveLine2(p14);
sethnuon 0:d56a10dcfd53 6 AnalogIn senseLine3(p15);
sethnuon 0:d56a10dcfd53 7
sethnuon 0:d56a10dcfd53 8 DigitalOut red1(p21);
sethnuon 0:d56a10dcfd53 9 DigitalOut red2(p22);
sethnuon 0:d56a10dcfd53 10 DigitalOut red3(p23);
sethnuon 0:d56a10dcfd53 11 DigitalOut red4(p24);
sethnuon 0:d56a10dcfd53 12
sethnuon 0:d56a10dcfd53 13 DigitalOut blue1(p28);
sethnuon 0:d56a10dcfd53 14 DigitalOut blue2(p27);
sethnuon 0:d56a10dcfd53 15 DigitalOut blue3(p26);
sethnuon 0:d56a10dcfd53 16 DigitalOut blue4(p25);
sethnuon 0:d56a10dcfd53 17
sethnuon 0:d56a10dcfd53 18 int main() {
sethnuon 0:d56a10dcfd53 19 while(1) {
sethnuon 0:d56a10dcfd53 20
sethnuon 0:d56a10dcfd53 21 pinReference.output();
sethnuon 0:d56a10dcfd53 22 pinReference = 0;
sethnuon 0:d56a10dcfd53 23 driveLine2 = 1;
sethnuon 0:d56a10dcfd53 24 float force = 0;
sethnuon 0:d56a10dcfd53 25 force = senseLine3.read();
sethnuon 0:d56a10dcfd53 26 wait(0.001);
sethnuon 0:d56a10dcfd53 27 pinReference.input();
sethnuon 0:d56a10dcfd53 28 driveLine2 = 0;
sethnuon 0:d56a10dcfd53 29 float position = 0;
sethnuon 0:d56a10dcfd53 30 position = senseLine3.read();
sethnuon 0:d56a10dcfd53 31 pc.printf("Force: %f", force);
sethnuon 0:d56a10dcfd53 32 pc.printf(" Position: %f\r\n", position);
sethnuon 0:d56a10dcfd53 33 wait(0.001);
sethnuon 0:d56a10dcfd53 34
sethnuon 0:d56a10dcfd53 35 if( position ==0 ) {
sethnuon 0:d56a10dcfd53 36 red1 = red2 = red3 = red4 = 0;
sethnuon 0:d56a10dcfd53 37 wait(0.001);
sethnuon 0:d56a10dcfd53 38 }else if( position < 0.35 ) {
sethnuon 0:d56a10dcfd53 39 red1 = 1;
sethnuon 0:d56a10dcfd53 40 red2 = red3 = red4 = 0;
sethnuon 0:d56a10dcfd53 41 wait(0.001);
sethnuon 0:d56a10dcfd53 42 } else if (position >= 0.35 && position < 0.62 ) {
sethnuon 0:d56a10dcfd53 43 red1 = red2 = 1;
sethnuon 0:d56a10dcfd53 44 red3 = red4 = 0;
sethnuon 0:d56a10dcfd53 45 wait(0.001);
sethnuon 0:d56a10dcfd53 46 } else if (position >= 0.62 && position < 0.9 ) {
sethnuon 0:d56a10dcfd53 47 red1 = red2 = red3 = 1;
sethnuon 0:d56a10dcfd53 48 red4 = 0;
sethnuon 0:d56a10dcfd53 49 wait(0.001);
sethnuon 0:d56a10dcfd53 50 } else if ( position >= 0.9) {
sethnuon 0:d56a10dcfd53 51 red1 = red2 = red3 = red4 = 1;
sethnuon 0:d56a10dcfd53 52 wait(0.001);
sethnuon 0:d56a10dcfd53 53
sethnuon 0:d56a10dcfd53 54 }
sethnuon 0:d56a10dcfd53 55 if ( position ==0 ) {
sethnuon 0:d56a10dcfd53 56 red1 = red2 = red3 = red4 = blue1 = blue2 = blue3 = blue4 = 0;
sethnuon 0:d56a10dcfd53 57 wait(0.001);
sethnuon 0:d56a10dcfd53 58 }else if( position < 0.35 && force >=0.8) {
sethnuon 0:d56a10dcfd53 59 red1 = red2 = red3 = red4 = 0;
sethnuon 0:d56a10dcfd53 60 blue2 = blue3 = blue4 = 0;
sethnuon 0:d56a10dcfd53 61 blue1 = 1;
sethnuon 0:d56a10dcfd53 62 wait(0.001);
sethnuon 0:d56a10dcfd53 63 } else if (position >= 0.35 && position < 0.62 && force >=0.8 ) {
sethnuon 0:d56a10dcfd53 64 red1 = red2 = red3 = red4 = 0;
sethnuon 0:d56a10dcfd53 65 blue3 = blue4 = 0;
sethnuon 0:d56a10dcfd53 66 blue1 = blue2 = 1;
sethnuon 0:d56a10dcfd53 67 wait(0.001);
sethnuon 0:d56a10dcfd53 68 } else if (position >= 0.62 && position < 0.9 && force >=0.8) {
sethnuon 0:d56a10dcfd53 69 red1 = red2 = red3 = red4 = 0;
sethnuon 0:d56a10dcfd53 70 blue4 = 0;
sethnuon 0:d56a10dcfd53 71 blue1 = blue2 = blue3 = 1;
sethnuon 0:d56a10dcfd53 72 wait(0.001);
sethnuon 0:d56a10dcfd53 73 } else if ( position >= 0.9 && force >=0.8) {
sethnuon 0:d56a10dcfd53 74 red1 = red2 = red3 = red4 = 0;
sethnuon 0:d56a10dcfd53 75 blue1 = blue2 = blue3 = blue4 = 1;
sethnuon 0:d56a10dcfd53 76 wait(0.001);
sethnuon 0:d56a10dcfd53 77 }
sethnuon 0:d56a10dcfd53 78 wait(0.3);
sethnuon 0:d56a10dcfd53 79
sethnuon 0:d56a10dcfd53 80 }
sethnuon 0:d56a10dcfd53 81 }