Lab3

Dependencies:   mbed-rtos mbed

Fork of ESE519_Lab3_EC_v4 by ese519

Files at this revision

API Documentation at this revision

Comitter:
jfields
Date:
Fri Oct 16 22:18:40 2015 +0000
Parent:
9:d7a9c2345e9e
Commit message:
a

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Oct 16 20:13:24 2015 +0000
+++ b/main.cpp	Fri Oct 16 22:18:40 2015 +0000
@@ -135,6 +135,7 @@
             q_mutex.lock();
             update_q();
             q_mutex.unlock();
+            led_q();
             wait(1);
             //keyPressed = 0;
         }
@@ -236,30 +237,45 @@
     while (1) {
         float ADC_val = Button.read(); 
         int val = ADC_val*10;
+        
+            int has1 = 0;
+            int has2 = 0;
+            int has3 = 0;
+            int has4 = 0;
+            int has5 = 0;
+            for (int i=0;i<4;i++) {
+                if (el_q[i] == 1) has1 = 1;
+                if (el_q[i] == 2) has2 = 1;
+                if (el_q[i] == 3) has3 = 1;
+                if (el_q[i] == 4) has4 = 1;
+                if (el_q[i] == 5) has5 = 1;
+            }
+        
+                
         q_mutex.lock();
-        if(val == 2) {
+        if (val == 2 && !has1) {
             el_q[el_q_size] = 1;
             el_q_size++;
             bubble_sort();
-        } else if(val == 4) {
+        } else if(val == 4 && !has2) {
             el_q[el_q_size] = 2;
             el_q_size++;
             bubble_sort();
-        } else if(val == 6) {
+        } else if(val == 6 && !has3) {
             el_q[el_q_size] = 3;
             el_q_size++;
             bubble_sort();
-        } else if(val == 8) {
+        } else if(val == 8 && !has4) {
             el_q[el_q_size] = 4;
             el_q_size++;
             bubble_sort();
-        } else if(val == 10) {
+        } else if(val == 10 && !has5) {
             el_q[el_q_size] = 5;
             el_q_size++;
             bubble_sort();
         }
         q_mutex.unlock();
-        wait(0.1);
+        wait(0.5);
         while (el_q_size == 4) { // wait for queue to empty
             wait(0.2);
         }
@@ -267,10 +283,10 @@
 }
 
 void update_q() {
-    for (int i=1;i<el_q_size;i++) {
-        el_q[i-1] = el_q[i];
+    el_q_size--;
+    for (int i=0;i<el_q_size;i++) {
+        el_q[i] = el_q[i+1];
     }
-    el_q_size--;    
 }
 
 void el_alg() {