ECE 4180 Final Project

Dependencies:   4DGL-uLCD-SE mbed

Files at this revision

API Documentation at this revision

Comitter:
dbegasse
Date:
Tue Dec 08 15:44:18 2015 +0000
Parent:
1:f7383e13e64f
Commit message:
ECE 4180 Final Project: XBee iMessage

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show diff for this revision Revisions of this file
diff -r f7383e13e64f -r 4d9a4421fc08 main.cpp
--- a/main.cpp	Tue Dec 08 00:24:37 2015 +0000
+++ b/main.cpp	Tue Dec 08 15:44:18 2015 +0000
@@ -1,9 +1,10 @@
 //Daniel Begasse
-//ECE 4180 Final Project
+//Keith Ng
+//This is our ECE 4180 Final Project
+//We use the uLCD, MPR121 Capacitive Touch Pad, XBee, and a pushbutton to send text messages between two identical breadboards
 
 #include "mbed.h"
 #include "uLCD_4DGL.h"
-#include "rtos.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <mpr121.h>
@@ -31,32 +32,27 @@
 Serial xbee(p13, p14);
 DigitalOut rst1(p11);
 
-
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
 DigitalOut led3(LED3);
 DigitalOut led4(LED4);
 DigitalIn send(p21);
 
-//Setup the timer
-//Timer t;
- 
-
 volatile bool tripped = false;
 volatile bool validkey;//This represents if the key pressed was a valid key
 volatile int oldpressed;//This is the previous key that was pressed
 volatile int value;//This is the value coming in from the register
 volatile int pressed;//This is the current key being pressed
 volatile int pressedcount = 0;//This is how many times the current key has been repeatedly pressed
-int cursor_row = 0;
+int cursor_row = 13;
 int cursor_col = 0;
-int sent_row = 0;
-int sent_col = 0;
-char message[100] = {'-'};
-string message_send = "-";
-string message_receive = "-";
-char message_received[100] = {'-'};
+int read_row = 0;
+int read_col = 0;
+string message_send = "-                  ";
+string message_receive = "                    ";
 int char_count = 0;//This is the number of times the space button has been pressed for the current message
+unsigned size; 
+int received_count = 0;
 
 bool sent = false;
 
@@ -152,7 +148,6 @@
             if (pressedcount > 0){
                 pressedcount = 0;
             } 
-            //message[char_count] =  '1';
             message_send[char_count] = '1';
         }
         
@@ -160,7 +155,6 @@
             if (pressedcount > 3){
                 pressedcount = 0;
             }
-            //message[char_count] =  key_2[pressedcount];
             message_send[char_count] = key_2[pressedcount];
         }
             
@@ -168,85 +162,94 @@
             if (pressedcount > 3){
                 pressedcount = 0;
             } 
-            
-            message[char_count] =  key_3[pressedcount];
+            message_send[char_count] = key_3[pressedcount];
         }
         
         if (pressed == 4){
             if (pressedcount > 3){
                 pressedcount = 0;
             } 
-            message[char_count] =  key_4[pressedcount];
+            message_send[char_count] = key_4[pressedcount];
         }
         
         if (pressed == 5){
             if (pressedcount > 3){
                 pressedcount = 0;
             }
-            message[char_count] =  key_5[pressedcount];
+            message_send[char_count] = key_5[pressedcount];
         }
         
         if (pressed == 6){
             if (pressedcount > 3){
                 pressedcount = 0;
             } 
-            message[char_count] =  key_6[pressedcount];
+            message_send[char_count] = key_6[pressedcount];
         }
         
         if (pressed == 7){
             if (pressedcount > 4){
                 pressedcount = 0;
             } 
-            message[char_count] =  key_7[pressedcount];
+            message_send[char_count] = key_7[pressedcount];
         }
         
         if (pressed == 8){
             if (pressedcount > 3){
                 pressedcount = 0;
             } 
-            message[char_count] =  key_8[pressedcount];
+            message_send[char_count] = key_8[pressedcount];
         }
         
         if (pressed == 9){
             if (pressedcount > 4){
                 pressedcount = 0;
             } 
-            message[char_count] =  key_9[pressedcount];
+            message_send[char_count] = key_9[pressedcount];
         }
     
         if (pressed == 10) {        
-            message[char_count] = ' ';
+            message_send[char_count] = ' ';
+        }
+        if (pressed == 11) {       
+            if (pressedcount > 0){
+                pressedcount = 0;
+            }  
+            message_send[char_count] = '0';
         }
 }
 
 void printMessage(){
     
-    uLCD.locate(cursor_col ,cursor_row);
+    uLCD.locate(cursor_col, cursor_row);
     
-    //for ( unsigned i = 0; i <= char_count; i++ ){
+    //This will print the current message being typed towards the bottom of the lcd screen
+    for ( unsigned i = 0; i <= char_count; i++ ){
         
-        //uLCD.printf("%c", message[i]);
-    //}
+        uLCD.printf("%c", message_send[i]);
+    }
     
-    uLCD.printf("%s", message_send);
-}
-
-void printCursor(){
-    
-    uLCD.text_char('|',char_count + 1, cursor_row, BLUE);
-    wait(.5);
-    uLCD.text_char('|',char_count + 1, cursor_row, BLACK);
-    wait(.5);
+    //If the message was just sent, 
+    if ( sent == true ){
+        
+        uLCD.locate(0, cursor_row);
+        
+        for ( unsigned i = 1; i <= char_count+1; i++ ){
+        
+            message_send[i] = ' ';//Overwrite all of the spots in the string with  a space
+            uLCD.printf("%c", message_send[i]);
+        }
+        char_count = 0;
+    }
 }
 
 void write(){
     
     char chartosend;
-        
+          
     for ( unsigned i = 0; i <= char_count; i++ ){
         
         //Go through each char of message and send the char's 1 by 1 through the xbee       
-        chartosend = message[i];        
+        chartosend = message_send[i];        
         xbee.printf("%c", chartosend);
     
         wait(0.01);
@@ -260,26 +263,32 @@
     
     char fromXBee;
     
-    led3 = 1;
-    wait(0.2);
+    //led3 = 1;
+    //wait(0.2);
+    
     
     if(xbee.readable()) {
         
+        uLCD.locate(received_count, read_row);
+        
         led4 = 1;
         wait(0.2);
         
-        uLCD.locate(sent_col ,sent_row);
         fromXBee = xbee.getc(); //Get individual characters being sent by other xbee
-        uLCD.printf("%c", fromXBee);
-        sent_col++;
+        message_receive[received_count] = fromXBee;
+        uLCD.printf("%c", message_receive[received_count]);
+        
+        received_count++;
+        
+        read();
         
         led4 = 0; 
-        wait(0.2);
+        //wait(0.2);
         
         }
     
-    led3 = 0;
-    wait(0.2);
+    //led3 = 0;
+    //wait(0.2);
     
 }
   
@@ -302,16 +311,25 @@
         checkCharacter();
         printMessage();
         
-        //sent = false;
+        sent = false;
         
         if ( send == 0 ){
         
             led2 = 1;
             write();
-            //sent = true; 
+            sent = true; 
+            pressed = 0;
+            validkey = false;
         }
         
         read();
+        
+        if (sent == true){
+            
+            read_row++;
+            received_count = 0;
+            
+        }
        
     }   
 }
\ No newline at end of file
diff -r f7383e13e64f -r 4d9a4421fc08 mbed-rtos.lib
--- a/mbed-rtos.lib	Tue Dec 08 00:24:37 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#c825593ece39