ECE 4180 Lab 04 - Jung Hun Kim

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
shyguykjh
Date:
Tue Oct 21 17:19:40 2014 +0000
Commit message:
ECE 4180 Lab04 Jung Hun Kim(10-21-2014);

Changed in this revision

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
diff -r 000000000000 -r f8d011978c8d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 21 17:19:40 2014 +0000
@@ -0,0 +1,447 @@
+#include "mbed.h"
+#include "uLCD_4DGL.h"
+#include <iostream>
+#include <math.h>
+#include <cmath>
+#include <string>
+#include <cstring>
+#include <list>
+#include <vector>
+#include <mpr121.h>
+Serial pc(USBTX, USBRX);
+using namespace std;
+//
+uLCD_4DGL uLCD(p13, p14, p11);
+InterruptIn interrupt(p26);
+InterruptIn interrupt2(p25);
+I2C i2c(p9, p10);
+I2C i2c2(p28, p27);
+//
+Mpr121 numpad(&i2c, Mpr121::ADD_VSS);
+Mpr121 operpad(&i2c2, Mpr121::ADD_VSS);
+
+int fallInterrupt() 
+{
+     int num = numpad.read(0x00);
+     num +=numpad.read(0x01)<<8;
+     int i=0;
+     i = 0;
+     for (i=0; i<12; i++) {
+        if (num & (1<<i))
+        break;
+     }
+     if(i == 0) {
+        uLCD.text_width(2); //4X size text
+        uLCD.text_height(2);
+        uLCD.color(BLUE);
+        uLCD.printf("%d", i);
+     }
+     else if (i == 1) {
+        uLCD.text_width(2); //4X size text
+        uLCD.text_height(2);
+        uLCD.color(BLUE);
+        uLCD.printf("%d", i);
+     }
+     else if (i == 2) {
+        uLCD.text_width(2); //4X size text
+        uLCD.text_height(2);
+        uLCD.color(BLUE);
+        uLCD.printf("%d", i);
+         }
+     else if (i == 3) {
+        uLCD.text_width(2); //4X size text
+        uLCD.text_height(2);
+        uLCD.color(BLUE);
+        uLCD.printf("%d", i);
+         }
+     else if (i == 4) {
+        uLCD.text_width(2); //4X size text
+        uLCD.text_height(2);
+        uLCD.color(BLUE);
+        uLCD.printf("%d", i);
+         }
+     else if (i == 5) {
+        uLCD.text_width(2); //4X size text
+        uLCD.text_height(2);
+        uLCD.color(BLUE);
+        uLCD.printf("%d", i);
+         }
+     else if (i == 6) {
+        uLCD.text_width(2); //4X size text
+        uLCD.text_height(2);
+        uLCD.color(BLUE);
+        uLCD.printf("%d", i);
+         }
+     else if (i == 7) {
+        uLCD.text_width(2); //4X size text
+        uLCD.text_height(2);
+        uLCD.color(BLUE);
+        uLCD.printf("%d", i);
+         }
+     else if (i == 8) {
+        uLCD.text_width(2); //4X size text
+        uLCD.text_height(2);
+        uLCD.color(BLUE);
+        uLCD.printf("%d", i);
+         }
+     else if (i == 9) {
+        uLCD.text_width(2); //4X size text
+        uLCD.text_height(2);
+        uLCD.color(BLUE);
+        uLCD.printf("%d", i);
+         }
+     else if (i == 10) {
+        uLCD.text_width(2); //4X size text
+        uLCD.text_height(2);
+        uLCD.color(BLUE);
+        uLCD.printf(".");
+         }
+     else if (i == 11) {
+        uLCD.text_width(2); //4X size text
+        uLCD.text_height(2);
+        uLCD.color(BLUE);
+        uLCD.printf("-");
+         }
+//        pc.printf("%d", i);
+    return i;
+}
+
+int fallInterrupt2() 
+{
+     int num = operpad.read(0x00);
+     num +=operpad.read(0x01)<<8;
+     int i =0;
+     i = 0;
+     for (i=0; i<12; i++) {
+        if (num & (1<<i))
+        break;
+     }
+     if(i == 1) {
+        uLCD.printf("+");
+     }
+     else if (i == 2) {
+        uLCD.printf("-");
+     }
+     else if (i == 3) {
+         uLCD.printf("*");
+         }
+     else if (i == 4) {
+         uLCD.printf("/");
+    }
+//    else if (i == 4) {
+//         uLCD.printf("/");
+//         }
+     else if (i == 5) {
+         uLCD.color(RED);
+         uLCD.printf("\n=");
+     }
+     else if (i == 6) {
+         uLCD.cls();
+    }
+    return i;
+}
+
+int main() {
+    while (1) {
+//  C;
+//  interrupt2.fall(&fallInterrupt2);
+//  interrupt.fall(&fallInterrupt);
+//  interrupt.mode(PullUp);
+//  interrupt2.mode(PullUp);
+  float temp = 0;
+  float temp1 = 0;
+  int temp2 = 0;
+  float temp3 = 0;
+  int temp4 = 0;
+  float temp5 = 0;
+  int temp6 = 0;
+  int count = 1;
+  int count2 = 1;
+  int count3 = 1;
+  int fans = 10;
+  int fans2 = 10;
+  int fans3 = 10;
+  int negate = 0;
+  while (1) {
+         int oper1 = operpad.read(0x00);
+         oper1 +=operpad.read(0x01)<<8;
+         int num1 = numpad.read(0x00);
+         num1 +=numpad.read(0x01)<<8;
+//         temp2 = fallInterrupt2();
+//         wait(0.1);
+         if (oper1){
+//             wait(0.3);
+            int ope = fallInterrupt2();
+            wait(0.2);
+            if (ope == 0) {
+                uLCD.cls();
+                uLCD.printf("Cleared");
+                wait(0.5);
+                uLCD.cls();
+                count = 1;
+                temp1 = 0;
+                temp2 = 0;
+                fans = 10;
+            }
+            else{
+                temp2 = ope;
+                break;
+             }
+         }
+         else if (num1){
+                int ans = fallInterrupt();
+                wait(0.2);
+                if (ans == 10) {
+                    count = count +1;
+//                    pc.printf("hi I am in ans==10");
+//                    pc.printf("hi count from ans ==10 is %d\n", count);
+                    }
+                else if (ans == 11) {
+                    negate = 1;
+                    }
+                else {
+                    if (count == 2) {
+                        if (negate == 1){
+//                        pc.printf("ans = %d\n", ans);
+//                        pc.printf("count = %d\n", count);
+//                        pc.printf("temp1 before = %0.2f\n", temp1);
+                            temp1 = temp1 *10;
+                            temp1 = (temp1 - ans)/10;
+                            temp1 = temp1;
+//                        pc.printf("temp1 after = %0.2f\n", temp1);
+                             count = count +1;
+                            fans = fans * 10;
+                        }
+                        else{
+                            temp1 = temp1 *10;
+                            temp1 = (temp1 + ans)/10;
+//                        pc.printf("temp1 after = %0.2f\n", temp1);
+                            count = count +1;
+                            fans = fans * 10;
+                        }
+                    }
+//                        wait(0.3);
+                    else if (count > 2) {
+                        if (negate == 1){
+                            temp1 = temp1 * fans;
+                            temp1 = temp1 - ans;
+//                        pc.printf("ans = %d\n", ans);
+                            temp1 = temp1/fans;
+                            temp1 = temp1;
+//                        pc.printf("temp1 after = %0.2f\n", temp1);
+                            fans = fans * 10;
+                        }
+                        else{
+                            temp1 = temp1 * fans;
+                            temp1 = temp1 + ans;
+//                        pc.printf("ans = %d\n", ans);
+                            temp1 = temp1/fans;
+//                        pc.printf("temp1 after = %0.2f\n", temp1);
+                            fans = fans * 10;
+                        }    
+                    }
+                    else if(count==1){
+                        if (negate == 1){
+                            temp1 = temp1 * 10;
+                            temp1 = temp1 - ans;
+                            temp1 = temp1;
+                        pc.printf("temp1 = %d\n", temp1);
+                        pc.printf("count = %d\n", count);
+                        }
+                        else {
+                            temp1 = temp1 * 10;
+                            temp1 = temp1 + ans;
+                        }
+                   }
+//                    wait(0.3);
+                }
+        wait(0.2);
+        }
+    }
+    while (1) {
+         int oper2 = operpad.read(0x00);
+         oper2 +=operpad.read(0x01)<<8;
+         int num2 = numpad.read(0x00);
+         num2 +=numpad.read(0x01)<<8;
+//         temp4 = fallInterrupt2();
+//         wait(0.1);
+         if (oper2){
+//             wait(0.3);
+            int ope = fallInterrupt2();
+            wait(0.2);
+            if (ope == 0) {
+                uLCD.cls();
+                uLCD.printf("Cleared");
+                wait(0.5);
+                uLCD.cls();
+                count2 = 1;
+                temp3 = 0;
+                temp4 = 0;
+                fans2 = 10;
+            }
+            else{
+                temp4 = ope;
+                break;
+             }
+         }
+         else if (num2){
+                int ans = fallInterrupt();
+                wait(0.2);
+                if (ans == 10) {
+                    count2 = count2 +1;
+//                    pc.printf("hi I am in ans==10");
+//                    pc.printf("hi count from ans ==10 is %d\n", count);
+                    }
+                else {
+                    if (count2 == 2) {
+//                        pc.printf("ans = %d\n", ans);
+//                        pc.printf("count = %d\n", count2);
+//                        pc.printf("temp1 before = %0.2f\n", temp3);
+                        temp3 = temp3 *10;
+                        temp3 = (temp3+ans)/10;
+//                        pc.printf("temp1 after = %0.2f\n", temp3);
+                        count2 = count2 +1;
+                        fans2 = fans2 * 10;
+                        }
+//                        wait(0.3);
+                    else if (count2 > 2) {
+                        temp3 = temp3 * fans2;
+                        temp3 = temp3 + ans;
+//                        pc.printf("ans = %d\n", ans);
+                        temp3 = temp3/fans2;
+//                        pc.printf("temp1 after = %0.2f\n", temp1);
+                        fans2 = fans2 * 10;
+                        }
+                    else if(count2==1){
+                        temp3 = temp3 * 10;
+                        temp3 = temp3 + ans;
+//                        pc.printf("temp1 = %d\n", temp1);
+//                        pc.printf("count = %d\n", count);
+                        }
+                    }
+//                    wait(0.3);
+                }
+        wait(0.2);
+       }
+    while (1) {
+        int oper3 = operpad.read(0x00);
+         oper3 +=operpad.read(0x01)<<8;
+         int num3 = numpad.read(0x00);
+         num3 +=numpad.read(0x01)<<8;
+//         temp6 = fallInterrupt2();
+//         wait(0.1);
+         if (oper3){
+//             wait(0.3);
+            int ope = fallInterrupt2();
+            wait(0.2);
+            if (ope == 0) {
+                uLCD.cls();
+                uLCD.printf("Cleared");
+                wait(0.5);
+                uLCD.cls();
+                count3 = 1;
+                temp5 = 0;
+                temp6 = 0;
+                fans3 = 10;
+            }
+            else{
+                temp6 = ope;
+                break;
+             }
+         }
+         else if (num3){
+                int ans = fallInterrupt();
+                wait(0.2);
+                if (ans == 10) {
+                    count3 = count3 +1;
+//                    pc.printf("hi I am in ans==10");
+//                    pc.printf("hi count from ans ==10 is %d\n", count);
+                    }
+                else {
+                    if (count3 == 2) {
+//                        pc.printf("ans = %d\n", ans);
+//                        pc.printf("count = %d\n", count3);
+//                        pc.printf("temp1 before = %0.2f\n", temp5);
+                        temp5 = temp5 *10;
+                        temp5 = (temp5+ans)/10;
+//                        pc.printf("temp1 after = %0.2f\n", temp5);
+                        count3 = count3 +1;
+                        }
+//                        wait(0.3);
+                    else if (count3 > 2) {
+                        temp5 = temp5 * fans3;
+                        temp5 = temp5 + ans;
+//                        pc.printf("ans = %d\n", ans);
+                        temp5 = temp5/fans3;
+//                        pc.printf("temp1 after = %0.2f\n", temp1);
+                        fans3 = fans3 * 10;
+                        }
+                    else if(count3==1){
+                        temp5 = temp5 * 10;
+                        temp5 = temp5 + ans;
+//                        pc.printf("temp1 = %d\n", temp1);
+//                        pc.printf("count = %d\n", count);
+                        }
+                    }
+//                    wait(0.3);
+                }
+        wait(0.2);
+       }
+       if ((temp2 == 1) && (temp4 == 1)){
+                temp = temp1 + temp3 + temp5;
+                pc.printf("temp is %0.2f\n", temp);
+           }
+       else if ((temp2 == 1) && (temp4 == 2)){
+                temp = temp1 + temp3 - temp5;
+           }
+       else if ((temp2 == 1) && (temp4 == 3)){
+                temp = temp1 + (temp3 * temp5);
+           }
+       else if ((temp2 == 1) && (temp4 == 4)){
+                temp = temp1 + (temp3 / temp5);
+           }
+       else if ((temp2 == 2) && (temp4 == 1)){
+                temp = temp1 - temp3 + temp5;
+        }
+       else if ((temp2 == 2) && (temp4 == 2)){
+                temp = temp1 - temp3 - temp5;
+        }
+       else if ((temp2 == 2) && (temp4 == 3)){
+                temp = temp1 - (temp3 * temp5);
+           }
+       else if ((temp2 == 2) && (temp4 == 4)){
+                temp = temp1 - (temp3 / temp5);
+           }
+       else if ((temp2 == 3) && (temp4 == 1)){
+                temp = temp1 * temp3 + temp5;
+        }
+       else if ((temp2 == 3) && (temp4 == 2)){
+                temp = temp1 * temp3 - temp5;
+        }
+       else if ((temp2 == 3) && (temp4 == 3)){
+                temp = temp1 * temp3 * temp5;
+        }
+       else if ((temp2 == 3) && (temp4 == 4)){
+                temp = temp1 * temp3 / temp5;
+        }
+       else if ((temp2 == 4) && (temp4 == 1)){
+                temp = temp1 / temp3 + temp5;
+        }
+       else if ((temp2 == 4) && (temp4 == 2)){
+                temp = temp1 / temp3 - temp5;
+        }
+       else if ((temp2 == 4) && (temp4 == 3)){
+                temp = temp1 / temp3 * temp5;
+        }
+       else if ((temp2 == 4) && (temp4 == 4)){
+                temp = temp1 / temp3 / temp5;
+        }
+        else{
+            uLCD.printf("Error");
+            }
+        
+ uLCD.color(RED);
+ uLCD.printf("%0.2f\n", temp);
+
+  }
+  }   
\ No newline at end of file
diff -r 000000000000 -r f8d011978c8d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 21 17:19:40 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file