vmh

Dependencies:   mbed

Revision:
0:4562b55bbb43
Child:
1:b4814760d8ee
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 11 08:43:44 2017 +0000
@@ -0,0 +1,499 @@
+#include "mbed.h"
+#include "ColorMbed.h"
+#include "TextLCD.h"
+
+ColorMbed dotmatrix;
+Serial bt(PA_15, PB_7);
+Serial pc(D1,D0);
+
+
+I2C i2c_lcd(D14,D15); // SDA, SCL
+TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2, TextLCD::HD44780); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type 
+
+
+int main(void)
+{
+    int ch;
+    int x=0;
+    int x0=0;
+    int x1=0;
+    int x2=0;
+    int x3=0;
+    int x4=0;
+    int x5=0;
+    int x6=0;
+    int x7=0;
+    int x8=0;
+    int amount =0;
+    int stateprint1 = 0;
+    int stateprint2 = 0;
+    int stateprint3 = 0;
+    int stateprint4 = 0;
+    int stateprint5 = 0;
+    int stateprint6 = 0;
+
+  // uint8_t rgb[3] = {255,255,100};
+  uint8_t rgbready[3] = {100,100,100};   //เริ่มต้นสีโรสโกล
+  uint8_t green[3] = {0,255,0};        //ไฟเขียว
+  uint8_t red[3] = {0,0,100};       //ไฟเฟล:ไม่ถึงองศาที่ต้องการ 
+  uint8_t yellow[3] = {0,150,200};  // ไฟสีเหลือง
+  
+  
+  
+  uint8_t tast[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; //เทสไฟติดเต็มแผ่น 
+  uint8_t complete[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF}; //สำเร็จติดสองแถว
+  uint8_t Ncomplete[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF}; //ไม่สำร็จติดสองแถว
+  
+  
+  
+  
+  
+  
+  //คิดว่าไม่น่าใช้ 
+ /*uint8_t pic[8] = {0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00};  // ติด1ดวง
+  uint8_t pic2[8] = {0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00}; // ติด 2 ดวง
+  uint8_t pic3[8] = {0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00};
+  uint8_t pic4[8] = {0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00};
+  uint8_t pic5[8] = {0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00};
+  uint8_t pic6[8] = {0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00};
+  uint8_t pic7[8] = {0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80};*/
+  
+  
+  
+  
+  
+  
+  
+  // ระดับ left
+  uint8_t greenleft[8] = {0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00};
+  uint8_t yellowleft[8] = {0x00,0x00,0x80,0x00,0x00,0x80,0x00,0x00};
+  uint8_t redleft[8] = {0x80,0x80,0x00,0x00,0x00,0x00,0x80,0x80};
+    // right 
+  uint8_t greenright[8] = {0x00,0x00,0x00,0x0,0x0,0x00,0x00,0x18};
+  uint8_t yellowright[8] = {0x00,0x00,0x0,0x00,0x00,0x00,0x00,0x24};
+  uint8_t redright[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC3};
+  // เลข 1-30
+  uint8_t zero[8] = {0x1C,0x14,0x14,0x14,0x14,0x14,0x1C,0x00};
+  uint8_t one[8] = {0x1C,0x08,0x08,0x08,0x08,0x18,0x08,0x00};
+  uint8_t two[8] = {0x1C,0x10,0x10,0x1C,0x04,0x04,0x1C,0x00};
+  uint8_t three[8] = {0x1C,0x04,0x04,0x1C,0x04,0x04,0x1C,0x00};
+  uint8_t four[8] = {0x04,0x04,0x04,0x1C,0x14,0x14,0x14,0x00};
+  uint8_t five[8] = {0x1C,0x04,0x04,0x1C,0x10,0x10,0x1C,0x00};
+  uint8_t six[8] = {0x1C,0x14,0x14,0x1C,0x10,0x10,0x1C,0x00};
+  uint8_t seven[8] = {0x04,0x04,0x04,0x04,0x04,0x04,0x1C,0x00};
+  uint8_t eight[8] = {0x1C,0x14,0x14,0x1C,0x14,0x14,0x1C,0x00};
+  uint8_t nine[8] = {0x1C,0x04,0x04,0x1C,0x14,0x14,0x1C,0x00};
+  uint8_t ten[8] = {0x3F,0x15,0x15,0x15,0x15,0x35,0x17,0x00};
+  uint8_t eleven[8] = {0x3F,0x12,0x12,0x12,0x12,0x36,0x12,0x00};
+  uint8_t twelve[8] = {0x3F,0x14,0x14,0x17,0x11,0x31,0x17,0x00};
+  uint8_t thirteen[8] = {0x3F,0x11,0x11,0x17,0x11,0x31,0x17,0x00};
+  uint8_t fourteen[8] = {0x39,0x11,0x11,0x17,0x15,0x35,0x15,0x00};
+  uint8_t fifteen[8] = {0x3F,0x11,0x11,0x17,0x14,0x34,0x17,0x00};
+  uint8_t sixteen[8] = {0x3F,0x15,0x15,0x17,0x14,0x34,0x17,0x00};
+  uint8_t seventeen[8] = {0x39,0x11,0x11,0x11,0x11,0x31,0x17,0x00};
+  uint8_t eightteen[8] = {0x3F,0x15,0x15,0x17,0x15,0x35,0x17,0x00};
+  uint8_t ninteen[8] = {0x3F,0x11,0x11,0x17,0x15,0x35,0x17,0x00};
+  uint8_t twenty[8] = {0x3F,0x25,0x25,0x3D,0x0D,0x0D,0x3F,0x00};
+  uint8_t twone[8] = {0x3F,0x22,0x22,0x3A,0x0A,0x0E,0x3A,0x00};
+  uint8_t twtwo[8] = {0x3F,0x24,0x24,0x3F,0x09,0x09,0x3F,0x00};
+  uint8_t twthree[8] = {0x3F,0x21,0x21,0x3F,0x09,0x09,0x3F,0x00};
+  uint8_t twfour[8] = {0x39,0x21,0x21,0x3F,0x0D,0x0D,0x3D,0x00};
+  uint8_t twfive[8] = {0x3F,0x21,0x21,0x3F,0xC,0xC,0x3F,0x00};
+  uint8_t twsix[8] = {0x3F,0x25,0x25,0x3F,0xC,0xC,0x3F,0x00};
+  uint8_t twseven[8] = {0x39,0x21,0x21,0x39,0x9,0x9,0x3F,0x00};
+  uint8_t tweight[8] = {0x3F,0x25,0x25,0x3F,0xD,0xD,0x3F,0x00};
+  uint8_t twnine[8] = {0x3F,0x21,0x21,0x3F,0xD,0xD,0x3F,0x00};
+  uint8_t thirty[8] = {0x3F,0xD,0xD,0x3D,0x0D,0x0D,0x3F,0x00};
+  
+  //องศา 
+  uint8_t gound[8] = {0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x81}; //จุดสองจุด
+  uint8_t step1[8] = {0x00,0x0,0x0,0x0,0x0,0x0,0x0,0x40};  //สเต็ปองศา
+  uint8_t step2[8] = {0x00,0x0,0x0,0x0,0x0,0x0,0x0,0x60};
+  uint8_t step3[8] = {0x00,0x0,0x0,0x0,0x0,0x0,0x0,0x70};
+  uint8_t step4[8] = {0x00,0x0,0x0,0x0,0x0,0x0,0x0,0x78};
+  uint8_t step5[8] = {0x00,0x0,0x0,0x0,0x0,0x0,0x0,0x7C};
+  uint8_t step6[8] = {0x00,0x0,0x0,0x0,0x0,0x0,0x0,0x7E};
+  
+  dotmatrix.init();
+  
+  
+  
+
+     do{
+        if(bt.readable()){
+            ch=bt.getc();
+            pc.printf("%d\n",ch);
+        }
+        if ((ch <=15 and ch >=0) or x==1){
+            if (stateprint1 == 0){
+                pc.printf("   pass step1   ");
+                lcd.cls();
+                lcd.printf("   pass step1   ");
+                stateprint1 =1;
+            }
+            
+            dotmatrix.display_pic(one,green);
+            dotmatrix.display_pic(step1,green);
+//            
+//                                if (amount==0){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);             
+//                                    dotmatrix.display_pic(one,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                } 
+//                                     
+//                                if (amount==1){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(two,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                if (amount==2){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(three,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                }
+//                                 
+//                                if (amount==3){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(four,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                if (amount==4){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(five,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                if (amount==5){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(six,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                if (amount==6){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(seven,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                if (amount==7){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(eight,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                if (amount==8){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(nine,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                if (amount==9){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(ten,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                }             
+                                x=1;
+            if((ch <=30 and ch >=16) or x2==1){
+                if (stateprint2 == 0){
+                    pc.printf("   pass step2   ");
+                    lcd.cls();
+                    lcd.printf("   pass step2   ");
+                    stateprint2 =1;
+                }
+//                                if (amount==0){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);             
+//                                    dotmatrix.display_pic(one,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                } 
+//                                     
+//                                else if (amount==1){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(two,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                else if (amount==2){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(three,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                }
+//                                 
+//                                else if (amount==3){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(four,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                else if (amount==4){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(five,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                else if (amount==5){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(six,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                else if (amount==6){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(seven,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                else if (amount==7){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(eight,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                else if (amount==8){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(nine,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                } 
+//                                
+//                                else if (amount==9){
+//                                    pc.printf("   amount %d   ",amount);
+//                                    lcd.cls();
+//                                    lcd.printf("   amount %d   ",amount);      
+//                                    dotmatrix.display_pic(ten,green);
+//                                    dotmatrix.display_pic(step1,green);
+//                                    
+//                                }   
+                dotmatrix.display_pic(one,green);
+                dotmatrix.display_pic(step2,green);
+                x2=1;
+                if((ch <=45 and ch >=31) or x3==1)
+                    {
+                    if (stateprint3 == 0){
+                        pc.printf("   pass step3   ");
+                        lcd.cls();
+                        lcd.printf("   pass step3   ");
+                        stateprint3 =1;
+                        //dotmatrix.display_pic(one,green);
+//                        dotmatrix.display_pic(step3,green);
+
+                    }
+                    dotmatrix.display_pic(one,green);
+                    dotmatrix.display_pic(step3,green);
+                    x3=1;
+                    if((ch <=60 and ch >=46) or x4==1)
+                        {
+                        if (stateprint4 == 0){
+                            pc.printf("   pass step4   ");
+                            lcd.cls();
+                            lcd.printf("   pass step4   ");
+                            stateprint4 =1;
+                                            
+                        }
+                        dotmatrix.display_pic(one,green);
+                        dotmatrix.display_pic(step4,green);
+                        x4=1;
+                        if((ch <=75 and ch >=61) or x5==1){
+                            if (stateprint5 == 0){
+                                pc.printf("   pass step5   ");
+                                lcd.cls();
+                                lcd.printf("   pass step5   ");
+                                stateprint5 =1;
+        
+                            }
+                            dotmatrix.display_pic(one,green);
+                            dotmatrix.display_pic(step5,green);
+                            x5=1;
+                        if((ch <=90 and ch >=76) or x6==1){
+                                if (stateprint6 == 0){
+                                    pc.printf("   pass step6   ");
+                                    lcd.cls();
+                                    lcd.printf("   pass step6   ");
+                                    stateprint6 =1;
+            
+                                }
+                                for (int i = 1; i <= 230; i++)
+                                        {        
+                                    
+                                dotmatrix.display_pic(one,green);
+                                dotmatrix.display_pic(step6,green);
+                                
+                                }
+                                x6=1;
+                                amount=amount+1;
+                                pc.printf("   amount %d   ",amount);       
+                                if (amount==1){
+                                    pc.printf("   amount %d   ",amount);
+                                    lcd.cls();
+                                    lcd.printf("   amount %d   ",amount);      
+                                    for (int i = 1; i <= 230; i++)
+                                        {        
+                                        dotmatrix.display_pic(one,green);
+                                    }
+                                } 
+                                     
+                                if (amount==2){
+                                    pc.printf("   amount %d   ",amount);
+                                    lcd.cls();
+                                    lcd.printf("   amount %d   ",amount);      
+                                    for (int i = 1; i <= 500; i++){        
+                                        dotmatrix.display_pic(two,green);
+                                    }
+                                } 
+                                
+                                if (amount==3){
+                                    pc.printf("   amount %d   ",amount);
+                                    lcd.cls();
+                                    lcd.printf("   amount %d   ",amount);      
+                                    for (int i = 1; i <= 500; i++){        
+                                        dotmatrix.display_pic(three,green);
+                                    }
+                                }
+                                 
+                                if (amount==4){
+                                    pc.printf("   amount %d   ",amount);
+                                    lcd.cls();
+                                    lcd.printf("   amount %d   ",amount);      
+                                    for (int i = 1; i <= 500; i++){        
+                                        dotmatrix.display_pic(four,green);
+                                    }
+                                } 
+                                
+                                if (amount==5){
+                                    pc.printf("   amount %d   ",amount);
+                                    lcd.cls();
+                                    lcd.printf("   amount %d   ",amount);      
+                                    for (int i = 1; i <= 500; i++){        
+                                        dotmatrix.display_pic(five,green);
+                                    }
+                                } 
+                                
+                                if (amount==6){
+                                    pc.printf("   amount %d   ",amount);
+                                    lcd.cls();
+                                    lcd.printf("   amount %d   ",amount);      
+                                    for (int i = 1; i <= 500; i++){        
+                                        dotmatrix.display_pic(six,green);
+                                    }
+                                } 
+                                
+                                if (amount==7){
+                                    pc.printf("   amount %d   ",amount);
+                                    lcd.cls();
+                                    lcd.printf("   amount %d   ",amount);      
+                                    for (int i = 1; i <= 500; i++){        
+                                        dotmatrix.display_pic(seven,green);
+                                    }
+                                } 
+                                
+                                if (amount==8){
+                                    pc.printf("   amount %d   ",amount);
+                                    lcd.cls();
+                                    lcd.printf("   amount %d   ",amount);      
+                                    for (int i = 1; i <= 500; i++){        
+                                        dotmatrix.display_pic(eight,green);
+                                    }
+                                } 
+                                
+                                if (amount==9){
+                                    pc.printf("   amount %d   ",amount);
+                                    lcd.cls();
+                                    lcd.printf("   amount %d   ",amount);      
+                                    for (int i = 1; i <= 500; i++){        
+                                        dotmatrix.display_pic(nine,green);
+                                    }
+                                } 
+                                
+                                if (amount==10){
+                                    pc.printf("   amount %d   ",amount);
+                                    lcd.cls();
+                                    lcd.printf("   amount %d   ",amount);      
+                                    for (int i = 1; i <= 500; i++){        
+                                        dotmatrix.display_pic(ten,green);
+                                    }
+                                } 
+                                
+                                if (amount==0){
+                                    pc.printf("   amount %d   ",amount);
+                                    lcd.cls();
+                                    lcd.printf("   amount %d   ",amount);      
+                                    for (int i = 1; i <= 500; i++){        
+                                        dotmatrix.display_pic(two,green);
+                                    }
+                                } 
+                                x=0;
+                                x1=0;
+                                x2=0;
+                                x3=0;
+                                x4=0;
+                                x5=0;
+                                x6=0;
+                                stateprint1 = 0;
+                                stateprint2 = 0;
+                                stateprint3 = 0;
+                                stateprint4 = 0;
+                                stateprint5 = 0;
+                            }
+                        }
+                    }
+                }
+            }
+        }  
+        }while(amount != 10);
+                        pc.printf("yeahhhhhhh");
+}
\ No newline at end of file