ECE 4180 Final Project
Dependencies: 4DGL-uLCD-SE mbed
Diff: main.cpp
- Revision:
- 1:f7383e13e64f
- Parent:
- 0:69cae396d104
- Child:
- 2:4d9a4421fc08
--- a/main.cpp Wed Dec 02 01:31:21 2015 +0000 +++ b/main.cpp Tue Dec 08 00:24:37 2015 +0000 @@ -3,10 +3,10 @@ #include "mbed.h" #include "uLCD_4DGL.h" +#include "rtos.h" #include <stdio.h> #include <stdlib.h> #include <mpr121.h> -#include <vector> #include <iostream> #include <string> @@ -27,6 +27,17 @@ // Setup the Serial to the PC for debugging Serial pc(USBTX, USBRX); +//Set up XBee +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; @@ -39,9 +50,16 @@ volatile int pressedcount = 0;//This is how many times the current key has been repeatedly pressed int cursor_row = 0; int cursor_col = 0; -char message[100]; +int sent_row = 0; +int sent_col = 0; +char message[100] = {'-'}; +string message_send = "-"; +string message_receive = "-"; +char message_received[100] = {'-'}; int char_count = 0;//This is the number of times the space button has been pressed for the current message +bool sent = false; + char key_1[1] = {'1'}; char key_2[4] = {'a','b','c','2'}; char key_3[4] = {'d','e','f','3'}; @@ -53,15 +71,11 @@ char key_9[5] = {'w','x','y','z','9'}; char key_10[1] = {' '}; - - void fallInterrupt() { validkey = false;//Each key pressed is invalid until proven to be valid value = mpr121.read(0x00); value += mpr121.read(0x01)<<8; - //pc.printf("Value: %x \r\n", value); - //Take the value from the register and use it to assign a key # switch(value){ @@ -118,166 +132,103 @@ validkey = false; break; } - - + //If the two values are different, assign pressed to oldpressed if ((pressed != oldpressed) && (validkey == true) ){ oldpressed = pressed; pressedcount = 0; char_count++;//move the cursor over if there is a new key - - } else if ((pressed == oldpressed) && (value != 0)) { - pressedcount++; - + pressedcount++; } - - } - void checkCharacter(){ - - if (pressed == 1){ - if (pressedcount > 0){ - pressedcount = 0; - } - - message[char_count] = '1'; - + //message[char_count] = '1'; + message_send[char_count] = '1'; } - - if (pressed == 2){ - + if (pressed == 2){ if (pressedcount > 3){ - pressedcount = 0; - } - - message[char_count] = key_2[pressedcount]; - + //message[char_count] = key_2[pressedcount]; + message_send[char_count] = key_2[pressedcount]; } if (pressed == 3){ - if (pressedcount > 3){ - pressedcount = 0; - } message[char_count] = key_3[pressedcount]; - } if (pressed == 4){ - if (pressedcount > 3){ - pressedcount = 0; - } - message[char_count] = key_4[pressedcount]; - } if (pressed == 5){ - if (pressedcount > 3){ - pressedcount = 0; - - } - + } message[char_count] = key_5[pressedcount]; - } if (pressed == 6){ - if (pressedcount > 3){ - pressedcount = 0; - } - message[char_count] = key_6[pressedcount]; - } if (pressed == 7){ - if (pressedcount > 4){ - pressedcount = 0; - } - message[char_count] = key_7[pressedcount]; - } if (pressed == 8){ - if (pressedcount > 3){ - pressedcount = 0; - } - message[char_count] = key_8[pressedcount]; - } if (pressed == 9){ - if (pressedcount > 4){ - pressedcount = 0; - } - message[char_count] = key_9[pressedcount]; - - } - - - if (pressed == 10) { - - - message[char_count] = ' '; - } + if (pressed == 10) { + message[char_count] = ' '; + } } void printMessage(){ uLCD.locate(cursor_col ,cursor_row); - //To save time only print if the size of the array has changed - //look at char count to tell - - for ( unsigned i = 0; i <= char_count; i++ ){ + //for ( unsigned i = 0; i <= char_count; i++ ){ - uLCD.printf("%c", message[i]); - } - - //message[char_count + 1] = '|'; + //uLCD.printf("%c", message[i]); + //} - - + uLCD.printf("%s", message_send); } void printCursor(){ @@ -286,38 +237,81 @@ wait(.5); uLCD.text_char('|',char_count + 1, cursor_row, BLACK); wait(.5); +} + +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]; + xbee.printf("%c", chartosend); + + wait(0.01); + led2 = 1; + wait(0.01); + led2 = 0; + } +} + +void read(){ + + char fromXBee; + + led3 = 1; + wait(0.2); + + if(xbee.readable()) { + + 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++; + + led4 = 0; + wait(0.2); + + } + + led3 = 0; + wait(0.2); } - int main(){ + rst1 = 0; + wait_ms(1); + rst1 = 1; + wait_ms(1); + pc.baud(9600); + send.mode(PullUp); interrupt.mode(PullUp); wait(.001); interrupt.fall(&fallInterrupt); - //Timer t; - while(1){ - - - //pc.printf("Whats in the list... %c\n", message[char_count]); checkCharacter(); - //printCursor(); printMessage(); - //USE A PUSH BUTTON TO MOVE THE CURSOR MANUALLY - //WHEN YOU MOVE THE CURSOR, ADD THE PREVIOUS CHARACTER TO THE MESSAGE VECTOR - //THEN WHEN YOU TRY TO SEND YOU SEND THE VECTORO + //sent = false; + + if ( send == 0 ){ + led2 = 1; + write(); + //sent = true; } - -} - - - - - + + read(); + + } +} \ No newline at end of file