├── .gitignore ├── LEIAME.md ├── LICENSE ├── README.md ├── arduino └── oscilloscope_arduino │ └── oscilloscope_arduino.ino ├── images ├── 0 - osciloscopio.bmp ├── 1 - Arduino UNO.jpg ├── 2 - garagino e conversor usb-serial.jpg ├── 4 - garaginoscopio_bb.jpg ├── 5 - multiplex analogico hcf4052be - cd4052.jpg ├── 6 - ler resistor e capacitor.jpg ├── 7 - programa processing.jpg ├── images.md ├── oscilloscope-en.png ├── oscilloscope-pt.png ├── oscilloscope-pwm-ondaQuadrada-pt.png ├── oscilloscope-pwm-squareWave-en.png ├── rog-000001381.jpg ├── rog-000005065.jpg └── uidades.png └── processing └── oscilloscope_4ch ├── Botao.pde ├── Canal.pde ├── CanalXYZ.pde ├── CheckBox.pde ├── Com.pde ├── Dial.pde ├── FmtNum.pde ├── Grupo.pde ├── Painel.pde ├── Tela.pde ├── TextBox.pde └── oscilloscope_4ch.pde /.gitignore: -------------------------------------------------------------------------------- 1 | application.linux-arm64/ 2 | application.linux64/ 3 | application.linux-armv6hf/ 4 | application.linux32/ 5 | application.windows64/ 6 | application.windows32/ 7 | data*.txt 8 | -------------------------------------------------------------------------------- /LEIAME.md: -------------------------------------------------------------------------------- 1 | # Osciloscópio com Arduino e Processing 2 | 3 | ### Descrição 4 | 5 | Osciloscópio de amostragem com 4 canais (tensões de 0 a 5V), com frequências até 3kHz. 6 | 7 | Possui um gerador de sinal PWM e uma saída de onda quadrada. 8 | 9 | Também pode, automaticamente, identificar o valor de resistor ou capacitor usando 3 escalas para melhor aproximação. 10 | 11 | Foi usado o microcontrolador Garagino, mas é totalmente compatível com o Arduino (www.arduino.cc). 12 | 13 | Usei a linguagem de programação "Processing" (www.processing.org) para criar o programa no computador. 14 | 15 | Veja uma [demonstração]( https://www.youtube.com/watch?v=aw_kyDAiNak) no youtube. 16 | 17 | 18 | ### Capacidades do Osciloscópio 19 | 20 | - Monitorar até 4 canais de tensão (0 a 5V). 21 | 22 | - Consegue mostrar frequências até 3kHz. 23 | 24 | - Estabiliza a onda na tela usando um "trigger" simples. 25 | 26 | - Identifica a frequência da onda usando o melhor critério (quadrada ou senoidal).. 27 | 28 | - Escalas: volts/divisão e tempo/divisão ajustadas individualmente para cada canal. 29 | 30 | - Ferramenta para medir tensão e tempo em cada canal. 31 | 32 | - Visualização combinada dos canais em XYZ. 33 | 34 | - Gerador de sinal PWM. 35 | 36 | - Medir valores de resistor ou capacitor em 3 escalas (automaticamente) 37 | 38 | 39 | ### Para quem não precisa ler valores de Resistores e Capacitores (sem componentes eletrônicos) 40 | 41 | Você pode ter as funções do osciloscópio, o sinal PWM e o gerador de Onda Quadrada, usando apenas os programas (sem alteração) e o Arduino. 42 | 43 | ![So Arduino e programas](./images/oscilloscope-pwm-ondaQuadrada-pt.png) 44 | 45 | 46 | 47 | ### Um pouco de história! (leitura opcional!) 48 | Eu soube da existência do Arduino no início de 2015 e fiquei impressionado com a facilidade de criarmos projetos tanto na montagem dos componentes quanto na digitação do código. (eu já havia feito um TCC no Senai usando o PIC16F877a e MikroC, então posso fazer essa afirmação com propriedade). 49 | 50 | Os Shields e as bibliotecas nos deixam livres dos códigos das entranhas do microcontrolador, e nos permite focar apenas na criação e funcionalidade do nosso projeto. 51 | 52 | E o melhor de tudo? É "Código Aberto"! 53 | 54 | Comprei o kit Arduino no LabdeGaragem e um livro sobre o assunto. Me diverti muito aprendendo e criando as experiências. 55 | 56 | Logo em seguida pensei que seria fácil criar um osciloscópio simples, pois eu estava precisando de um. 57 | 58 | Tentei usar o Visual Basic e o C++, com os quais tenho alguma familiaridade, mas não ficou bom o traçado das curvas na tela. 59 | 60 | Então em Abril de 2015 conheci o Processing, e percebi a facilidade e a capacidade para criar qualquer aplicativo. Foi o casamento perfeito! 61 | 62 | Em Julho de 2015 conclui a minha primeira versão do osciloscópio que chamei de Garaginoscópio, pois fiz com o Garagino, que iria ficar melhor por ser fisicamente menor. 63 | 64 | Com o tempo fui melhorando o layout e acrescentando novas funções, como um gerador de PWM e um medidor de resistor e capacitor. 65 | 66 |   67 | ### O Osciloscópio 68 | 69 | [![Imagem do Osciloscopio](./images/0%20-%20osciloscopio.bmp)](https://www.youtube.com/watch?v=aw_kyDAiNak) 70 | 71 | ![Imagem do Osciloscopio](./images/rog-000005065.jpg) 72 | 73 | 74 | ### O circuito no Arduino 75 | 76 | ![Imagem do Osciloscopio](./images/oscilloscope-pt.png ) 77 | 78 | ### O circuito no Garagino 79 | 80 | ![Imagem do Osciloscopio](./images/4%20-%20garaginoscopio_bb.jpg ) 81 | 82 | 83 | ### O circuito de leitura do resistor e capacitor 84 | 85 | ![Imagem do Osciloscopio](./images/6%20-%20ler%20resistor%20e%20capacitor.jpg) 86 | 87 | ### O CI 74HC4052 (multiplexador analógico) 88 | 89 | ![Imagem do Osciloscopio](./images/5%20-%20multiplex%20analogico%20hcf4052be%20-%20cd4052.jpg) 90 | 91 | ### O programa em Processing 92 | 93 | ![Imagem do Osciloscopio](./images/7%20-%20programa%20processing.jpg) 94 | 95 | ### Melhorias para o futuro 96 | 97 | - Medir tensões 110/220 Vac 98 | 99 | - Aumentar a capacidade da frequência usando microcontroladores mais poderosos. 100 | 101 | - Usar conexão bluetooth para conectar o osciloscópio ao celular (Android) 102 | 103 | ### Finalizando 104 | 105 | Eu gostei muito de desenvolver os programas e o hardware do osciloscópio. 106 | 107 | Acredito que ele tenha um ótimo potencial para um produto mais profissional. 108 | 109 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 rogeriobego 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Oscilloscope using Arduino and Processing 2 | 3 | ### Description 4 | 5 | Sampling oscilloscope with 4 channels (voltages from 0 to 5V), with frequencies up to 3kHz. 6 | 7 | It has a PWM signal generator and a square wave output. 8 | 9 | It can also automatically identify the resistor or capacitor value using 3 scales for better approximation. 10 | 11 | The Garagino microcontroller was used, but it is fully compatible with the Arduino (www.arduino.cc). 12 | 13 | I used the programming language "Processing" (www.processing.org) to create the program on the computer. 14 | 15 | See a [demo] (https://www.youtube.com/watch?v=aw_kyDAiNak) on youtube. 16 | 17 | 18 | ### Oscilloscope Capabilities 19 | 20 | - Monitor up to 4 voltage channels (0 to 5V). 21 | 22 | - Can display frequencies up to 3kHz. 23 | 24 | - Stabilizes the wave on the screen using a simple trigger. 25 | 26 | - Identify the frequency of the wave using the best criterion (square or sinusoidal). 27 | 28 | - Scales: volts / division and time / division adjusted individually for each channel. 29 | 30 | - Tool to measure voltage and time in each channel. 31 | 32 | - Combined display of channels in XYZ. 33 | 34 | - PWM signal generator. 35 | 36 | - Measure resistor or capacitor values on 3 scales (automatically) 37 | 38 | 39 | ### For those who do not need to read values of Resistors and Capacitors (without electronic components) 40 | 41 | You can have the oscilloscope functions, the PWM signal, and the Square Wave generator using only the programs (unchanged) and the Arduino. 42 | 43 | ![Only Arduino and programs](./images/oscilloscope-pwm-squareWave-en.png ) 44 | 45 | 46 | ### The Oscilloscope 47 | 48 | [![Imagem do Osciloscopio](./images/0%20-%20osciloscopio.bmp)](https://www.youtube.com/watch?v=aw_kyDAiNak) 49 | 50 | ![Imagem do Osciloscopio](./images/rog-000005065.jpg) 51 | 52 | 53 | ### The circuit using Arduino 54 | 55 | ![Imagem do Osciloscopio](./images/oscilloscope-en.png ) 56 | 57 | ### The circuit using Garagino 58 | 59 | ![Imagem do Osciloscopio](./images/4%20-%20garaginoscopio_bb.jpg ) 60 | 61 | 62 | ### The resistor and capacitor reading circuit 63 | 64 | ![Imagem do Osciloscopio](./images/6%20-%20ler%20resistor%20e%20capacitor.jpg) 65 | 66 | ### The 74HC4052 CI (analog multiplexer) 67 | 68 | ![Imagem do Osciloscopio](./images/5%20-%20multiplex%20analogico%20hcf4052be%20-%20cd4052.jpg) 69 | 70 | ### The Processing program 71 | 72 | ![Imagem do Osciloscopio](./images/7%20-%20programa%20processing.jpg) 73 | 74 | ### Improvements for the future 75 | 76 | - Measuring voltages 110/220 Vac 77 | 78 | - Increase frequency capacity using more powerful microcontrollers. 79 | 80 | - Use bluetooth connection to connect oscilloscope to mobile phone (Android) 81 | 82 | ### Finishing 83 | 84 | I really enjoyed developing oscilloscope programs and hardware. 85 | 86 | I believe it has great potential for a more professional product. 87 | 88 | -------------------------------------------------------------------------------- /arduino/oscilloscope_arduino/oscilloscope_arduino.ino: -------------------------------------------------------------------------------- 1 | // 28/05/2017 => bug v1.5 => qdo aumenta 1 canal dá erro na serial (disabling serial) 2 | // 22/05/2017 => versão 1.5 => dynamic buffer - 1ch=400pt/ch, 2chs=200pt/ch, 3chs=130pt/ch, 4chs=100pt/ch 3 | // 21/01/2017 => versão 1.4 => melhorar o trigger: informar valor e sentido (subindo/descendo) 4 | // 13/03/2016 => versão 1.3 => alterar o clock do ADC para ler maiores frequencias 5 | // 14/09/2015 => implementei TimerOne.h pin9(pwm) e pino10(2*periodo) output 6 | // 03/08/2016 => versão 1.2 => ler resistor em A5 7 | // 26/07/2015 => versão 1.1 => ler em microsegundos 8 | //String versao="1.2"; // versão do programa - 9 | #define versao "v1.5" 10 | 11 | /* trabalhando com TimerOne 12 | Timer1.initializa(us); // inicializa o timer1 (chamar primeiro) 13 | Timer1.setPeriodo(us); // new period 14 | Timer1.start(); // 15 | Timer1.stop(); 16 | Timer1.restart(); 17 | Timer1.resume(); 18 | Timer1.pwm(pin,duty); pin 9 ou 10, dute(0-1023) (usar primeiro no pwm) 19 | Timer1.setPwmDuty(pin,duty); //reconfigura o pwm 20 | Timer1.disablePwm(pin); //stop using pwm on a pin. (volta para o digitalWrite()) 21 | Timer1.attachInterrupt(function);// roda a função como uma interrupção então usar "volatile" no nome de variaveis 22 | Timer1.detachInterrupt();// 23 | noInterrupts(); 24 | blinkCopy=blinkCount; // desliga a interrupção para passar a variavel volatile 25 | interrupts(); 26 | 27 | */ 28 | 29 | 30 | #include 31 | 32 | //--- constantepara configuração do prescaler ====== 33 | // vou usar o PS_16 34 | const unsigned char PS_16 = (1 << ADPS2); 35 | const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0); 36 | const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1); 37 | const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); 38 | // configurar no setup: ADC 39 | //====================================== 40 | 41 | boolean pwmOn=true; 42 | unsigned long pwmP=20000; //Periodo 20000us=20ms=0.02s => 50Hz 43 | byte pwmPon=25; // % do pwmP em HIGH 44 | 45 | /* -- 07/May/2017 -- 46 | int v0[100]; 47 | int v1[100]; 48 | int v2[100]; // guarda os valores das leituras 49 | int v3[100]; // acrescentei mais um canal em 15/10/2015 50 | */ 51 | /* ------------------------------------------------ 52 | /* I changed the 4 buffers (v0[100],v1[],v2[],v3[]) above 53 | * by 1 buffer bellow (vb[408]) 54 | * The chq indicates how many channels will use and the buffer 55 | * will be divided by then: 56 | * 4 ch (q=102) => 0-101, 102-203, 204-305, 306-407 57 | * 3 ch (q=136) => 0-135, 136-271, 272-407 58 | * 2 ch (q=204) => 0-203, 204-407 59 | * 1 ch (q=408) => 0-407 60 | * chi[n] indicates the initial position of the buffer 61 | * q indicates the size of channel buffer 62 | ------------------------------------------------ 63 | */ 64 | int vb[400]; // (100*4=400) buffer stores the measure values of all channels 65 | // (old) int chi[]={0,102,204,306}; // channel init position on buffer vb[] 66 | int chi[]={0,100,200,300}; // channel init position on buffer vb[] 67 | int chq=4; // how many channels are ON 68 | int q=100; // quantidade de leituras 69 | int qmax=100; // qtd maxima permitida para q 70 | // (new) chq-qmax; 4-100; 3-130; 2-200; 1-400 71 | // (old) chq-qmax; 4-102; 3-136; 2-204; 1-408 72 | int vtrigger=0; // tensao de trigger 73 | boolean Ch[]={true,true,true,true}; // ativa/desativa canais 74 | unsigned int dt=4; // 100us a 1000us(1ms) a 3000ms(3s) 75 | char unidade='m'; // unidade: m=milisegundo, u=microsegundo 76 | 77 | // obs: para leitura dos 3 canais o tempo mínimo é 380us 78 | // obs: para leitura dos 4 canais o tempo mínimo é 500us 79 | // 1 canal deve dar 120us 80 | 81 | boolean varias=false; // v = varias 82 | boolean uma=false; // u = uma 83 | boolean fluxo=false; // f = fluxo de dados (envia cada leitura sem guardar na memoria) 84 | // velocidade limitada pela serial 115200 85 | unsigned long dtReal, tIni, tFim; // contador de final de tempo para o fluxo 86 | char canalTrigger='x'; // de '0','1','2','3' (canal do trigger), 'x'=não tem trigger 87 | 88 | 89 | //--------------- Ler Resistor/Capacitor --------- 90 | boolean lerRC=false; 91 | #define pinV 5 92 | #define pinA 7 // pino A 10 multiplex 93 | #define pinB 8 // pino B 9 multiplex 94 | byte entrada=0; 95 | int vi, vf, v; 96 | //float rx=0, cx=0; 97 | //float r[]={0.0,200.0,20000.0,1000000.0}; 98 | //float re[]={0.0,145.2,20692.9,1017847.5}; 99 | //float vcc[]={0,871.5,1026.3,1027.1}; 100 | unsigned long dtRC=0; 101 | char unidadeRC=' '; 102 | boolean debug=true; 103 | 104 | void setup() { 105 | 106 | //---------- configura o preescaler do ADC ====== 107 | ADCSRA &= ~PS_128; //limpa configuração da biblioteca do arduino 108 | 109 | // valores possiveis de prescaler só deixar a linha com prescaler desejado 110 | // PS_16, PS_32, PS_64 or PS_128 111 | //ADCSRA |= PS_128; // 64 prescaler 112 | // ADCSRA |= PS_64; // 64 prescaler 113 | // ADCSRA |= PS_32; // 32 prescaler 114 | ADCSRA |= PS_16; // 16 prescaler 115 | //================================================= 116 | 117 | //definir Timer1 pwm(pino9) e pino10 para monitorar freq 118 | pinMode(10,OUTPUT); 119 | //vou inicializar com 10Hz (100ms=100000us) 120 | Timer1.initialize(pwmP); //100000us=100ms=>10Hz 121 | Timer1.pwm(9,map(pwmPon,0,100,0,1023)); //pwm no pino9 com 25% duty cycle 122 | Timer1.attachInterrupt(callback); //attaches callback() como timer overflow interrupt 123 | //Timer1.stop(); 124 | 125 | //inicializar A0, A1, A2, A3 com pull_up 126 | // não ficou bom pois qdo não tem nada conectado na porta, ela fica 127 | // com 5v. O melhor é colocar um pull_down com resistor 128 | // A0___|R=20k|___GND 129 | // |__ Vinput 130 | /* 131 | * pinMode(A0,INPUT_PULLUP); 132 | * pinMode(A1,INPUT_PULLUP); 133 | * pinMode(A2,INPUT_PULLUP); 134 | * pinMode(A3,INPUT_PULLUP); 135 | */ 136 | 137 | //Serial.begin(9600); 138 | Serial.begin(115200); 139 | //Serial.begin(250000); 140 | Serial.println(); 141 | Serial.print(">init="); Serial.println(versao); 142 | //printHelp(); 143 | //printConfig(); 144 | 145 | //ler Resistor e Capacitor 146 | //pinMode(pinCarga,OUTPUT); 147 | //digitalWrite(pinCarga,LOW); 148 | pinMode(pinA,OUTPUT); 149 | pinMode(pinB,OUTPUT); 150 | selecionar(0); 151 | } 152 | 153 | void callback(){ 154 | digitalWrite(10,digitalRead(10)^1); // ^1 = xor (0->1, 1->0) 155 | } 156 | 157 | void loop() { 158 | lerSerial(); 159 | if (varias) { 160 | lerEnviar(); 161 | } else if (uma) { 162 | if (canalTrigger=='x'){ 163 | lerEnviar(); 164 | uma=false; 165 | } else { 166 | if (trigger()){ 167 | lerEnviar(); 168 | uma=false; 169 | } 170 | } 171 | } else if (fluxo) { 172 | lerFluxo(); 173 | } 174 | if (lerRC){ 175 | if (millis()>=dtRC){ 176 | lerResistorCapacitor(); 177 | dtRC=millis()+3000; 178 | } 179 | } 180 | } 181 | 182 | void lerSerial(){ 183 | int k; 184 | float kf; 185 | char c, c2; 186 | if (Serial.available()>0){ 187 | c=Serial.read(); 188 | switch (c){ 189 | case 'h': // enviar help pela serial 190 | printHelp(); 191 | break; 192 | case 'd': //alterar o valor de dt (us/ms) 193 | k=Serial.parseInt(); // como e inteiro então vai de 0 a 32767 (parseint limita 16bits) 194 | if (k>=1 && k<=30000) {//28/08/15 deve ser dtmin=400us(3canais) dtmax=30000 195 | dt=k; 196 | } 197 | c=Serial.read(); 198 | if (c=='u' || c=='m'){ 199 | unidade=c; 200 | } else { // sem unidade é segundo, então converter para mili (x1000)m 201 | unidade='m'; 202 | dt*=1000; 203 | } 204 | // Serial.print("=> dt="); Serial.print(dt); Serial.print(unidade); Serial.println("s"); 205 | break; 206 | case 'q': // alterar valor do q.(ponto no final) (quantidade de leituras) 207 | k=Serial.parseInt(); // inteiro de 0 a 32767 208 | c=Serial.read(); // para ir mais rápido colocar um . no final ex: q150. 209 | if (k>=1 && k<=qmax) { 210 | q=k; 211 | } 212 | //calcBuffer(); //não precisa pois será usado o qmax 213 | Serial.print("=> q="); Serial.println(q); 214 | break; 215 | case 'c': //cnm : n=0-3, m=(o)ativa/(x)desativa canal n exemplo: c0x, c2o 216 | delay(100); 217 | c=Serial.read(); 218 | delay(100); 219 | c2=Serial.read(); 220 | if (c>='0' && c<='3'){ 221 | if (c2=='o'){ 222 | Ch[c-'0']=true; 223 | }else if (c2=='x'){ 224 | Ch[c-'0']=false; 225 | } 226 | // recalcular o buffer para cada canal e colocar o indice 227 | // inicial para cada canal 228 | //Serial.println("entrar calcBuffer"); 229 | calcBuffer(); 230 | //Serial.println("saiu calcBuffer"); 231 | /* Serial.print("=> Canais: "); 232 | for (k=0; k<3;k++){ 233 | Serial.print("Ch"); Serial.print(k); Serial.print("="); Serial.print(Ch[k]); 234 | } 235 | Serial.println(); 236 | */ 237 | } 238 | break; 239 | case 't': // trigger: t(canal) 240 | // trigger: t0, t1, t2, t3 241 | // tx desligado 242 | // tv512. valor da tensão 0-1024 (5v) 243 | delay(100); 244 | c=Serial.read(); 245 | if ((c>='0' && c<='3') || c=='x'){ 246 | canalTrigger=c; 247 | } else if (c=='v'){ 248 | k=Serial.parseInt(); 249 | c=Serial.read(); 250 | if (k>=0 && k<=1024) { 251 | vtrigger=k; 252 | } 253 | } 254 | 255 | // Serial.print("=> canalTrigger="); Serial.println(canalTrigger); 256 | break; 257 | case '?': 258 | printConfig(); 259 | break; 260 | case '1': // enviar Uma Amostra (q leituras) 261 | if (!uma) uma=true; 262 | if (uma){ 263 | varias=false; 264 | fluxo=false; 265 | } 266 | // Serial.print("=> uma="); Serial.println(uma); 267 | break; 268 | case 'v': // o(on)/x(off) - enviar Varias Amostras (q leituras cada) 269 | delay(100); 270 | c=Serial.read(); 271 | if (c=='o') { 272 | varias=true; 273 | } else { 274 | varias=false; 275 | } 276 | if (varias){ 277 | uma=false; 278 | fluxo=false; 279 | } 280 | // Serial.print("=> varias="); Serial.println(varias); 281 | break; 282 | case 'f': // o(on)/x(off) - enviar Fluxo (ler e enviar - nao armazenar) 283 | delay(100); 284 | c=Serial.read(); 285 | if (c=='o') { 286 | fluxo=true; 287 | } else { 288 | fluxo=false; 289 | } 290 | if (fluxo){ 291 | varias=false; 292 | uma=false; 293 | if (unidade=='u'){ // microsegundo 294 | tIni=micros(); tFim=tIni+dt; 295 | } else{ // milisegundo 296 | tIni=millis(); tFim=tIni+dt; 297 | } 298 | } 299 | // Serial.print("=> fluxo="); Serial.println(fluxo); 300 | break; 301 | case 'r': // (on/off) - enviar valor lido do Resistor em A5 302 | delay(100); 303 | c=Serial.read(); 304 | if (c=='o') { 305 | lerRC=true; 306 | } else { 307 | lerRC=false; 308 | } 309 | // Serial.print("=> lerRC="); Serial.println(lerRC); 310 | dtRC=0; 311 | break; 312 | case 's': // Sinal: Ligar/desligar Gerador de Sinal 313 | delay(100); 314 | c=Serial.read(); 315 | if (c=='o'){ 316 | Timer1.restart(); // zera o contador 317 | Timer1.start(); //inicio 318 | // Serial.println("Timer1 restart/start"); 319 | }else{ 320 | Timer1.stop(); 321 | // Serial.println("Timer1.stop()"); 322 | } 323 | break; 324 | case 'p': // Sinal: alterar Período ex: p100m p343u 325 | kf=Serial.parseFloat(); 326 | if (kf>0){ 327 | c=Serial.read(); // ler unidade e converter para micro 328 | // Serial.print(">>kf="); Serial.print(kf); Serial.print(" c="); Serial.println(c); 329 | switch (c){ 330 | case 'u': //já está em micro (u) 331 | pwmP=long(kf); 332 | break; 333 | case 'm': // está em mili (m) então converter para micro (u) 334 | pwmP=long(kf*1000.0); 335 | // Serial.print("kf="); Serial.print(kf); Serial.print("m"); Serial.print(" pwmP=kf*1000="); Serial.println(pwmP); 336 | break; 337 | case ' ': // está em segundo ( ) então converter para micro (u) 338 | pwmP=long(kf*1000000.0); 339 | break; 340 | default: // se veio caracter desconhecido faço o pwmP=1s 341 | pwmP=1000000l; // coloquei L no final do 100000 para dizer que é long 342 | // Serial.print("=> erro unidade pwmP, usando padrao(us)="); Serial.println(1000000); 343 | break; 344 | } 345 | Timer1.setPeriod(pwmP); 346 | Timer1.setPwmDuty(9,map(pwmPon,0,100,0,1023)); 347 | // Serial.print("=> setPeriod="); Serial.println(pwmP); 348 | } 349 | break; 350 | case 'o': // Sinal: alterar tempo em ON ex: o25% o50% 351 | k=int(Serial.parseFloat()); 352 | c=Serial.read(); // só ler a % e desprezar (faz o parseInt ficar mais rapido 353 | if (k>=0 && k<=100){ 354 | pwmPon=k; 355 | Timer1.setPwmDuty(9,map(pwmPon,0,100,0,1023)); 356 | // Serial.print("=> pwm on="); Serial.print(k); Serial.println("%"); 357 | } 358 | break; 359 | default: 360 | Serial.print("erro c="); Serial.println(c,HEX); 361 | } 362 | } 363 | } 364 | 365 | void calcBuffer(){ 366 | //Serial.println("entrou calcBuffer"); 367 | chq=0; 368 | // conta a quantidade de canais ativos 369 | for (int k=0;k<4;k++){ 370 | if (Ch[k]) {chq+=1;} 371 | } 372 | // calc size of each channel 373 | switch (chq){ 374 | case 0: 375 | qmax=0; 376 | break; 377 | case 1: 378 | qmax=400; 379 | break; 380 | case 2: 381 | qmax=200; 382 | break; 383 | case 3: 384 | qmax=130; 385 | break; 386 | case 4: 387 | qmax=100; 388 | break; 389 | } 390 | /* 391 | if (chq<=0) { 392 | qmax=0; 393 | } else { 394 | qmax=408/chq; // chq-qmax; 4-102; 3-136; 2-204; 1-408 395 | } 396 | */ 397 | if (q>qmax) { 398 | q=qmax; 399 | } 400 | //Serial.print("q=408/chq=");Serial.print("408/");Serial.print(chq);Serial.print("=");Serial.println(q); 401 | // qtdCanais-qmax (chq-qmax) (4-100) (3-130) (2-200) (1-400) 402 | int chInit=0; 403 | for (int k=0; k<4; k++){ 404 | if (Ch[k]) { 405 | chi[k]=chInit; 406 | chInit+=qmax; 407 | } 408 | } 409 | 410 | // Serial.print("chq="); Serial.print(chq); Serial.print(" q="); Serial.print(q); Serial.print(" qmax="); Serial.println(qmax); 411 | // for (int k=0; k<4; k++){ 412 | // Serial.print("k=");Serial.print(k); Serial.print(" chi[k]="); Serial.println(chi[k]); 413 | // } 414 | 415 | } 416 | 417 | void printHelp(){ 418 | Serial.println("-----------------------"); 419 | Serial.print("! BegOscopio "); Serial.print(versao); Serial.println(" - rogerio.bego@hotmail.com !"); 420 | Serial.println("-----------------------"); 421 | /* 422 | Serial.println("----------- help ---------------------"); 423 | Serial.println(" h : help"); 424 | Serial.println(" ? : exibir as configuracoes atuais"); 425 | Serial.println(" -------- controle da amostragem ------"); 426 | Serial.println(" d___ : d[1-3000][un] - ex: d100m, d200u - dt = intervalo de tempo (us/ms) entre as leituras"); 427 | Serial.println(" q___ : q[1-100]. - qtd de leituras"); 428 | Serial.println(" cn_ : (o)ativa,(x)desativa canal: ex: c2o (ativar Ch2), c0x (desativar Ch0)"); 429 | Serial.println(" t_ : 0,1,2,3(canal),x(off) "); 430 | Serial.println(" tv__ : tv512. valor da tensao 0-1024 (0-5v)"); 431 | Serial.println(" -------- envio das amostras ---------"); 432 | Serial.println(" 1 : enviar uma amostra"); 433 | Serial.println(" v_ : o(on),x(off) enviar varias amostras"); 434 | Serial.println(" f_ : o(on),x(off) enviar fluxo de dados"); 435 | Serial.println(" obs: 1, v, f sao mutuamente excludentes"); 436 | Serial.println(" -------- leitura de Resistor ou Capacitor ----"); 437 | Serial.println(" r_ : o(on),x(off) ler Resistor ou Capacitor"); 438 | Serial.println(" -------- Gerador de Sinal pwm ---------"); 439 | Serial.println(" s_ : o(on),x(off) ativa Ger.Sinal (pwm na porta 9) (porta 10 indica 2*T)"); 440 | Serial.println(" p_ : p[valor][unidade] periodo do sinal de 100u a 8s"); 441 | Serial.println(" o_ : o[0-100][%] Ton em porcentagem"); 442 | Serial.println("----------------------------------------"); 443 | */ 444 | } 445 | 446 | 447 | 448 | void printConfig(){ 449 | Serial.println("------ configuracoes -------"); 450 | Serial.print(">? q="); Serial.println(q); 451 | Serial.print(">? qmax="); Serial.println(qmax); 452 | Serial.print(">? dt="); Serial.print(dt); Serial.print(unidade); Serial.println("s"); 453 | float t=(float)q * (float)dt; 454 | Serial.print(" -> T=(q*dt)= "); Serial.print(t); Serial.print(unidade); Serial.println("s "); 455 | Serial.print(">? Canais: "); 456 | for (int k=0; k<4; k++){ 457 | Serial.print(" Ch"); Serial.print(k); Serial.print("="); 458 | if (Ch[k]) { 459 | Serial.print("o"); 460 | } else { 461 | Serial.print("x"); 462 | } 463 | } 464 | Serial.println(); 465 | Serial.print(">? canalTrigger="); Serial.println(canalTrigger); 466 | Serial.print(">? uma="); Serial.println(uma); 467 | Serial.print(">? varias="); Serial.println(varias); 468 | Serial.print(">? fluxo="); Serial.println(fluxo); 469 | Serial.print(">? lerRC="); Serial.println(lerRC); 470 | Serial.print(">? pwmOn="); Serial.println(pwmOn); 471 | Serial.print(">? pwmP="); Serial.print(pwmP); Serial.println("us"); 472 | Serial.print(">? pwmPon="); Serial.print(pwmPon); Serial.println("%"); 473 | } 474 | 475 | 476 | unsigned long microsOuMillis(){ 477 | if (unidade=='u'){ 478 | return micros(); 479 | } else { 480 | return millis(); 481 | } 482 | } 483 | 484 | //-- procurar tensão maior que zero no canalTrigger ---- 485 | //-- se UMA=true então fica aguardando indefinitivamente 486 | //-- se UMA=false então fica aguardando até o tempo tFIM (q*dt) 487 | boolean trigger(){ // a variavel canalTrigger indica qual canal fará o trigger: 0,1,2 ou 3 488 | unsigned long tFim; // contador do tempo Final 489 | int v1=0,v2=0; 490 | //int c1=0, c2=0; 491 | boolean achou=false; 492 | tFim=microsOuMillis()+q*dt; 493 | // dispara na subida do valor vtrigger+10 494 | //fica lendo a tensão enquanto for maior que vtrigger 495 | // E tempo menor que tFim 496 | do{ 497 | v1=analogRead(canalTrigger-'0'); 498 | //c1++; 499 | }while (v1>vtrigger && microsOuMillis()0 && microsOuMillis()10+vtrigger){ 511 | achou=true; 512 | } 513 | //Serial.print("v1="); Serial.print(v1); Serial.print(" v2=");Serial.println(v2); 514 | //Serial.print("c1=");Serial.print(c1);Serial.print(" c2=");Serial.println(c2); 515 | } 516 | return achou; 517 | } 518 | 519 | 520 | void lerEnviar(){ 521 | 522 | /* 523 | // enviar quais canais serao enviados. ex: >ch=1<\t>3<\t> 524 | Serial.print(">chq="); Serial.print(chq); Serial.print("\t"); 525 | for (int k=0; k<4; k++){ 526 | if (Ch[k]){Serial.print(k); Serial.print("\t");} 527 | } 528 | Serial.println(""); 529 | 530 | //enviar os valores dos canais 531 | for (int k=0; kv="); Serial.print(k); Serial.print("\t"); 533 | if (Ch[0]) {Serial.print(chi[0]+k); Serial.print("\t");} 534 | if (Ch[1]) {Serial.print(chi[1]+k); Serial.print("\t");} 535 | if (Ch[2]) {Serial.print(chi[2]+k); Serial.print("\t");} 536 | if (Ch[3]) {Serial.print(chi[3]+k); Serial.print("\t");} 537 | Serial.println(""); 538 | } 539 | 540 | 541 | return; 542 | 543 | */ 544 | 545 | 546 | unsigned long tFim; // contador do tempo Final 547 | unsigned long tTotalReal; // tempo Total da leitura dos valores. 548 | if (canalTrigger>='0' && canalTrigger<='3'){ 549 | //Serial.print("canalTrigger=");Serial.println(canalTrigger); 550 | Serial.print("trigger="); Serial.println(trigger()); 551 | } 552 | tTotalReal=microsOuMillis(); 553 | 554 | for (int k=0; kq="); Serial.println(q); 575 | Serial.print(">dt="); Serial.print(dt); Serial.print(unidade); Serial.println("s"); 576 | Serial.print(">dtReal="); Serial.print(dtReal); // Serial.print(unidade); Serial.println("s"); 577 | if (unidade=='m'){ 578 | Serial.println("e-3"); 579 | }else if (unidade=='u'){ 580 | Serial.println("e-6"); 581 | } 582 | 583 | // enviar quais canais serao enviados. ex: >ch=1<\t>3<\t> 584 | Serial.print(">chq="); Serial.print(chq); Serial.print("\t"); 585 | for (int k=0; k<4; k++){ 586 | if (Ch[k]){Serial.print(k); Serial.print("\t");} 587 | } 588 | Serial.println(""); 589 | 590 | //enviar os valores dos canais 591 | for (int k=0; kv="); Serial.print(k); Serial.print("\t"); 593 | if (Ch[0]) {Serial.print(vb[chi[0]+k]); Serial.print("\t");} 594 | if (Ch[1]) {Serial.print(vb[chi[1]+k]); Serial.print("\t");} 595 | if (Ch[2]) {Serial.print(vb[chi[2]+k]); Serial.print("\t");} 596 | if (Ch[3]) {Serial.print(vb[chi[3]+k]); Serial.print("\t");} 597 | Serial.println(""); 598 | 599 | /* 600 | if (Ch[0]) {Serial.print(chi[0]+k); Serial.print("\t");} 601 | if (Ch[1]) {Serial.print(chi[1]+k); Serial.print("\t");} 602 | if (Ch[2]) {Serial.print(chi[2]+k); Serial.print("\t");} 603 | if (Ch[3]) {Serial.print(chi[3]+k); Serial.print("\t");} 604 | Serial.println(""); 605 | */ 606 | } 607 | /* -- eliminado em 07/May/2017 - criei buffer dinamico vb[408] -- 608 | for (int k=0; kv="); 610 | Serial.print(k); Serial.print("\t"); 611 | Serial.print(v0[k]); Serial.print("\t"); 612 | Serial.print(v1[k]); Serial.print("\t"); 613 | Serial.print(v2[k]); Serial.print("\t"); 614 | Serial.println(v3[k]); 615 | } 616 | */ 617 | Serial.print(">tTotalReal="); Serial.print(tTotalReal); //Serial.print(unidade); Serial.println("s"); 618 | if (unidade=='m'){ 619 | Serial.println("e-3"); 620 | }else if (unidade=='u'){ 621 | Serial.println("e-6"); 622 | } 623 | } 624 | 625 | void lerFluxo(){ 626 | int v0, v1, v2, v3; // guarda os valores das leituras 627 | //byte v0, v1, v2, v3; // guarda os valores das leituras 628 | boolean leu=false; 629 | if (microsOuMillis()>=tFim){ 630 | dtReal=microsOuMillis()-tIni; 631 | tIni=microsOuMillis(); tFim=tIni+dt; 632 | if (Ch[0]) {v0=analogRead(A0);} 633 | if (Ch[1]) {v1=analogRead(A1);} 634 | if (Ch[2]) {v2=analogRead(A2);} 635 | if (Ch[3]) {v3=analogRead(A3);} 636 | //if (Ch[0]) {v0=analogRead(A0)/4;} 637 | //if (Ch[1]) {v1=analogRead(A1)/4;} 638 | //if (Ch[2]) {v2=analogRead(A2)/4;} 639 | //if (Ch[3]) {v3=analogRead(A3)/4;} 640 | leu=true; 641 | } 642 | if (leu){ 643 | Serial.print(">f="); 644 | Serial.print("0"); Serial.print("\t"); 645 | Serial.print(dtReal); 646 | if (unidade=='m'){ 647 | Serial.print("e-3"); 648 | }else if (unidade=='u'){ 649 | Serial.print("e-6"); 650 | } 651 | Serial.print("\t"); 652 | if (Ch[0]) {Serial.print(v0);} else {Serial.print("0");} Serial.print("\t"); 653 | if (Ch[1]) {Serial.print(v1);} else {Serial.print("0");} Serial.print("\t"); 654 | if (Ch[2]) {Serial.print(v2);} else {Serial.print("0");} Serial.print("\t"); 655 | if (Ch[3]) {Serial.println(v3);} else {Serial.println("0");} 656 | } 657 | } 658 | 659 | //=========== Rotinas para leitura de Resistor e Capacitor =========== 660 | 661 | void lerResistorCapacitor(){ 662 | descarregar(); 663 | lerEntrada(1); 664 | if (vf-vi>=100) {// e' capacitor 665 | calcCapacitor(); 666 | } else { 667 | if (v<900) { // calcular valor do resistor 668 | calcRx(); 669 | } else { // subir selecionar 2 670 | // descarregar se for capacitor 671 | descarregar(); 672 | lerEntrada(2); 673 | if (vf-vi>=100) { // capacitor - escala 2 674 | calcCapacitor(); 675 | } else { // resistor 676 | if (v<900){ // calcular valor do resistor 677 | calcRx(); 678 | } else { // subir selecionar 3 (nao consegue detectar capacitor corretamente) 679 | lerEntrada(3); 680 | if (v<900){ 681 | calcRx(); 682 | } else { 683 | Serial.println(">rc=3\tColoque RC"); 684 | } 685 | } 686 | } 687 | } 688 | } 689 | } 690 | 691 | void calcCapacitor(){ 692 | float re[]={0.0,145.2,20692.9,1017847.5}; 693 | float cx=0; 694 | descarregar(); 695 | selecionar(1); 696 | dtRC=millis(); 697 | while (analogRead(pinV)<647){} // 647 = 63.2% Vcc => (nessa voltagem t=rc) 698 | dtRC=millis()-dtRC; 699 | if (dtRC>=100) { // dentro da faixa Cx>1mF 700 | cx=(float)dtRC/re[entrada]; 701 | unidadeRC='m'; //resultado em mF 702 | } else { // fora da faixa, subir para escala 2 703 | descarregar(); 704 | selecionar(2); 705 | dtRC=millis(); 706 | while (analogRead(pinV)<647){} 707 | dtRC=millis()-dtRC; 708 | if (dtRC>=10) { // dentro da faixa 709 | cx=(float)dtRC*1000.0/re[entrada]; 710 | unidadeRC='u'; // resultado em uF 711 | } else { // fora da faixa, então subir escala 712 | descarregar(); 713 | selecionar(3); 714 | dtRC=millis(); 715 | while (analogRead(pinV)<647){} 716 | dtRC=millis()-dtRC; 717 | cx=(float)dtRC*1000000.0/re[entrada]; 718 | unidadeRC='n'; // resultado em nF 719 | } 720 | } 721 | Serial.print(">c="); Serial.print(entrada); Serial.print("\t"); Serial.print(cx); Serial.print(" "); Serial.print(unidadeRC); Serial.println("F"); 722 | } 723 | 724 | void lerEntrada(byte e){ 725 | selecionar(e); 726 | dtRC=micros(); 727 | vi=analogRead(pinV); 728 | v=0; 729 | for (int k=0; k<10; k++){ 730 | v+=analogRead(pinV); 731 | } 732 | v/=10; 733 | vf=analogRead(pinV); 734 | dtRC=micros()-dtRC; 735 | } 736 | 737 | void descarregar(){ 738 | selecionar(0); 739 | while (analogRead(pinV)>0){} 740 | } 741 | 742 | void calcRx(){ 743 | float re[]={0.0,145.2,20692.9,1017847.5}; 744 | float vcc[]={0,871.5,1026.3,1027.1}; 745 | float rx=0; 746 | rx=re[entrada]*(float)v/(vcc[entrada]-(float)v); 747 | Serial.print(">r="); Serial.print(entrada); Serial.print("\t"); 748 | switch (entrada) { 749 | case 1: 750 | if (rx>=1000){ 751 | rx/=1000; 752 | Serial.print(rx); Serial.println(" Kohm"); 753 | } else { 754 | Serial.print(rx); Serial.println(" ohm"); 755 | } 756 | break; 757 | case 2: 758 | Serial.print(rx/1000); Serial.println(" Kohm"); 759 | break; 760 | case 3: 761 | Serial.print(rx/1000000); Serial.println(" Mohm"); 762 | break; 763 | } 764 | } 765 | 766 | void selecionar(byte e){ 767 | entrada=e; 768 | digitalWrite(pinA,bitRead(entrada,0)); 769 | digitalWrite(pinB,bitRead(entrada,1)); 770 | } 771 | 772 | 773 | -------------------------------------------------------------------------------- /images/0 - osciloscopio.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/0 - osciloscopio.bmp -------------------------------------------------------------------------------- /images/1 - Arduino UNO.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/1 - Arduino UNO.jpg -------------------------------------------------------------------------------- /images/2 - garagino e conversor usb-serial.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/2 - garagino e conversor usb-serial.jpg -------------------------------------------------------------------------------- /images/4 - garaginoscopio_bb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/4 - garaginoscopio_bb.jpg -------------------------------------------------------------------------------- /images/5 - multiplex analogico hcf4052be - cd4052.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/5 - multiplex analogico hcf4052be - cd4052.jpg -------------------------------------------------------------------------------- /images/6 - ler resistor e capacitor.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/6 - ler resistor e capacitor.jpg -------------------------------------------------------------------------------- /images/7 - programa processing.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/7 - programa processing.jpg -------------------------------------------------------------------------------- /images/images.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /images/oscilloscope-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/oscilloscope-en.png -------------------------------------------------------------------------------- /images/oscilloscope-pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/oscilloscope-pt.png -------------------------------------------------------------------------------- /images/oscilloscope-pwm-ondaQuadrada-pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/oscilloscope-pwm-ondaQuadrada-pt.png -------------------------------------------------------------------------------- /images/oscilloscope-pwm-squareWave-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/oscilloscope-pwm-squareWave-en.png -------------------------------------------------------------------------------- /images/rog-000001381.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/rog-000001381.jpg -------------------------------------------------------------------------------- /images/rog-000005065.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/rog-000005065.jpg -------------------------------------------------------------------------------- /images/uidades.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriobego/oscilloscope-arduino-processing/e3a1db3380c2abbadb492025ca07ae97492b61eb/images/uidades.png -------------------------------------------------------------------------------- /processing/oscilloscope_4ch/Botao.pde: -------------------------------------------------------------------------------- 1 | class Botao{ 2 | int x,y,w,h; 3 | String tex; 4 | boolean mPressionou=false; 5 | boolean clicado=false; 6 | color cor_ativo=color(0,255,0); 7 | color cor_fio=color(0); 8 | 9 | 10 | //constructor 11 | Botao(String tex_,int x_,int y_, int w_, int h_){ 12 | tex=tex_; x=x_; y=y_; w=w_; h=h_; 13 | } 14 | Botao(String tex_,int x_,int y_, int w_, int h_,color cor_ativo_, color cor_fio_){ 15 | tex=tex_; x=x_; y=y_; w=w_; h=h_; 16 | cor_ativo=cor_ativo_; 17 | cor_fio=cor_fio_; 18 | } 19 | void display(){ 20 | if (mPressionou){ 21 | fill(0,100,0); 22 | } else if (clicado){ 23 | fill(cor_ativo); //fill(0,255,0); 24 | } else{ 25 | fill(200); 26 | } 27 | stroke(cor_fio); strokeWeight(1); 28 | rect(x,y,w,h); 29 | textAlign(CENTER,CENTER); 30 | if (cor_ativo==color(0,0,255) && clicado){ // usar branco para texto na cor de fundo blue 31 | fill(255); 32 | } else{ 33 | fill(0); 34 | } textSize(14); text(tex,x+w/2,y+h/2); 35 | // if (tex.equals("1")) println("mPressionou=",mPressionou); 36 | } 37 | 38 | void mousePressionou(){ 39 | if (mouseButton==LEFT) { 40 | if (mouseX>x && mouseXy && mouseYx && mouseXy && mouseY=0 && pMin2>=0){ 445 | //desenhar os pMin1 e pMin2 446 | strokeWeight(5); stroke(255,0,255); 447 | point(fx(pMin1-qInit),p0); 448 | point(fx(pMin2-qInit),p0); 449 | strokeWeight(1); 450 | 451 | tCalc.setV(abs(pMin2-pMin1)*dt.v.v); 452 | fCalc.setV(1/tCalc.v); 453 | 454 | //mostrar a frequencia e o periodo 455 | textAlign(LEFT); fill(0); 456 | text(fCalc.printV()+"Hz ("+tCalc.printV()+"s)",medir.x,medir.y+29); 457 | } 458 | 459 | 460 | 461 | } 462 | 463 | 464 | 465 | 466 | 467 | /*============================================================ 468 | controle do retangulo de medição na tela (faz medições tempoxtensão) 469 | =============================================================== */ 470 | // mostrar o retangulo de seleção e os valores tempo x volts 471 | void displayRect(){ 472 | if (telaClicou){ 473 | fill(nCor,50); stroke(nCor,255); strokeWeight(1); 474 | tracejado(xi,yi,xi+dx,yi+dy,3); 475 | fill(255); 476 | float vTemp=abs(dx)/(Q)*ft.v.v*1000.0; 477 | //println("Q=",Q); 478 | String vh=nf(vTemp,0,1)+" ms"; 479 | String fh=nf(1000/vTemp,0,1)+ " Hz"; 480 | String vv=nf(abs(dy)/(Q)*fm.v.v,0,2)+" V"; 481 | textAlign(RIGHT); text(vh+" "+fh,xi+dx-10,yi+dy/2); 482 | textAlign(LEFT); text(vv,xi+dx,yi+dy/2); 483 | } 484 | } 485 | 486 | void tracejado(float xi, float yi, float xf, float yf, float step){ 487 | float temp; 488 | boolean faz=true; 489 | if (xi>xf) { 490 | temp=xf; xf=xi; xi=temp; 491 | } 492 | if (yi>yf) { 493 | temp=yf; yf=yi; yi=temp; 494 | } 495 | for (float x=xi; xtela.x && mouseXtela.y && mouseY blue=172 74 | // criar escala de cores para cZ 75 | //rect(tela.x,tela.y,tela.w/3,30); 76 | //strokeWeight(1); stroke(nCor); noFill(); 77 | strokeWeight(1); noStroke(); 78 | if (verPontos.clicado){ 79 | px=tela.x; 80 | py=tela.w/3.0/172.0; 81 | colorMode(HSB); //stroke(255); strokeWeight(2); 82 | for (int k=0; k<172; k++){ 83 | fill(color(k,255,255)); 84 | rect(px+k*py,tela.y,py,30); 85 | } 86 | colorMode(RGB); fill(255);textSize(20); 87 | textAlign(LEFT); text("0v",tela.x,tela.y+15); 88 | textAlign(RIGHT); text("5v",tela.x+tela.w/3,tela.y+15); 89 | textAlign(CENTER); text("ch"+str(cZ),tela.x+tela.w/3/2,tela.y+15); 90 | } 91 | 92 | // criar eixos 93 | float px0=tela.x+10*Q-(p0-tela.y-2*Q); // posição x central da tela 94 | strokeWeight(3); 95 | //if (inv.clicado){ 96 | // //stroke(cor[cY]); line(p0,p0,p0,p0-255*fa/fm.v.v*Q); // vertical 97 | // //stroke(cor[cX]); line(p0,p0,p0-255*fa/fm.v.v*Q,p0); // horizontal 98 | // stroke(cor[cX]); line(px0,XYZy,px0,XYZy-255*fa/fm.v.v*Q); // vertical 99 | // stroke(cor[cY]); line(px0,XYZy,px0+255*fa/fm.v.v*Q,XYZy); // horizontal 100 | //} else { 101 | //stroke(cor[cX]); line(p0,p0,p0,p0-255*fa/fm.v.v*Q); // vertical 102 | //stroke(cor[cY]); line(p0,p0,p0+255*fa/fm.v.v*Q,p0); // horizontal 103 | stroke(cor[cY]); line(px0,p0,px0,p0-1023*fa/fm.v.v*Q); // vertical 104 | stroke(cor[cX]); line(px0,p0,px0+1023*fa/fm.v.v*Q,p0); // horizontal 105 | //} 106 | strokeWeight(1); noFill(); 107 | stroke(nCor); colorMode(HSB); 108 | beginShape(); 109 | for (int k=0;kpini && mouseX(p0-20) && mouseY<(p0+20)){ 148 | mouseOffSet=mouseY-p0; 149 | pegouP0=true; 150 | } 151 | } 152 | } 153 | 154 | void p0MouseArrastou(){ 155 | if (pegouP0){ 156 | //p0=constrain(mouseY,tela.y,tela.y+tela.h)-mouseOffSet; 157 | p0=constrain(mouseY,tela.y+2*Q,tela.y+12*Q)-mouseOffSet; 158 | } 159 | } 160 | 161 | 162 | void mouseClicado(){ 163 | XYZ.mouseClicado(); 164 | // canais selecionados do XYZ 165 | for (int k=0;k<3;k++){ 166 | if(selXYZ[k].mouseClicado()){ 167 | int j=10-4-(parseInt(selXYZ[0].tex)+parseInt(selXYZ[1].tex)+parseInt(selXYZ[2].tex)); 168 | selXYZ[k].tex=str(j); 169 | selXYZ[k].cor_ativo=cor[j]; 170 | selXYZ[k].clicado=true; 171 | } 172 | } 173 | fm.mouseClicado(); 174 | curvaSuave.mouseClicado(); 175 | verCanais.mouseClicado(); 176 | } 177 | 178 | void mousePressionou(){ 179 | fm.mousePressionou(); 180 | p0MousePressionou(); //se pegar o triangulo de p0 181 | } 182 | 183 | void mouseArrastou(){ 184 | fm.mouseArrastou(); 185 | p0MouseArrastou(); // se arrastou o p0 186 | } 187 | 188 | void mouseSoltou(){ 189 | fm.mouseSoltou(); 190 | if (pegouP0) { 191 | pegouP0=false; 192 | } 193 | } 194 | 195 | void mouseMoveu(){ 196 | fm.mouseMoveu(); 197 | } 198 | 199 | 200 | } -------------------------------------------------------------------------------- /processing/oscilloscope_4ch/CheckBox.pde: -------------------------------------------------------------------------------- 1 | class CheckBox{ 2 | int x,y,w,h; 3 | int tSize; // textSize 4 | //color cor; // cor do fundo 5 | //color corBack; // cor do fundo do texto 6 | boolean clicado=false; 7 | boolean piscar=false; 8 | String tex, tex2=""; 9 | //constructor 10 | CheckBox(String tex_, int x_, int y_, int tSize_){ 11 | tex=tex_; x=x_; y=y_; tSize=tSize_; //h=h_; cor=cor_; corBack=corBack_; 12 | textSize(tSize); 13 | h=tSize; 14 | w=(int)textWidth(tex)+h+5; 15 | //println("w=",w); 16 | } 17 | void display(){ 18 | //noFill(); stroke(255); strokeWeight(1); rect(x,y,w,h); 19 | if (piscar){ 20 | fill(map(millis()%1000,0,1000,0,125)); 21 | }else{ 22 | fill(0); 23 | } 24 | textAlign(LEFT,CENTER); 25 | textSize(14); text(tex,x+h+5,y+h/2-2); 26 | if (clicado) { 27 | fill(0,200,0); 28 | } else { 29 | noFill(); 30 | } 31 | stroke(0);strokeWeight(1); rect(x+2,y+2,h-2,h-4); //ellipse(x+h/2,y+h/2,0.6*h,0.6*h); //rect(x+w-h,y,h,h); 32 | fill(0); 33 | //println("clicado=",clicado," tex2=",tex2); 34 | 35 | if (clicado && tex2.length()>0){ 36 | text(tex2,x+5,y+1.75*h); 37 | 38 | } 39 | } 40 | 41 | boolean mouseClicado(){ 42 | boolean r=false; 43 | if (mouseX>x && mouseXy && mouseYx && mouseXy & mouseYy && mouseY1){ 89 | indPort=ports.length-2; 90 | }else{ 91 | indPort=ports.length-1; 92 | } 93 | selectSerial.tex=ports[indPort]; 94 | indSpeed=1; 95 | selectSpeed.tex=speeds[indSpeed]; 96 | versionArduino.tex=""; 97 | } 98 | } else if (selectSerial.mouseClicado()) { // mudar porta serial 99 | //println("Com=mouseClicado"); 100 | if (!conectado){ 101 | indPort++; 102 | if (indPort>=ports.length) indPort=0; 103 | } 104 | selectSerial.tex=ports[indPort]; 105 | } else if (selectSpeed.mouseClicado()) { // mudar speed (baudrate) 106 | if (!conectado){ 107 | indSpeed++; 108 | if (indSpeed>=speeds.length) indSpeed=0; 109 | } 110 | selectSpeed.tex=speeds[indSpeed]; 111 | } else if (onOff.mouseClicado()){ // mudar X (desconectado) para ok (conectado) 112 | if (conectado){ // desconectar 113 | r=-1; // -1 => desconectar 114 | //port.stop(); 115 | //conectado=false; 116 | } else { // conectar 117 | //if (indPortvMax){ 231 | v.setV(vMax); 232 | } else { 233 | v.setV(v2); 234 | } 235 | updateCx(); 236 | ifShiftAlterarGrupo(); 237 | } 238 | return alterou; 239 | } 240 | 241 | void mouseMoveu(){ 242 | if (mouseY>y && mouseYcx-10 && mouseXx && mouseXy-10 && mouseYx-15 && mouseX0){ 65 | n2+=k; 66 | } else { 67 | if (i2>0){ 68 | i2--; 69 | n2=1000+k; 70 | } 71 | } 72 | return n2*pow(10,(i2-5)*3); 73 | } 74 | 75 | void v2nu(float v_){ 76 | i=constrain(int((log(v_)/log(10)+15)/3),0,unid.length-1); // calcular o indice do expoente do numero (v_) na base 10 77 | if (nInt){ 78 | n=round(v_/pow(10,(i-5)*3)); 79 | } else { 80 | n=round((v_/pow(10,(i-5)*3))*10.0)/10.0; 81 | } 82 | u=unid[i]; 83 | } 84 | 85 | void nu2v(){ 86 | v=n*pow(10,(i-5)*3); 87 | v2nu(v); 88 | } 89 | } -------------------------------------------------------------------------------- /processing/oscilloscope_4ch/Grupo.pde: -------------------------------------------------------------------------------- 1 | class Grupo{ 2 | float v=0; 3 | int qtd=0; 4 | int conta=0; 5 | 6 | //constructor 7 | //Grupo(){ 8 | // v=0; 9 | // qtd=0; 10 | // conta=0; 11 | //} 12 | } -------------------------------------------------------------------------------- /processing/oscilloscope_4ch/Painel.pde: -------------------------------------------------------------------------------- 1 | class Painel{ 2 | int x,y,w,h; 3 | String tex=""; 4 | String tex2=""; 5 | Boolean piscar=false; 6 | 7 | //constructor 8 | Painel(String tex_, int x_, int y_, int w_, int h_){ 9 | tex=tex_; 10 | x=x_; y=y_; w=w_; h=h_; 11 | } 12 | 13 | void display(){ 14 | strokeWeight(1); fill(200); stroke(0); 15 | rect(x,y,w,h); 16 | if (piscar){ 17 | fill(map(millis()%1000,0,1000,0,255)); 18 | }else { 19 | fill(0); 20 | } 21 | 22 | textAlign(LEFT); text(tex+" "+tex2,x+5,y+textAscent()); 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /processing/oscilloscope_4ch/Tela.pde: -------------------------------------------------------------------------------- 1 | class Tela{ 2 | int x,y,w,h; 3 | 4 | //constructor 5 | Tela(float xi, float yi, float wi, float hi){ 6 | x=int(xi); y=int(yi); w=int(wi); h=int(hi); 7 | } 8 | void display(){ 9 | fill(0); stroke(0,0,255); strokeWeight(1);// noStroke(); 10 | rect(x,y,w,h); 11 | stroke(100); 12 | for (float lin=y; linx && mouseXy && mouseY when start serial communication, processing send initial commands to arduino in eventserial 4 | // 24/06/2017 => dynamic buffer bug fixed - qInit was not returning to 0 when q changed 5 | // 22/05/2017 => v1.3 dynamic buffer - 1ch=400pt/ch, 2chs=200pt/ch, 3chs=130pt/ch, 4chs=100pt/ch 6 | // 28/05/2017 => bug v1.3 => tenho 1 canal ativo, qdo ativo outro canal dá erro na serial (disabling serialEvent()) 7 | // 14/05/2017 - BegOscopio v1.3 8 | // 29/01/2017 - v1.2 coloquei um valor para o trigger 0-1024 (0-5v) 9 | // transmitir tv512. (512=2.5v) 10 | // 15/10/2015 - acrescentei mais um canal - 4canais 11 | // 16/09/2015 - devido a falta de memória no Arduino, 12 | // mudei o array de int para byte, 13 | // então, dividi os valores por 4 (1023/4=255) 14 | // 08/09/2015 garaginoscopio v1 15 | 16 | //constantes para a classe Dial 17 | byte escLinear=0; // Dial com escala linear 18 | byte escLog=1; // Dial com escala logarítimica (base 10) 19 | byte altMove=2; // mudar o valor ao arrastar o mouse "MouseDragged" 20 | byte altSolta=3; // mudar o valor ao soltar o botão do mouse "MouseReleased" 21 | boolean nInt=true; // n é inteiro (arredondar), ou decimal !nInt 22 | boolean fmt=true; // fmt=true="formatar", !fmt=false="não formatar" 23 | boolean esperandoTrigger=false; 24 | int vTrigger=0; // valor do trigger (subindo) 0-1024 (0-5v) 25 | 26 | color cor[]={color(255, 0, 0), color(0, 255, 0), color(0, 0, 255), color(255,255,0)}; // canais: red,green,blue,yellow 27 | 28 | import processing.serial.*; 29 | 30 | /* 31 | 08-Jun-2017 - output file "dados.txt" when click button 32 | t (ms)ch0 (mV)ch1 (mV) 33 | 01215123 34 | 121232 35 | 22350350 36 | */ 37 | PrintWriter output; 38 | boolean outputOpen=false; 39 | Botao save; 40 | int qSave=0; 41 | 42 | 43 | // configuração dos objetos 44 | Serial port; 45 | Com com; 46 | Tela tela; 47 | CanalXYZ chXYZ; 48 | //Botao XYZ; 49 | //float XYZy; // coordenada y do gráfico XYZ 50 | //float mouseOffSet; 51 | //boolean XYZyPegou=false; // indica se pegou o triangulo do controle do y do XYZ 52 | //Botao selXYZ[]=new Botao[3]; 53 | //Botao medir[]=new Botao[5]; 54 | //Botao trigger[]=new Botao[5]; 55 | Botao resetEixos; 56 | Botao resetMedir; 57 | Canal canal[]=new Canal[4]; 58 | //byte chq=4; // qtd de canais ativos 59 | Grupo grupo[]=new Grupo[3]; // usado para alterar v/div e ms/div simultaneamente em todos os canais usando SHIFT 60 | // painel para os controles de Amostragem 61 | Painel pnlAmostra; // painel 62 | Dial dt; // delta t (tempo de cada leitura) 63 | Dial q; // quantidade de leituras 64 | Botao umaAmostra; // solicita uma Amostra 65 | Botao variasAmostras; // solicita várias Amostras 66 | Botao fluxoContinuo; // entra com leitura a cada dt 67 | FmtNum tTotal; // tempo total da amostragem dt*q 68 | 69 | Botao demo[]=new Botao[3]; // botões para gerar sinais de demonstração 70 | float fase1, fase2, t1, t2; // fase dos DEMO //para noise(t) do demo 71 | CheckBox verPontos; // ver os pontos da amostragem 72 | CheckBox calcFreq; // detectar frequencia 73 | CheckBox grafDif; // (ver) mostrar gráfico Diferença (parecido com a derivada) 74 | 75 | //Dial ruido; // usado para melhorar a detecção da frequencia 76 | 77 | // painel para medir resistor/capacitor 78 | Painel pnlRC; // o valor é colocado em tex2 do CheckBox RC 79 | CheckBox RC; // ativa/desativa medidor de resistor/capacitor 80 | 81 | // painel para o Gerador de Sinal 82 | Painel pnlSinal; 83 | CheckBox sinal; // f e t são dependentes f=1/t, t=1/f 84 | Dial fSinal; // f (frequencia) do Sinal (10kHz-0.125Hz) 85 | Dial tSinal; // T (período) do Sinal (100us-8s) 86 | Dial tonSinal; // tempo em ON (0-100%) 87 | 88 | // verificar se o tempo de leitura Real é igual ao desejado 89 | FmtNum tTotalReal, dtReal; // tempos reais de leitura enviados pelo Arduino 90 | boolean dtErro=false; 91 | float Q=45.0; //tamanho do quadrado na tela 92 | 93 | int chq=4; // qtd de canais selecionados (visiveis) 94 | //int qMax=102; // chq-qMax: 4-102, 3-136, 2-204, 1-408 95 | int ch[]={0,1,2,3}; // quais canais estão visiveis (ON) 96 | 97 | 98 | //temporarios 99 | int marg1, marg2; //margem temporaria para ajustar a posição dos objetos 100 | 101 | void setup() { 102 | size(660, 700); 103 | //size(800,700); 104 | frameRate(10); 105 | 106 | // inicialização dos objetos 107 | // d=new Dial(escLinear,altSolta,"teste","V/div",5,1,100,10,10,100,20); 108 | //port=new Serial(this,Serial.list()[1],9600); 109 | //port.bufferUntil(10); //configurado para pegar linhas inteiras 110 | tela=new Tela(30+10, 60, 10*Q, 12*Q); //horizontal 10divisoes , vertical 12divisoes 111 | 112 | marg1=tela.x+tela.w+10; 113 | marg2=marg1+200; 114 | 115 | //16-Jun-2017 serial port names are too long in Mac - Roman Random 116 | com=new Com(port, tela.x+tela.w-250, 5, 250, 55); 117 | //com=new Com(port, tela.x+tela.w-175, tela.y-30, 175, 20); 118 | 119 | //XYZ=new Botao("XYZ", marg2, tela.y, 45, 20); 120 | //XYZy=tela.y+5*Q; 121 | //for (int k=0; k<3;k++){ 122 | // selXYZ[k]=new Botao(str(k),XYZ.x+XYZ.w+6+k*(18+2),XYZ.y,18,20); 123 | // selXYZ[k].cor_ativo=cor[parseInt(selXYZ[k].tex)]; 124 | // selXYZ[k].clicado=true; 125 | //} 126 | 127 | // for (Grupo g:grupo){ 128 | // g=new Grupo(); 129 | // } 130 | for (byte k=0; k<3; k++){ // deve estar antes do canal 131 | grupo[k]=new Grupo(); 132 | } 133 | 134 | resetEixos=new Botao("eixos",marg1+50,tela.y,45,20); 135 | resetMedir=new Botao("medir",resetEixos.x+resetEixos.w+2,tela.y,45,20); 136 | 137 | //demo & canais 138 | for (byte k=0; k<4; k++) { 139 | if (k<3) {demo[k]=new Botao(str(k+1), marg1+50+k*30, tela.y/2-10, 30, 20);} 140 | //medir[k]=new Botao(str(k),marg2+60+k*(18+2),tela.y+10,18,20,cor[k],cor[k]); 141 | //trigger[k]=new Botao(str(k),medir[k].x,medir[k].y+medir[k].h+10,medir[k].w,20,cor[k],cor[k]); 142 | canal[k]=new Canal(k, cor[k], marg1, tela.y+27+k*110, 143, 100); //h115 143 | } 144 | //medir[4]=new Botao("x",medir[3].x+medir[3].w,medir[3].y,medir[3].w,medir[3].h,color(200),color(0)); 145 | //trigger[4]=new Botao("x",trigger[3].x+trigger[3].w,trigger[3].y,trigger[3].w,trigger[3].h,color(200),color(0)); 146 | 147 | 148 | //chXYZ 149 | chXYZ=new CanalXYZ(color(255,0,255),marg1,canal[3].y+canal[3].h+10,143,80); 150 | chXYZ.verCanais.clicado=true; 151 | 152 | verPontos=new CheckBox("ver pontos", chXYZ.x, chXYZ.y+chXYZ.h+5, 15); 153 | calcFreq=new CheckBox("detectar freq.", verPontos.x, verPontos.y+verPontos.h+5, 15); 154 | grafDif=new CheckBox("ver",calcFreq.x+calcFreq.w,calcFreq.y,15); 155 | //ruido=new Dial(escLinear, altMove, !nInt, fmt, "ruido", "V", 0, 0, 2, calcFreq.x+20, calcFreq.y+17, 100, 20); 156 | 157 | // 08-jun-2017 - button to save data in data.txt 158 | save=new Botao("salvar datax.txt",calcFreq.x,calcFreq.y+calcFreq.h+5,150,20); 159 | 160 | 161 | //medidor de resistor/capacitor 162 | pnlRC=new Painel("", tela.x, tela.y+tela.h+10, 125, 40); 163 | RC=new CheckBox("medir res./cap.", pnlRC.x, pnlRC.y, 15); 164 | 165 | //Gerador de Sinais - agora só gera onda quadrada, depois vai gerar triangulo, denteDeSerra, e senidal 166 | pnlSinal=new Painel("", pnlRC.x+pnlRC.w+10, pnlRC.y, 100, 85); 167 | sinal=new CheckBox("Ger.Sinal", pnlSinal.x, pnlSinal.y, 15); 168 | fSinal=new Dial(escLog, altSolta, !nInt, fmt, "f", "Hz", 50f, 125e-3f, 10e3f, pnlSinal.x+5, sinal.y+sinal.h+2, pnlSinal.w-10, 20); 169 | tSinal=new Dial(escLog, altSolta, !nInt, fmt, "T", "s", 20e-3f, 100e-6f, 8f, fSinal.x, fSinal.y+fSinal.h+2, fSinal.w, fSinal.h); 170 | tonSinal=new Dial(escLinear, altSolta, nInt, !fmt, "Ton", "%", 25f, 0f, 100f, tSinal.x, tSinal.y+tSinal.h+2, tSinal.w, tSinal.h); 171 | 172 | // posicionamento da Amostragem 173 | pnlAmostra=new Painel("Amostragem", pnlSinal.x+pnlSinal.w+10, pnlSinal.y, 200, 85); 174 | dt=new Dial(escLog, altSolta, nInt, fmt, "dt", "s", 1e-3f, 10e-6f, 2f, pnlAmostra.x+5, pnlAmostra.y+20, 100, 20); 175 | dtReal=new FmtNum(0,nInt,fmt); 176 | q=new Dial(escLinear, altSolta, nInt, !fmt, "q", "", 100, 1, 100, dt.x+dt.w+5, dt.y, 60, 20); 177 | tTotal=new FmtNum(dt.v.getV()*q.v.getV(), !nInt); 178 | tTotalReal=new FmtNum(0,!nInt); 179 | umaAmostra=new Botao("uma", dt.x, dt.y+dt.h+5, 50, 20); 180 | variasAmostras=new Botao("varias", umaAmostra.x+umaAmostra.w+5, umaAmostra.y, umaAmostra.w, umaAmostra.h); 181 | fluxoContinuo=new Botao("fluxo", variasAmostras.x+variasAmostras.w+5, variasAmostras.y, variasAmostras.w, variasAmostras.h); 182 | 183 | 184 | 185 | } 186 | 187 | void draw() { 188 | //==== Construir a tela e mostrar os controles ========= 189 | background(100); 190 | fill(0, 255, 255); 191 | textAlign(LEFT, TOP); 192 | textSize(18); 193 | text("BegOscopio "+versao, tela.x, 12); 194 | fill(0); 195 | textSize(12); 196 | text("rogerio.bego@hotmail.com", tela.x, tela.y-15); 197 | tela.display(); 198 | // Botões de demonstração 199 | textSize(15); 200 | fill(0); 201 | textAlign(RIGHT, CENTER); 202 | text("DEMO", demo[0].x-5, demo[0].y+demo[0].h/2); //tela.x+tela.w+10,tela.y); 203 | text("RESET",resetEixos.x-5,resetEixos.y+resetEixos.h/2); 204 | //text("medir", medir[0].x-5,medir[0].y+medir[0].h/2); 205 | //text("trigger", trigger[0].x-5,trigger[0].y+trigger[0].h/2); 206 | chXYZ.display(); 207 | //XYZ.display(); 208 | //for (byte k=0; k<3;k++){ 209 | // selXYZ[k].display(); 210 | //} 211 | for (byte k=0; k<4; k++) { 212 | if (k<3){demo[k].display();} 213 | //medir[k].display(); 214 | //trigger[k].display(); 215 | canal[k].display(); 216 | } 217 | //medir[4].display(); 218 | //trigger[4].display(); 219 | verPontos.display(); 220 | calcFreq.display(); 221 | grafDif.display(); 222 | //ruido.display(); 223 | save.display(); 224 | com.display(); 225 | resetEixos.display(); 226 | resetMedir.display(); 227 | 228 | tTotal.setV(dt.v.getV()*q.v.getV()); 229 | pnlAmostra.tex2="("+tTotal.printV()+"s)"; 230 | pnlAmostra.display(); 231 | dt.display(); 232 | q.display(); 233 | umaAmostra.display(); 234 | variasAmostras.display(); 235 | fluxoContinuo.display(); 236 | //== mostrar o dtReal, tTotalRea e o erro 237 | textAlign(LEFT); 238 | if (dtErro){ fill(255,0,0); } else {fill(0,20,0); } 239 | String tex="Real: dt"+dtReal.printV()+"s"; 240 | if (fluxoContinuo.clicado==false){ 241 | tex+=" total"+tTotalReal.printV()+"s"; 242 | } 243 | text(tex,pnlAmostra.x+5,pnlAmostra.y+pnlAmostra.h-2); 244 | fill(0); 245 | //text("tTotal "+tTotalReal.printV(),pnlSinal.x+pnlSinal.w+10,pnlSinal.y+40); 246 | 247 | 248 | pnlRC.display(); 249 | RC.display(); 250 | 251 | pnlSinal.display(); 252 | sinal.display(); 253 | fSinal.display(); 254 | tSinal.display(); 255 | tonSinal.display(); 256 | 257 | //=== se DEMO estiver ativado, então, gerar os dados === 258 | /* 259 | for (int k=0; k<3; k++) { 260 | if (demo[k].clicado) { 261 | switch(k) { 262 | case 0: // senoide com oscilação na frequencia (angulo, periodo) 263 | canal[0].criarDados2(noise(t), (second()/10+1)*3.0*TWO_PI); 264 | canal[1].criarDados2(t+TWO_PI/3, 3*TWO_PI); 265 | canal[2].criarDados2(t+2*TWO_PI/3, 3*TWO_PI); 266 | canal[3].criarDados2(t+3*TWO_PI/3,3*TWO_PI); 267 | t+=0.02; 268 | break; 269 | case 1: // senoide com oscilação na amplitude (angulo, perido, amplitude) 270 | canal[0].criarDados(noise(t, t1), noise(t1, t)*5*TWO_PI, noise(t+0.1)); 271 | canal[1].criarDados(t1, 3*TWO_PI, noise(t1)); 272 | canal[2].criarDados(noise(t), noise(t)*3*TWO_PI, noise(t1, t)); 273 | canal[3].criarDados(noise(t+1),noise(t)*4*TWO_PI,noise(t,t1)); 274 | t+=0.01; 275 | t1+=0.05; 276 | break; 277 | case 2: // onda quadrada com ruido (angulo, periodo) 278 | canal[0].criarDados3(noise(t), (second()/10+1)*3.0*TWO_PI); 279 | canal[1].criarDados3(t+TWO_PI/3, 3*TWO_PI); 280 | canal[2].criarDados3(t+2*TWO_PI/3, 3*TWO_PI); 281 | canal[3].criarDados3(t+3*TWO_PI/3,3*TWO_PI); 282 | t+=0.02; 283 | break; 284 | } 285 | } 286 | } 287 | */ 288 | //=== se DEMO estiver ativado, então, gerar os dados === 289 | if (demo[0].clicado){ 290 | float mf=second()/10; // de 10 em 10 segundos faz multiplos da frequencia mf*freq 291 | for (int k=0; kinit=v1.5 414 | /* 415 | //initProgram(); 416 | println("init delay 5000"); 417 | delay(5000); 418 | println("end delay 5000"); 419 | for (int k=0;k<4;k++){ 420 | canal[k].chN.clicado=true; 421 | } 422 | // ligar uma amostra 423 | variasAmostras.clicado=true; 424 | if (variasAmostras.clicado) { 425 | port.write("vo"); 426 | } else { 427 | port.write("vx"); 428 | } 429 | println("Abri Serial"); 430 | println("variasAmostra.clicado=",variasAmostras.clicado); 431 | */ 432 | } 433 | 434 | } else if (r==-1) { //retornou -1 então fechar serial 435 | port.stop(); 436 | com.conectado=false; 437 | com.versionArduino.tex=""; 438 | com.erro=false; 439 | } 440 | 441 | if (resetEixos.mouseClicado()){ 442 | for (int k=0; k<4;k++){ 443 | canal[k].p0=tela.y+3*Q*(k+1);//posição da tensão zero 444 | } 445 | resetEixos.clicado=false; 446 | } 447 | 448 | if (resetMedir.mouseClicado()){ 449 | for (int k=0; k<4;k++){ 450 | canal[k].telaClicou=false; 451 | } 452 | resetMedir.clicado=false; 453 | } 454 | 455 | 456 | /* 457 | if (XYZ.mouseClicado()) { 458 | if (XYZ.clicado) { 459 | canal[0].chN.clicado=true; 460 | canal[1].chN.clicado=false; 461 | canal[2].chN.clicado=false; 462 | canal[3].chN.clicado=false; 463 | } else { 464 | canal[1].chN.clicado=true; 465 | canal[2].chN.clicado=true; 466 | canal[3].chN.clicado=true; 467 | } 468 | } 469 | */ 470 | chXYZ.mouseClicado(); 471 | //XYZ.mouseClicado(); 472 | // canais selecionados do XYZ 473 | /* 474 | for (int k=0;k<3;k++){ 475 | if(selXYZ[k].mouseClicado()){ 476 | int j=10-4-(parseInt(selXYZ[0].tex)+parseInt(selXYZ[1].tex)+parseInt(selXYZ[2].tex)); 477 | selXYZ[k].tex=str(j); 478 | selXYZ[k].cor_ativo=cor[j]; 479 | selXYZ[k].clicado=true; 480 | } 481 | } 482 | */ 483 | // habilitar XYZ 484 | //XYZ.mouseClicado(); 485 | 486 | for (int k=0; k<4; k++) { 487 | if (canal[k].mouseClicado()){ // se alterou o Chn para visível ou não visível 488 | if (com.conectado){ // enviar comando para o Arduino não ler esse canal 489 | if (canal[k].chN.clicado){ 490 | port.write("c"+str(k)+"o"); 491 | } else { 492 | port.write("c"+str(k)+"x"); 493 | } 494 | } 495 | verificarQ(); 496 | } 497 | } 498 | 499 | for (int k=0; k<3;k++){ 500 | if (demo[k].mouseClicado()) { // Acionar o DEMO e desmarcas os outros 2 501 | if (demo[k].clicado) { 502 | int total=0; 503 | for (int k2=0; k2<3;k2++){ 504 | if (demo[k2].clicado) total++; 505 | } 506 | if (total<=1) { 507 | tonSinal.salvar(); 508 | fSinal.salvar(); 509 | tSinal.salvar(); 510 | } 511 | for (int j=0; jk; j--) { 515 | demo[j].clicado=false; 516 | } 517 | tonSinal.alterar=altMove; 518 | fSinal.alterar=altMove; 519 | tSinal.alterar=altMove; 520 | } else { 521 | tonSinal.restaurar(); 522 | tonSinal.alterar=altSolta; 523 | fSinal.restaurar(); 524 | fSinal.alterar=altSolta; 525 | tSinal.restaurar(); 526 | tSinal.alterar=altSolta; 527 | } 528 | } 529 | } 530 | 531 | 532 | 533 | // botões para medir tempo x tensão nos 4 canais (e botão de limpar x) 534 | /* 535 | for (int k=0;k<5;k++){ 536 | if (medir[k].mouseClicado()){ 537 | if (medir[k].clicado){ 538 | for (int j=0; jk;j--){ 542 | medir[j].clicado=false; 543 | } 544 | } 545 | if (k==4){ // limpar os retangulos 546 | for (int i=0; i<4; i++){ 547 | canal[i].telaClicou=false; 548 | } 549 | } 550 | } 551 | } 552 | */ 553 | 554 | // botões para acionar o trigger nos canais 555 | /* 556 | for (int k=0;k<5;k++){ 557 | if (trigger[k].mouseClicado()){ 558 | if (trigger[k].clicado){ 559 | for (int j=0; jk;j--){ 563 | trigger[j].clicado=false; 564 | } 565 | //enviar comando para o Arduino 566 | if (com.conectado) { 567 | port.write("t"+trigger[k].tex); 568 | } 569 | } else{ 570 | if (com.conectado){ 571 | port.write("tx"); 572 | } 573 | } 574 | } 575 | } 576 | */ 577 | 578 | verPontos.mouseClicado(); 579 | calcFreq.mouseClicado(); 580 | grafDif.mouseClicado(); 581 | 582 | //08-Jun-2017 write data to file 583 | if (save.mouseClicado()){ 584 | // 14-Jun-2017 save fluxo or save memory 585 | //println("fluxoContinuo.clicado=",fluxoContinuo.clicado); 586 | if (fluxoContinuo.clicado){ 587 | if (outputOpen==false){ // não está gravando, então iniciar a gravação 588 | //println("outputOpen==false => ",outputOpen); 589 | String fileName ="dataf"+nf(year(),4)+nf(month(),2)+nf(day(),2)+nf(hour(),2)+nf(minute(),2)+nf(second(),2)+".txt"; 590 | output=createWriter(fileName); 591 | outputOpen=true; 592 | save.tex="salvando"; 593 | // cabeçalho 594 | //output.println("BegOscopio v"+versao+" "+nf(year())+"-"+nf(month())+"-"+nf(day())+" "+nf(hour())+":"+nf(minute())+":"+nf(second())); 595 | output.print("dt(");output.print(dt.v.printV());output.print(dt.unidade);output.print(")"); 596 | for (int k=0; k<4; k++){ 597 | if (canal[k].chN.clicado){ 598 | output.print('\t');output.print("ch");output.print(k);output.print("(mV)"); 599 | } 600 | } 601 | output.println(); 602 | qSave=0; 603 | // ao entrar cada dado no fluxo gravar em output.print() 604 | // gravar na rotina de entrada 605 | } else { // save já está gravando, então parar a gravação 606 | //println("outputOpen==true => ",outputOpen); 607 | output.close(); 608 | outputOpen=false; 609 | qSave=1; 610 | if (qSave>10) {qSave=1;} 611 | save.tex="salvar datax.txt" + "-"+qSave; 612 | save.clicado=false; 613 | } 614 | } else { 615 | String fileName ="data"+nf(year(),4)+nf(month(),2)+nf(day(),2)+nf(hour(),2)+nf(minute(),2)+nf(second(),2)+".txt"; 616 | output=createWriter(fileName); 617 | // cabeçalho 618 | //output.println("BegOscopio v"+versao+" "+nf(year())+"-"+nf(month())+"-"+nf(day())+" "+nf(hour())+":"+nf(minute())+":"+nf(second())); 619 | output.print("dt(");output.print(dt.v.printV());output.print(dt.unidade);output.print(")"); 620 | for (int k=0; k<4; k++){ 621 | if (canal[k].chN.clicado){ 622 | output.print('\t');output.print("ch");output.print(k);output.print("(mV)"); 623 | } 624 | } 625 | output.println(); 626 | // dados 627 | float f=5000.0/1023.0; 628 | for (int k2=0; k210) {qSave=1;} 641 | save.tex="salvar datax.txt" + "-"+qSave; 642 | save.clicado=false; 643 | } 644 | } 645 | //ruido.mouseClicado(); 646 | 647 | //se clicou em dt ou q então enviar comando para Arduino e ajustar tela 648 | if (dt.mouseClicado()) { // se true alterou dt, então ajustarFt() (escala de t na tela) 649 | enviarDt(); 650 | ajustarFt(); 651 | } 652 | if (q.mouseClicado()) { // se true alterou q, então ajustarFt() 653 | enviarQ(); 654 | ajustarFt(); 655 | } 656 | 657 | if (RC.mouseClicado()) { 658 | if (com.conectado) { 659 | if (RC.clicado) { 660 | port.write("ro"); 661 | } else { 662 | port.write("rx"); 663 | RC.tex2=""; 664 | } 665 | } else { 666 | RC.clicado=false; 667 | } 668 | } 669 | 670 | if (umaAmostra.mouseClicado()) { // receber apenas Uma Amostra 671 | variasAmostras.clicado=false; 672 | fluxoContinuo.clicado=false; 673 | if (outputOpen) { 674 | fecharDados(); 675 | } 676 | if (com.conectado) { 677 | port.write("1"); 678 | } 679 | umaAmostra.clicado=false; 680 | // verificar se tem algum trigger acionado para que ele fique esperando o disparo 681 | // vai ficar piscando para indicar que está aguardando o disparo. 682 | int k2=-1; 683 | for (int k=0; k<4;k++){ 684 | if (canal[k].trigger.clicado) { 685 | k2=k; 686 | break; 687 | } 688 | } 689 | //println("k2=",k2); 690 | 691 | if (k2>=0 && k2<=3){ 692 | pnlAmostra.piscar=true; 693 | canal[k2].trigger.piscar=true; 694 | esperandoTrigger=true; 695 | } else { 696 | pnlAmostra.piscar=false; 697 | esperandoTrigger=false; 698 | } 699 | } 700 | if (variasAmostras.mouseClicado()) { 701 | umaAmostra.clicado=false; 702 | fluxoContinuo.clicado=false; 703 | if (outputOpen) { 704 | fecharDados(); 705 | } 706 | if (com.conectado) { 707 | if (variasAmostras.clicado) { 708 | port.write("vo"); 709 | } else { 710 | port.write("vx"); 711 | } 712 | } else { 713 | variasAmostras.clicado=false; 714 | } 715 | } 716 | if (fluxoContinuo.mouseClicado()) { 717 | umaAmostra.clicado=false; 718 | variasAmostras.clicado=false; 719 | if (com.conectado) { 720 | if (fluxoContinuo.clicado) { 721 | port.write("fo"); 722 | 723 | } else { 724 | port.write("fx"); 725 | if (outputOpen){ 726 | fecharDados(); 727 | } 728 | } 729 | } else { 730 | fluxoContinuo.clicado=false; 731 | } 732 | } 733 | 734 | if (sinal.mouseClicado()){ 735 | if (com.conectado){ 736 | if (sinal.clicado){ 737 | port.write("so"); 738 | } else { 739 | port.write("sx"); 740 | } 741 | } 742 | } 743 | 744 | if (fSinal.mouseClicado()){ 745 | tSinal.setV(1/fSinal.v.v); 746 | enviarCmd("tSinal"); 747 | } 748 | if (tSinal.mouseClicado()){ 749 | fSinal.setV(1/tSinal.v.v); 750 | enviarCmd("tSinal"); 751 | } 752 | if (tonSinal.mouseClicado()){ 753 | enviarCmd("tonSinal"); 754 | } 755 | } 756 | 757 | void verificarQ(){ 758 | chq=0; // contar qtd de canais ativos 759 | for (int k=0; k<4; k++){ 760 | if (canal[k].chN.clicado){ 761 | chq+=1; 762 | } 763 | } 764 | //q.vMax=408.0/chq; 765 | switch (chq){ 766 | case 0: 767 | q.vMax=0; 768 | break; 769 | case 1: 770 | q.vMax=400; 771 | break; 772 | case 2: 773 | q.vMax=200; 774 | break; 775 | case 3: 776 | q.vMax=130; 777 | break; 778 | case 4: 779 | q.vMax=100; 780 | break; 781 | } 782 | if (q.v.v>q.vMax) { 783 | q.setV(q.vMax); 784 | ajustarFt(); 785 | } else { 786 | q.setV(q.v.v); 787 | } 788 | } 789 | 790 | void mousePressed() { 791 | //d.mousePressionou(); 792 | for (int k=0; k<4; k++) { 793 | canal[k].mousePressionou(); 794 | } 795 | chXYZ.mousePressionou(); 796 | dt.mousePressionou(); 797 | q.mousePressionou(); 798 | //ruido.mousePressionou(); 799 | 800 | // só para aparecer o verde do pressionado 801 | umaAmostra.mousePressionou(); 802 | variasAmostras.mousePressionou(); 803 | fluxoContinuo.mousePressionou(); 804 | 805 | fSinal.mousePressionou(); 806 | tSinal.mousePressionou(); 807 | tonSinal.mousePressionou(); 808 | 809 | for (int k=0; k<3;k++){ 810 | demo[k].mousePressionou(); 811 | } 812 | resetEixos.mousePressionou(); 813 | resetMedir.mousePressionou(); 814 | 815 | } 816 | 817 | void mouseReleased() { 818 | // d.mouseSoltou(); 819 | for (int k=0; k<4; k++) { 820 | canal[k].mouseSoltou(); 821 | } 822 | chXYZ.mouseSoltou(); 823 | 824 | for (int k=0; k<3;k++){ 825 | demo[k].mouseSoltou(); 826 | } 827 | resetEixos.mouseSoltou(); 828 | resetMedir.mouseSoltou(); 829 | // só para aparecer o verde do pressionado 830 | umaAmostra.mouseSoltou(); 831 | variasAmostras.mouseSoltou(); 832 | fluxoContinuo.mouseSoltou(); 833 | 834 | 835 | //se soltar o mouse no dt ou q, então enviar os dados para o Arduino 836 | if (dt.mouseSoltou()) { 837 | enviarDt(); 838 | ajustarFt(); 839 | } 840 | if (q.mouseSoltou()) { 841 | enviarQ(); 842 | // acertar as escalas ft de cada canal 843 | ajustarFt(); 844 | } 845 | 846 | 847 | //ruido.mouseSoltou(); 848 | 849 | if (fSinal.mouseSoltou()) { 850 | tSinal.setV(1/fSinal.v.v); 851 | enviarCmd("tSinal"); 852 | } 853 | if (tSinal.mouseSoltou()) { 854 | fSinal.setV(1/tSinal.v.v); 855 | enviarCmd("tSinal"); 856 | } 857 | if (tonSinal.mouseSoltou()){ 858 | enviarCmd("tonSinal"); 859 | } 860 | 861 | 862 | // controle do y do XYZ 863 | //if (XYZ.clicado){ 864 | // XYZyPegou=false; 865 | //} 866 | 867 | 868 | } 869 | 870 | void mouseMoved() { 871 | //teste 872 | // canal[0].cor=get(mouseX,mouseY); 873 | // println("cor=",canal[0].cor); 874 | com.mouseMoveu(); 875 | 876 | for (int k=0; k<4; k++) { 877 | canal[k].mouseMoveu(); 878 | } 879 | chXYZ.mouseMoveu(); 880 | dt.mouseMoveu(); 881 | q.mouseMoveu(); 882 | //ruido.mouseMoveu(); 883 | 884 | fSinal.mouseMoveu(); 885 | tSinal.mouseMoveu(); 886 | 887 | tonSinal.mouseMoveu(); 888 | } 889 | 890 | void mouseDragged() { 891 | //d.mouseArrastou(); 892 | for (int k=0; k<4; k++) { 893 | canal[k].mouseArrastou(); 894 | } 895 | chXYZ.mouseArrastou(); 896 | dt.mouseArrastou(); 897 | q.mouseArrastou(); 898 | //ruido.mouseArrastou(); 899 | 900 | if (fSinal.alterar==altSolta){ 901 | fSinal.mouseArrastou(); 902 | tSinal.mouseArrastou(); 903 | } else { 904 | if (fSinal.mouseArrastou()){ 905 | tSinal.setV(1/fSinal.v.v); 906 | } 907 | if (tSinal.mouseArrastou()){ 908 | fSinal.setV(1/tSinal.v.v); 909 | } 910 | } 911 | 912 | 913 | tonSinal.mouseArrastou(); 914 | 915 | // controle do y do XYZ 916 | //if (XYZ.clicado){ 917 | // if (XYZyPegou){ 918 | // XYZy=constrain(mouseY,tela.y,tela.y+10*Q)-mouseOffSet; 919 | // } 920 | //} 921 | } 922 | 923 | 924 | void keyReleased(){ 925 | keyPressed=false; 926 | } 927 | 928 | 929 | void fecharDados(){ 930 | output.close(); 931 | outputOpen=false; 932 | if (qSave>10) {qSave=1;} 933 | save.tex="salvar datax.txt" + "-"+qSave; 934 | save.clicado=false; 935 | } 936 | 937 | 938 | /* ========================================== 939 | Comando enviados para o Arduino 940 | ========================================== */ 941 | 942 | //=== Ger.Sinal - Se alterou f/T/Ton - enviar comando para Arduino == 943 | void enviarCmd(String cmd){ 944 | if (cmd.equals("tSinal")){ 945 | if (com.conectado){ 946 | port.write("p"+tSinal.v.printV()); 947 | println("p"+tSinal.v.printV()); 948 | } 949 | } else if (cmd.equals("tonSinal")){ 950 | if (com.conectado){ 951 | port.write("o"+tonSinal.v.printV()+"%"); 952 | println("o"+tonSinal.v.printV()+"%"); 953 | } 954 | } 955 | } 956 | 957 | //==Se alterou dt ou q enviar comando para Arduino e ajustar a escala da tela == 958 | void enviarDt() { 959 | if (com.conectado) { 960 | port.write("d"+dt.v.printV()); 961 | } 962 | // acertar as escalas ft de cada canal 963 | ajustarFt(); 964 | } 965 | void enviarQ() { 966 | if (com.conectado) { 967 | port.write("q"+q.v.printV()+"."); 968 | } 969 | } 970 | 971 | void ajustarFt() { 972 | float ftNew=dt.v.getV()*q.v.getV()/10.0; 973 | println("ftNew=",ftNew," dt=",dt.v.getV()," q=",q.v.getV()); 974 | for (int k=0; k<4; k++) { 975 | canal[k].ft.setV(ftNew); 976 | } 977 | } 978 | 979 | /*===================================== 980 | Entrada do Evento Porta Serial 981 | =====================================*/ 982 | void serialEvent(Serial p) { 983 | //if (p.available()>0) {} 984 | try { 985 | String cmd="", val=""; 986 | String tex=p.readStringUntil(10); 987 | //print(">>>> ",tex); //eliminar 988 | if (tex.charAt(0)=='>') { //comando: >cmd=v1(tab)v2(tab)v3(tab) 989 | int i=tex.indexOf("="); 990 | if (i>=0) { // encontrou sinal "=" (igual) obs: i=-1 => não encontrou o sinal '=' 991 | cmd=tex.substring(1, i); // pegar o comando obs: substring(inclusive,exclusive) 992 | val=tex.substring(i+1); // pegar o valor 993 | //println("cmd=",cmd," val=",val); 994 | if (cmd.equals("init")) { // init 995 | println("versionArduino=<",val,">"); 996 | com.versionArduino.tex=".ino "+val.substring(0,val.length()-1); 997 | //start all channels 998 | for (int k=0;k<4;k++){ 999 | canal[k].chN.clicado=true; 1000 | } 1001 | // enviar dt 1002 | enviarDt(); 1003 | // verificar e enviar q 1004 | verificarQ(); 1005 | enviarQ(); 1006 | 1007 | // send command to Arduino -> start Signal Gennerator 60Hz tOn25% 1008 | enviarCmd("tSinal"); 1009 | enviarCmd("tonSinal"); 1010 | sinal.clicado=true; 1011 | port.write("so"); 1012 | 1013 | // ligar varias amostra 1014 | variasAmostras.clicado=true; 1015 | port.write("vo"); 1016 | 1017 | //if (variasAmostras.clicado) { 1018 | // port.write("vo"); 1019 | // } else { 1020 | // port.write("vx"); 1021 | // } 1022 | println("Abri Serial"); 1023 | println("variasAmostra.clicado=",variasAmostras.clicado); 1024 | 1025 | } else if (cmd.equals("f")) { // entra fluxo de dados - deslocar dados e armazenar no final 1026 | String tex2[]=splitTokens(val); //val = "0(t)dtReal(t)ch0(t)ch1(t)ch2" 1027 | //deslocar os dados para baixo, para incluir o novo dado no final 1028 | for (int j=0; j<4; j++) { 1029 | for (int k=1; k1.1*dt.v.v){ dtErro=true;} else {dtErro=false;} 1039 | 1040 | // salvar em arquivo 1041 | if (outputOpen) { 1042 | float f=5000.0/1023.0; 1043 | //for (int k2=0; k2v=1 1024 100 300 300 1087 | for (int k=0; kdt.v.n+10){ dtErro=true;} else {dtErro=false;} 1122 | //text(dtReal,pnlAmostra.x+2,pnlAmostra.y+pnlAmostra.h-12); 1123 | //voltar // println("cmd=",cmd," val=",val," dtReal=",dtReal.printV()); 1124 | 1125 | } else if (cmd.equals("r") || cmd.equals("c") || cmd.equals("rc")) { // valor do resistor 1126 | String tex2[]=splitTokens(val, "\t\r"); 1127 | //i=val.indexOf("\t"); 1128 | //for (int k=0; k>>> ",tex); 1186 | } 1187 | } 1188 | } 1189 | //println("cmd=",cmd); 1190 | //println("val=",val); 1191 | } 1192 | } 1193 | catch(RuntimeException e){ 1194 | e.printStackTrace(); 1195 | 1196 | } 1197 | } --------------------------------------------------------------------------------