eiei

Dependencies:   LCD4884 mbed

Files at this revision

API Documentation at this revision

Comitter:
toiy01344
Date:
Mon Dec 11 23:05:41 2017 +0000
Commit message:
joystrick

Changed in this revision

LCD4884.lib Show annotated file Show diff for this revision Revisions of this file
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 6ac9ce3391e2 LCD4884.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD4884.lib	Mon Dec 11 23:05:41 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/Project-bike/code/LCD4884/#bf9618815a4a
diff -r 000000000000 -r 6ac9ce3391e2 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 11 23:05:41 2017 +0000
@@ -0,0 +1,796 @@
+#include "mbed.h"
+#include "LCD4884.h"
+#include <iostream>
+
+#define MENU_X 1
+#define MENU_Y 1
+AnalogIn joy(A0);
+LCD4884 lcd;
+Serial pc(PA_15,PB_7);
+Serial nutty(D1,D0);
+char func ;
+int i=0;
+int y=2;          
+int XA=0;
+int YA=2;
+int check = 0;
+char mode[42];
+int page = 0;
+float move=0;
+char V[5];
+char word[42];
+
+
+int main(){
+    lcd.backlight(ON);
+    lcd.LCD_init();
+    pc.baud(38400);
+    
+    while(1){
+        
+    printf("y=%d   page=%d   YA=%d   XA=%d   move=%.2f   mode=%d\n",y,page,YA,XA,move,mode);
+        move = joy.read()*1000;
+        if(move >= 0 && move <= 5){
+            XA -= 8; //left
+            wait(0.3);
+        }
+        if(move >= 475 && move <= 490){
+            YA += 1; //down
+            y += 3; 
+            wait(0.3);
+        }
+        if(move >= 700 && move <= 745){
+            XA += 8; //right
+            wait(0.3);
+        }
+        if(move >= 900){
+            YA -= 1; //up
+            y -= 3;
+            wait(0.3);
+        }
+        //switch
+        if(XA == 0 && YA == 0){
+            mode[0] = 1;
+            }
+        else{
+            mode[0] = 0;   
+            } 
+        if(XA == 0 && YA == 2){
+            mode[2] = 1;
+            }
+        else{
+            mode[2] = 0;   
+            }
+        if(XA == 0 && YA == 3){
+            mode[3] = 1;
+            }
+        else{
+            mode[3] = 0;   
+            }
+        if(XA == 0 && y == 5){
+            mode[5] = 1;
+            }
+        else{
+            mode[5] = 0;   
+            }
+        if(XA == 8 && YA == 0){
+            mode[1] = 1;
+            }
+        else{
+            mode[1] = 0;   
+            }
+        if(XA == 16 && YA == 0){
+            mode[4] = 1;
+            }
+        else{
+            mode[4] = 0;   
+            }
+        if(XA == 24 && YA == 0){
+            mode[6] = 1;
+            }
+        else{
+            mode[6] = 0;   
+            }
+        if(XA == 32 && YA == 0){
+            mode[7] = 1;
+            }
+        else{
+            mode[7] = 0;   
+            }
+        if(XA == 40 && YA == 0){
+            mode[8] = 1;
+            }
+        else{
+            mode[8] = 0;   
+            }
+        if(XA == 48 && YA == 0){
+            mode[9] = 1;
+            }
+        else{
+            mode[9] = 0;   
+            }
+        if(XA == 56 && YA == 0){
+            mode[10] = 1;
+            }
+        else{
+            mode[10] = 0;   
+            }
+        if(XA == 64 && YA == 0){
+            mode[11] = 1;
+            }
+        else{
+            mode[11] = 0;   
+            }
+        if(XA == 72 && YA == 0){
+            mode[12] = 1;
+            }
+        else{
+            mode[12] = 0;   
+            }    
+        if(XA == 0 && YA == 1){
+            mode[13] = 1;
+            }
+        else{
+            mode[13] = 0;   
+            }
+        if(XA == 8 && YA == 1){
+            mode[14] = 1;
+            }
+        else{
+            mode[14] = 0;   
+            }
+        if(XA == 16 && YA == 1){
+            mode[15] = 1;
+            }
+        else{
+            mode[15] = 0;   
+            }
+        if(XA == 24 && YA == 1){
+            mode[16] = 1;
+            }
+        else{
+            mode[16] = 0;   
+            }
+        if(XA == 32 && YA == 1){
+            mode[17] = 1;
+            }
+        else{
+            mode[17] = 0;   
+            }
+        if(XA == 40 && YA == 1){
+            mode[18] = 1;
+            }
+        else{
+            mode[18] = 0;   
+            }
+        if(XA == 48 && YA == 1){
+            mode[19] = 1;
+            }
+        else{
+            mode[19] = 0;   
+            }
+        if(XA == 56 && YA == 1){
+            mode[20] = 1;
+            }
+        else{
+            mode[20] = 0; 
+            }
+        if(XA == 64 && YA == 1){
+            mode[21] = 1;
+            }
+        else{
+            mode[21] = 0; 
+            }
+        if(XA == 72 && YA == 1){
+            mode[22] = 1;
+            }
+        else{
+            mode[22] = 0; 
+            }        
+        if(XA == 0 && YA == 2){
+            mode[23] = 1;
+            }
+        else{
+            mode[23] = 0;   
+            }
+        if(XA == 8 && YA == 2){
+            mode[24] = 1;
+            }
+        else{
+            mode[24] = 0;   
+            }
+        if(XA == 16 && YA == 2){
+            mode[25] = 1;
+            }
+        else{
+            mode[25] = 0;   
+            }
+        if(XA == 24 && YA == 2){
+            mode[26] = 1;
+            }
+        else{
+            mode[26] = 0;   
+            }
+        if(XA == 0 && YA == 4){
+            mode[27] = 1;
+            }
+        else{
+            mode[27] = 0;   
+            }
+        if(XA == 32 && YA == 2){
+            mode[28] = 1;
+            }
+        else{
+            mode[28] = 0;   
+            }
+        if(XA == 40 && YA == 2){
+            mode[29] = 1;
+            }
+        else{
+            mode[29] = 0;   
+            }
+        if(XA == 48  && YA == 2){
+            mode[31] = 1;
+            }
+        else{
+            mode[31] = 0;   
+            }    
+        if(XA == 8 && YA == 4){
+            mode[30] = 1;
+            }
+        else{
+            mode[30] = 0;   
+            }    
+        if(XA == 0  && YA == 3){
+            mode[32] = 1;
+            }
+        else{
+            mode[32] = 0;   
+            }
+        if(XA == 8  && YA == 3){
+            mode[33] = 1;
+            }
+        else{
+            mode[33] = 0;   
+            }
+        if(XA == 16  && YA == 3){
+            mode[34] = 1;
+            }
+        else{
+            mode[34] = 0;   
+            }
+        if(XA == 24  && YA == 3){
+            mode[35] = 1;
+            }
+        else{
+            mode[35] = 0;   
+            }      
+        if(XA == 32  && YA == 3){
+            mode[36] = 1;
+            }
+        else{
+            mode[36] = 0;   
+            }
+        if(XA == 40  && YA == 3){
+            mode[37] = 1;
+            }
+        else{
+            mode[37] = 0;   
+            }                      
+        if(XA == 48  && YA == 3){
+            mode[38] = 1;
+            }
+        else{
+            mode[38] = 0;   
+            }
+        if(XA == 56  && YA == 3){
+            mode[39] = 1;
+            }
+        else{
+            mode[39] = 0;   
+            }
+        if(XA == 64  && YA == 3){
+            mode[40] = 1;
+            }
+        else{
+            mode[40] = 0;   
+            }
+        if(XA == 72  && YA == 3){
+            mode[41] = 1;
+            }
+        else{
+            mode[41] = 0;   
+            }    
+                    
+        //page                                                         
+        if (page == 0){
+            lcd.LCD_clear();  
+            XA = 0;
+            if(YA < 2){
+                YA = 2;
+            }
+            //show menu    
+            lcd.LCD_write_string(0, 0, "     Menu     ", 0);
+            lcd.LCD_write_string(0, 1, "--------------", 0);
+            lcd.LCD_write_string(0, 2, "1.Show speed", mode[2]);
+            lcd.LCD_write_string(0, 3, "2.Show word", mode[3]);
+            if(YA > 3){
+                YA = 2;
+            }
+            if(XA == 0 && YA == 2){    
+                if(move >= 200 && move <= 215 ){
+                    page = 1;
+                    XA = 0; 
+                    YA = 0;
+                    y = 2;
+                    //pc.putc('1');
+                    wait(0.3);
+                    }
+            }
+            if(XA == 0 && YA == 3){    
+                if(move >= 200 && move <= 215 ){
+                    page = 2;
+                    XA = 0; 
+                    YA = 0;
+                    func = '!';
+                    pc.putc(func);
+                    
+                    //word.clear();
+                    wait(0.5);
+                    }
+            }
+        }
+        if (page == 1){
+            func = '?';
+            pc.putc(func);
+            lcd.LCD_clear(); 
+            XA = 0;
+            if(y < 2){
+                y = 5;
+            }
+            if(y > 5){
+                y = 2;
+            }
+            if(XA == 0 && y == 5){    
+                if(move >= 200 && move <= 215 ){
+                    page = 0;
+                    XA = 0; 
+                    YA = 2;
+                    wait(0.3);
+                    }
+            }    
+            lcd.LCD_write_string(0, 0, "   velocity   ", 0);
+            lcd.LCD_write_string(0, 1, "--------------", 0);
+            lcd.LCD_write_string(0, 5, "back", 1);
+            lcd.LCD_write_string(60, 4, "km/h", mode[28]);
+            while(1){
+            move = joy.read()*1000;
+            //printf("y=%d   page=%d   YA=%d   XA=%d   move=%.2f   mode=%d \n",y,page,YA,XA,move,mode);
+            y = 5;
+            if(pc.readable()){
+                for (int i =0;i<4;i++){
+                    V[i] = pc.getc();
+                }
+                nutty.printf("%c \n",V);
+                lcd.LCD_write_string_big(0, 2, V, mode[28]);
+                V[0]=' ';
+                V[1]=' ';
+                V[2]=' ';
+                V[3]=' ';
+                V[4]=' ';
+                }
+             if(XA == 0 && y == 5){    
+                if(move >= 200 && move <= 215 ){
+                    page = 0;
+                    XA = 0; 
+                    YA = 2;
+                    wait(0.3);
+                    break;
+                    }
+            }    
+            }
+            
+            
+        }
+        if (page == 2){
+            lcd.LCD_clear();
+            if(YA == 2 && XA > 48){
+                XA = 0;    
+            }
+            if(YA == 4 && XA < 0){
+                XA = 8;    
+            }
+            if(YA == 4 && XA > 8){
+                XA = 0;    
+            }
+            if(YA == 2 && XA < 0){
+                XA = 48;    
+            }  
+            if(YA < 0){
+                YA = 4;
+            }
+            if(XA < 0){
+                XA = 72;
+            }
+            if(YA > 4){
+                YA = 0;
+            }
+            if(XA > 72){
+                XA = 0;
+            }   
+            
+            //len
+            if (i > 5){
+                i=0;
+            }
+            
+            //add word                
+            if(XA == 0 && YA == 0){ 
+                if(move >= 200 && move <= 215 && check == 0 ){
+                    check = 1 ;
+                    wait(0.3);
+                    }
+                else if(move >= 200 && move <= 215 && check == 1 ){
+                    word[i] = 'A';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 8 && YA == 0){    
+                if(move >= 200 && move <= 215 ){
+                    word[i]= 'B';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 16 && YA == 0){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'C';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 24 && YA == 0){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'D';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 32 && YA == 0){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'E';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 40 && YA == 0){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'F';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 48 && YA == 0){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'G';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA ==56 && YA == 0){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'H';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA ==64 && YA == 0){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'I';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA ==72 && YA == 0){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'J';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 0 && YA == 1){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'K';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 8 && YA == 1){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'L';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 16 && YA == 1){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'M';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 24 && YA == 1){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'N';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 32 && YA == 1){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'O';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 40 && YA == 1){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'P';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 48 && YA == 1){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'Q';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA ==56 && YA == 1){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'R';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA ==64 && YA == 1){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'S';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA ==72 && YA == 1){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'T';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 0 && YA == 2){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'U';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 8 && YA == 2){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'V';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 16 && YA == 2){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'W';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 24 && YA == 2){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'X';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 32 && YA == 2){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'Y';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 40 && YA == 2){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = 'Z';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 48 && YA == 2){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = ' ';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 0 && YA == 3){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = '1';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 8 && YA == 3){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = '2';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 16 && YA == 3){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = '3';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 24 && YA == 3){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = '4';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 32 && YA == 3){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = '5';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 40 && YA == 3){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = '6';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 48 && YA == 3){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = '7';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 56 && YA == 3){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = '8';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 64 && YA == 3){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = '9';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            if(XA == 72 && YA == 3){    
+                if(move >= 200 && move <= 215 ){
+                    word[i] = '0';
+                    i++;
+                    wait(0.3);
+                    }
+            }
+            
+            //show select
+            lcd.LCD_write_string(0, 0, "A", mode[0]);
+            lcd.LCD_write_string(8, 0, "B", mode[1]);
+            lcd.LCD_write_string(16, 0, "C", mode[4]);
+            lcd.LCD_write_string(24, 0, "D", mode[6]);
+            lcd.LCD_write_string(32, 0, "E", mode[7]);
+            lcd.LCD_write_string(40, 0, "F", mode[8]);
+            lcd.LCD_write_string(48, 0, "G", mode[9]);
+            lcd.LCD_write_string(56, 0, "H", mode[10]);
+            lcd.LCD_write_string(64, 0, "I", mode[11]);
+            lcd.LCD_write_string(72, 0, "J", mode[12]);
+            lcd.LCD_write_string(0, 1, "K", mode[13]);
+            lcd.LCD_write_string(8, 1, "L", mode[14]);
+            lcd.LCD_write_string(16, 1, "M", mode[15]);
+            lcd.LCD_write_string(24, 1, "N", mode[16]);
+            lcd.LCD_write_string(32, 1, "O", mode[17]);
+            lcd.LCD_write_string(40, 1, "P", mode[18]);
+            lcd.LCD_write_string(48, 1, "Q", mode[19]);
+            lcd.LCD_write_string(56, 1, "R", mode[20]);
+            lcd.LCD_write_string(64, 1, "S", mode[21]);
+            lcd.LCD_write_string(72, 1, "T", mode[22]);
+            lcd.LCD_write_string(0, 2, "U", mode[23]);
+            lcd.LCD_write_string(8, 2, "V", mode[24]);
+            lcd.LCD_write_string(16, 2, "W", mode[25]);
+            lcd.LCD_write_string(24, 2, "X", mode[26]);
+            lcd.LCD_write_string(32, 2, "Y", mode[28]);
+            lcd.LCD_write_string(40, 2, "Z", mode[29]);
+            lcd.LCD_write_string(48, 2, "space", mode[31]);
+            lcd.LCD_write_string(0, 3, "1", mode[32]);
+            lcd.LCD_write_string(8, 3, "2", mode[33]);
+            lcd.LCD_write_string(16, 3, "3", mode[34]);
+            lcd.LCD_write_string(24, 3, "4", mode[35]);
+            lcd.LCD_write_string(32, 3, "5", mode[36]);
+            lcd.LCD_write_string(40, 3, "6", mode[37]);
+            lcd.LCD_write_string(48, 3, "7", mode[38]);
+            lcd.LCD_write_string(56, 3, "8", mode[39]);
+            lcd.LCD_write_string(64, 3, "9", mode[40]);
+            lcd.LCD_write_string(72, 3, "0", mode[41]);
+            lcd.LCD_write_string(0, 5, "back", mode[27]);
+            lcd.LCD_write_string(56, 5, "sent", mode[30]);
+            lcd.LCD_write_string(13, 4, "<", 0);
+            lcd.LCD_write_string(22, 4, word,0);
+            lcd.LCD_write_string(60, 4, ">", 0);
+            
+            if(XA == 0 && YA == 4){    
+                if(move >= 200 && move <= 215 ){
+                    page = 0;
+                    check = 0 ;
+                    XA = 0; 
+                    YA = 2;
+                    i=0;
+                    wait(0.3);  
+                    }
+            }
+            if(XA == 8 && YA == 4){    
+                if(move >= 200 && move <= 215 ){
+                    pc.putc('&');
+                    for (int i =0; i<6 ;i++)
+                    {
+                        pc.putc(word[i]);
+                        wait(0.3);
+                    }
+                    page = 3;
+                    }
+            }    
+        }
+        if (page == 3){
+            lcd.LCD_clear();  
+            //show word    
+            lcd.LCD_write_string(0, 0, "    word    ", 0);
+            lcd.LCD_write_string(0, 1, "--------------", 0);
+            lcd.LCD_write_string(22, 3, word, 0);
+            lcd.LCD_write_string(0, 5, "back", 1);
+            XA = 1;
+            YA = 1;
+            int chk;
+            if(XA == 1 && YA == 1 && move > 250)
+            {
+                XA = 0;
+                YA = 5;
+                chk = 0;
+            }
+            while(chk == 0)
+            {
+                move = joy.read()*1000;
+                if(XA==0 && YA==5 && move >= 200 && move <= 215){
+                    page = 2;
+                    XA = 0;
+                    YA = 0;
+                    word[0] = ' ';
+                    word[1] = ' '; 
+                    word[2] = ' '; 
+                    word[3] = ' '; 
+                    word[4] = ' '; 
+                    word[5] = ' ';  
+                    wait(0.3);
+                    chk = 1;
+                    check = 0;
+                    }
+            }
+            }
+                    
+        }
+    }
+
diff -r 000000000000 -r 6ac9ce3391e2 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Dec 11 23:05:41 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/fb8e0ae1cceb
\ No newline at end of file