ECE 4180 Final Project
Dependencies: 4DGL-uLCD-SE mbed
main.cpp
- Committer:
- dbegasse
- Date:
- 2015-12-02
- Revision:
- 0:69cae396d104
- Child:
- 1:f7383e13e64f
File content as of revision 0:69cae396d104:
//Daniel Begasse //ECE 4180 Final Project #include "mbed.h" #include "uLCD_4DGL.h" #include <stdio.h> #include <stdlib.h> #include <mpr121.h> #include <vector> #include <iostream> #include <string> using namespace std; //Set up the interrupt pin InterruptIn interrupt(p26); // Setup the i2c bus on pins 9 and 10 I2C i2c(p9, p10); // constructor(i2c object, i2c address of the mpr121) Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); //create a global lcd project uLCD_4DGL uLCD(p28, p27, p30); // Setup the Serial to the PC for debugging Serial pc(USBTX, USBRX); //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_col = 0; char message[100]; int char_count = 0;//This is the number of times the space button has been pressed for the current message char key_1[1] = {'1'}; char key_2[4] = {'a','b','c','2'}; char key_3[4] = {'d','e','f','3'}; char key_4[4] = {'g','h','i','4'}; char key_5[4] = {'j','k','l','5'}; char key_6[4] = {'m','n','o','6'}; char key_7[5] = {'p','q','r','s','7'}; char key_8[4] = {'t','u','v','8'}; 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){ case (0x1): pressed = 10; validkey = true; break; case (0x10): pressed = 11; validkey = true; break; case (0x100): pressed = 12; validkey = true; break; case (0x2): pressed = 7; validkey = true; break; case (0x20): pressed = 8; validkey = true; break; case (0x200): pressed = 9; validkey = true; break; case (0x4): pressed = 4; validkey = true; break; case (0x40): pressed = 5; validkey = true; break; case (0x400): pressed = 6; validkey = true; break; case (0x8): pressed = 1; validkey = true; break; case (0x80): pressed = 2; validkey = true; break; case (0x800): pressed = 3; validkey = true; break; default: 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++; } } void checkCharacter(){ if (pressed == 1){ if (pressedcount > 0){ pressedcount = 0; } message[char_count] = '1'; } if (pressed == 2){ if (pressedcount > 3){ pressedcount = 0; } message[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] = ' '; } } 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++ ){ uLCD.printf("%c", message[i]); } //message[char_count + 1] = '|'; } void printCursor(){ uLCD.text_char('|',char_count + 1, cursor_row, BLUE); wait(.5); uLCD.text_char('|',char_count + 1, cursor_row, BLACK); wait(.5); } int main(){ pc.baud(9600); 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 } }