Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 //estabelece a porta serial nucleo - pc 00004 Serial pc(D1, D0, 115200); //tx, rx, baud 00005 // estabelece a porta serial nucleo - display 00006 Serial display(D8, D2, 9600); //tx, rx, baud 00007 00008 DigitalOut led1(D13); 00009 00010 // Declaracao das funcoes 00011 void Rx_interrupt(); 00012 void SendText(char* page); //manda strings pela serial para o display 00013 void DisplayCircle(int x, int y); 00014 void DisplayProgressBar (int time); 00015 void DisplayXYZ(int x, int y, int z); 00016 00017 // declaracao de variaveis 00018 char rx_line; 00019 int estado = 0; 00020 int machine_xaxis_size = 1000; 00021 int machine_yaxis_size = 1000; 00022 int coleta_idx = 1; // indice do frasco atual (sendo selecionado) 00023 int volume = 0; // volume de trasferencia do frasco atual 00024 int tempo_dosagem = 2; // tempo real do ciclo em min 00025 00026 int x_percent; 00027 int y_percent; 00028 int z_percent; 00029 int x_relative; 00030 int y_relative; 00031 int x_cartesian; 00032 int y_cartesian; 00033 int z_cartesian; 00034 00035 00036 // main test program 00037 int main() { 00038 00039 // toda vez q chegar(Rx) info pela serial, execura a funcao interupt 00040 display.attach(&Rx_interrupt, Serial::RxIrq); 00041 00042 while(1) 00043 { 00044 00045 // --------- Tela 2 ------ acionada quando comeca a rotina de referenciamento 00046 // input 00047 while(estado == 2){ 00048 00049 SendText("t1.txt=\"REFERENCIANDO EIXO X ...\""); 00050 wait(2); 00051 // funcao q referencia o x 00052 00053 SendText("t1.txt=\"REFERENCIANDO EIXO Y ...\""); 00054 // funcao q referencia o y 00055 wait(2); 00056 00057 SendText("t1.txt=\"REFERENCIANDO EIXO Z ...\""); 00058 // funcao q referencia o z 00059 wait(2); 00060 00061 SendText("page 3"); 00062 estado = 3; 00063 } 00064 00065 00066 // ---------- Telas 4 ------- acionada quando comeca a rotina de Selecao da posicao de coleta 00067 // - coordenadas dos pontos-> passos do motor (n0, n1, n2) em tempo real 00068 // - desenhar o circulo na posicao de pega em tempo real 00069 while (estado == 4){ 00070 //CircleXY(x, y, "RED"); // cria um circulo na posicao x y passada 00071 DisplayCircle(500,500); 00072 DisplayXYZ(500, 500, 500); 00073 00074 } 00075 00076 // --------- Tela 6 --------- selecao das posicoes de trasferencia 00077 // - coordenadas do joy stick (n0, n1, n2) em tempo real 00078 // - desenhar o circulo na posicao de pega em tempo real 00079 // - mandar variavel volume (b2, b3) 00080 if (estado == 6){ 00081 char txt[100]; 00082 sprintf(txt,"n3.val=%d",coleta_idx); // coloca o indice da posicao de coelta no display 00083 pc.printf(txt); 00084 SendText(txt); 00085 } 00086 00087 while (estado == 6){ 00088 00089 DisplayCircle(500, 500); 00090 DisplayXYZ(500, 500, 500); 00091 00092 char txt[100]; 00093 sprintf(txt,"n4.val=%d",volume); // coloca o indice da posicao de coelta no display 00094 pc.printf(txt); 00095 SendText(txt); 00096 wait(1); 00097 00098 00099 } 00100 00101 00102 00103 // ------- Tela 8 ---------- dosagem 00104 while(estado == 8) { 00105 wait(3); 00106 SendText("page 9"); 00107 estado = 9; 00108 00109 00110 } 00111 00112 00113 // ------- Tela 9 ---------- fim 00114 00115 if (estado == 9) { 00116 char txt[50]; 00117 wait(2); 00118 sprintf(txt,"n0.val=%d",tempo_dosagem); 00119 pc.printf(txt); 00120 SendText(txt); 00121 } 00122 00123 00124 } 00125 00126 00127 } 00128 00129 00130 // definicao das funcoes 00131 00132 void Rx_interrupt() // funcao que recebe os outputs dos botoes do display 00133 { 00134 led1=1; 00135 while(display.readable()) 00136 00137 // Recebe o char do buffer usado pelo dispositivo "display" 00138 rx_line = display.getc(); 00139 // Manda o char pela serial PC 00140 pc.putc(rx_line); 00141 00142 switch(rx_line) 00143 { 00144 case 'z': 00145 SendText("page 1"); 00146 estado = 1; 00147 rx_line = 0x00; 00148 break; 00149 00150 case 'a': 00151 SendText("page 2"); 00152 estado = 2; 00153 rx_line = 0x00; 00154 break; 00155 00156 case 'v': 00157 rx_line = 0x00; 00158 estado = 0; 00159 break; 00160 00161 case 'b': 00162 SendText("page 4"); 00163 estado = 4; 00164 break; 00165 00166 case 'c': 00167 SendText("page 5"); 00168 estado = 5; 00169 break; 00170 00171 case 'd': 00172 SendText("page 6"); 00173 estado = 6; 00174 break; 00175 00176 case 'e': // Selecionar mais uma posicao de tranferencia 00177 SendText("page 6"); // recarrega a pagina -> zera os valores 00178 estado = 6; 00179 break; 00180 00181 case 'f': // Finalizar selecao das posicoes de tranferencia 00182 SendText("page 7"); // pagina pra comecar o processo de pipetagem 00183 estado = 7; 00184 break; 00185 00186 case 'g': // Aumenta 1ml no volume de transferencia 00187 volume ++; 00188 break; 00189 00190 case 'h': // Diminui 1ml no volume de transferencia 00191 volume --; 00192 break; 00193 00194 case 'i': // inicia a dosagem 00195 SendText("page 8"); // pagina pra comecar o processo de pipetagem 00196 estado=8; 00197 break; 00198 00199 case 'j': // Volta para intro_posicoinamento_pega 00200 SendText("page 3"); // pagina pra comecar o processo de pipetagem 00201 estado=3; 00202 break; 00203 00204 case 'k': // Volta para intro_dosagem 00205 SendText("page 7"); // pagina pra comecar o processo de pipetagem 00206 estado=7; 00207 break; 00208 00209 00210 default: rx_line=0x00; 00211 00212 00213 } 00214 led1=0; 00215 return; 00216 } 00217 00218 00219 00220 00221 void SendText(char* text){ 00222 00223 display.printf(text); 00224 display.putc(0xFF); 00225 display.putc(0xFF); 00226 display.putc(0xFF); 00227 wait(0.05); 00228 } 00229 00230 00231 void DisplayCircle(int x, int y){ 00232 char txt[100]; 00233 00234 x_percent = x/machine_xaxis_size; 00235 y_percent = y/machine_yaxis_size; 00236 00237 x_relative = x_percent*(500-250) + 250; 00238 y_relative = y_percent*(372-132) + 133; 00239 00240 sprintf(txt,"cirs %d,%d,5,RED", x_relative, y_relative); //??????????????????????????????????????????????????????? 00241 pc.printf(txt); 00242 SendText(txt); 00243 } 00244 00245 void DisplayXYZ(int x, int y, int z){ 00246 char txt[100]; 00247 x_percent = x/machine_xaxis_size; 00248 y_percent = y/machine_yaxis_size; 00249 y_percent = y/machine_yaxis_size; 00250 00251 00252 x_cartesian = x_percent*(10); 00253 y_cartesian = y_percent*(10); 00254 z_cartesian = z_percent*(10); 00255 00256 sprintf(txt,"n0.val=%d",x_cartesian); 00257 pc.printf(txt); 00258 SendText(txt); 00259 00260 sprintf(txt,"n1.val=%d",y_cartesian); 00261 pc.printf(txt); 00262 SendText(txt); 00263 00264 sprintf(txt,"n2.val=%d",z_cartesian); 00265 pc.printf(txt); 00266 SendText(txt); 00267 } 00268
Generated on Tue Aug 2 2022 17:31:04 by
1.7.2