Mahandra Raditya / Mbed 2 deprecated NewLCDCalibrator

Dependencies:   TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // https://www.youtube.com/watch?v=yScO_v7NUYQ 
00002 // LEITURA DE BOTÕES
00003 
00004 #include "mbed.h"
00005 #include "TextLCD.h"
00006 
00007 
00008 //FRDM-K64F
00009 //TextLCD lcd(PTA0,PTC4,PTB23,PTA2,PTC2,PTC3); // rs, e, d4-d7
00010 TextLCD lcd(D8, D9, D4, D5, D6, D7); // rs, e, d4-d7
00011 
00012 DigitalIn digi1 (D1);
00013 DigitalIn digi2 (D2);
00014 DigitalIn digi3 (D3);
00015 
00016 enum States {calib1, calib2, homing, emgcontrol, demo}; //calib1=0, calib2=1, ..., demo=4
00017 int state;
00018 Ticker      main_loop;
00019 
00020 float looptime = 0.001f;
00021 
00022 //Timer       time;
00023 
00024 
00025                 
00026 AnalogIn Sensor(PTB2); //ESPECIFICA O PINO DE LEITURA ANALOGICA PARA FRDM-K64F 
00027 void loopfunction(){
00028     switch (state){
00029             case calib1:
00030                 lcd.printf(" * Calibrating... /n motor 1 * "); //while in calib 1 print
00031                 lcd.cls();
00032             break;
00033         
00034             case calib2:
00035                 lcd.printf(" * Calibrating... /n motor 2 * "); //while in calib 2 print
00036                 lcd.cls();
00037             break;
00038         
00039             case homing:
00040                 lcd.printf(" * Homing... * "); //while in homing print
00041                 lcd.cls();
00042             break;
00043         
00044             case emgcontrol:
00045                 lcd.printf(" * Calibrating EMG... * "); //while calibrating EMG print
00046                 lcd.cls();
00047             break;
00048         
00049             case demo:
00050                 lcd.printf(" * demo... * "); //while in demo print
00051                 lcd.cls();
00052             break;
00053         }
00054 }
00055 
00056 
00057 
00058 
00059 int main() {
00060     
00061     lcd.printf(" Calibration \n FRDM-K64F");
00062     wait(3);   
00063     lcd.cls();   
00064      main_loop.attach(&loopfunction, looptime); //1000 Hz main loop
00065      while(1){                                                  // Clean the display
00066 if(Sensor.read_u16()>12000 && Sensor.read_u16()< 15000){
00067                state = calib1;                
00068                 } 
00069                 
00070             if(Sensor.read_u16()>46000 && Sensor.read_u16()< 48000){
00071                 state = calib2;               
00072                 } 
00073                 
00074             if(Sensor.read_u16()>30000 && Sensor.read_u16()< 32000){
00075                 state = homing;                 
00076                 } 
00077                 
00078             if(Sensor.read_u16()>0 && Sensor.read_u16()< 10000){
00079                 lcd.printf("right", Sensor.read_u16());
00080             wait(1);        
00081             lcd.cls();                    
00082                 }  
00083                 
00084             else {
00085                 lcd.printf("Press to start", Sensor.read_u16());
00086             wait(1);        
00087             lcd.cls();
00088             }
00089 }
00090 /*
00091             if(Sensor.read_u16()>12000 && Sensor.read_u16()< 15000){
00092                lcd.printf("Procedure \n will start");
00093                tick.attach(&ticker, 2.0);                
00094                 } 
00095                 
00096             if(Sensor.read_u16()>46000 && Sensor.read_u16()< 48000){
00097                lcd.printf(" * left * ");
00098                wait(1);
00099                lcd.cls();                
00100                 } 
00101                 
00102             if(Sensor.read_u16()>30000 && Sensor.read_u16()< 32000){
00103                lcd.printf("  * down * ");
00104                wait(1);
00105                lcd.cls();                
00106                 } 
00107                 
00108             if(Sensor.read_u16()>0 && Sensor.read_u16()< 10000){
00109                lcd.printf("  * right * ");
00110                wait(1);
00111                lcd.cls();                       
00112                 }  
00113                 
00114             else {
00115                 lcd.printf("Press to start", Sensor.read_u16());
00116             wait(1);        
00117             lcd.cls();
00118             }*/
00119                    
00120                                         
00121         }
00122 
00123 
00124