boa Tarde.
Eu trabalho com arduino a pouco tempo, e no entanto estou tentando fazer que ele controle um modulo de alta-tensão, ja consegui que ele faça a maior parte dos processos, porem estou com dificuldade em colocar um temporizador nele, ja tentei algumas coisas, porem a parte de temporização esta um fracasso,
esse equipamento tem que levantar tensão até um determinado valor "pré determinado" e deveria mandar descer a tensão quando terminar de contar o tempo.
não estou conseguindo fazer isso, e seria muito agradecido se aguém conseguisse me ajudar.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
float tensao; //valor real de medição
float vtensao = 0; //ancora para tensão
float rtensao = 0; //entrada analogica para tensão
float tensaoLCD;
float tensaoC;
float corrente; //valor real de corrente
float vcorrente = 0; // ancora para corrente
float rcorrente = 2; // entrada para corrente
float correnteC;
float correnteLCD;
int s1 = 13;//encremento de tela
int s2 = 7;//decremento de tela
int s4 = 8; // encremento do valor de variavel
int k1 = 9;//sobe tensão
int k2 = 6;//desce tensão
float x;//comparação do valor setado com a tensão
float tensaox; //valor real setado
float tensaoy;//valor setado com multiplicador
int s; // estagio da tela
int fugax = 50; //valor real setado da fuga
float fuga; //valor real com mutiplicador
int saida = 10;
int pwm = 0;
int apwm;
int p1;
int p2 = 0;
int am;
int tempo;
int ctempo;
int rtempo;
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print(" E.E.A.T. ");
lcd.setCursor(0,1);
lcd.print("www.eeat.com.br ");
delay(2000);
lcd.setCursor(0,1);
lcd.print("(11)4017-2114 ");
delay(2000);
lcd.setCursor(0,1);
lcd.print("(11)4017-2121 ");
delay(2000);
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
pinMode (s1, INPUT);
pinMode (s2, INPUT);
pinMode (s4, INPUT);
pinMode (saida, OUTPUT);
//pinMode (sfuga, OUTPUT);
pinMode (k1, OUTPUT);
pinMode (k2, OUTPUT);
tensaox=0;
p1=3;
tempo = 0;
s=1;
am = 0;
Serial.begin(9600);
}
void loop() {
//************COMUNICAÇÃO SERIAL*********
Serial.print("tensao = ");
Serial.println(tensaoy);
// AJUSTE DE TELA
tensaox = constrain (tensaox, 0, 1200);
s = constrain (s, 1, 7);
if (digitalRead(s4)==HIGH)s++;
if (s>6){
s=1;
}
//*************TELA *****1*****
//*******VELOCIDADE DO MOTOR*****
if(s==1);{
pwm = map(apwm, 0, 1023, 0, 255);
apwm = constrain (apwm, 0, 255);
p1 = constrain(p1, 1, 3);
p2 = constrain(p2, 0, 1);
if(digitalRead(s1)==HIGH)p1++;
if(digitalRead(s2)==HIGH)p1--;
if(p1==1){
apwm=150;
}
if(p1==2){
apwm=200;
}
if (p1==3){
apwm=255;
}
//if(p1==4){
// apwm=80;
//}
lcd.setCursor(0,0);
lcd.print("VEL. DO VARIADOR");
lcd.setCursor(0,1);
lcd.print("");
if(p1==1){
lcd.print("0,5 Kv/s ");
}
else if(p1==2){
lcd.print("1 Kv/s ");
}
else if(p1==3){
lcd.print("2 Kv/s ");
}
//analogWrite(motor, apwm);
}
//***********TELA****2**********************
//*****TELA TEMPORIZADOR***********************
rtempo= ctempo*1000;
tempo= rtempo/1000;
ctempo=constrain(ctempo, 0, 20);
if(s==2){
if(digitalRead(s1)==HIGH)ctempo++;
if(digitalRead(s2)==HIGH)ctempo--;
lcd.setCursor(0,0);
lcd.print("TEMPORIZADOR ");
lcd.setCursor(0,1);
lcd.print("");
lcd.print(tempo);
lcd.print(" Seg. ");
}
//**************TELA**3***********
//********AUTOMATICO**MANUAL******
am = constrain(am, 1, 2);
if(s==3){
if(digitalRead(s1)==HIGH)am++;
if(digitalRead(s2)==HIGH)am--;
lcd.setCursor(0,0);
lcd.print("AJUS. AUT./MAN. ");
if(am==1){
lcd.setCursor(0,1);
lcd.print("AUTOMATICO");
}
if(am==2){
lcd.setCursor(0,1);
lcd.print("MANUAL");
}
}
//*****TELA******4******
//********AJUSTAR TENSÃO**********
vtensao=analogRead(rtensao);
vtensao = map(vtensao, 0, 1023, 0, 1000);
if(am==2 && s==4){
s=5;
}
tensaoy = tensaox*1;
if(s==4 && am==1){
if (digitalRead(s1)==HIGH)tensaox++;
if (digitalRead(s2)==HIGH)tensaox--;
lcd.setCursor(5,1);
lcd.print(" ");
lcd.setCursor (0,0);
lcd.print("AJUSTE TENSAO ");
lcd.setCursor (0,1);
lcd.print(tensaoy);
lcd.print("kV");
}
tensaoLCD = 5*(vtensao/1000)*24;
tensao=tensaoLCD;
//********TELA****5******
//******AJUSTE****CORRENTE**DE**FUGA*****
vcorrente=analogRead(rcorrente);
//vcorrente = map (vcorrente, 0, 1023, 0, 1000);
fuga=constrain(fuga, 0, 100);
fugax=constrain(fugax, 0, 100);
if (correnteLCD<10){
correnteC = 1.09;
}
if (correnteLCD>=10 && correnteLCD<=20){
correnteC = 1.035;
}
if (correnteLCD>20 && correnteLCD<=30){
correnteC = 1.03;
}
if (correnteLCD>30 && correnteLCD<=40){
correnteC = 1.028;
}
if (correnteLCD>40 && correnteLCD<=50){
correnteC = 1.024;
}
if (correnteLCD>50 && correnteLCD<=60){
correnteC = 1.028;
}
if (correnteLCD>60 && correnteLCD<=70){
correnteC = 1.02;
}
if (correnteLCD>70 && correnteLCD<=80){
correnteC = 1.024;
}
if (correnteLCD>80 && correnteLCD<=90){
correnteC = 1.017;
}
if (correnteLCD>90){
correnteC = 1.02;
}
correnteLCD = 5*(vcorrente/1023)*20;
corrente=correnteLCD*correnteC;
fuga = fugax*1;
if ( s==5 ){
if(digitalRead(s1)==HIGH)fugax++;
if(digitalRead(s2)==HIGH)fugax--;
lcd.setCursor (0,0);
lcd.print("AJUSTAR FUGA ");
lcd.setCursor (0,1);
lcd.print(fuga);
lcd.print("mA ");
}
//******TELA**5*************
//*******MEDIÇÃO*****************
if(s==6){
if(corrente>=fuga){
digitalWrite(saida, HIGH);
}
lcd.setCursor (0,0);
lcd.print("");
lcd.print(corrente);
lcd.print(" mA ");
lcd.setCursor (0,1);
lcd.print("");
lcd.print(tensao);
lcd.print(" Kv ");
if(am==1){
if(x==0 || x<990){
digitalWrite(k1, HIGH);}
else{digitalWrite (k1, LOW);}
if(x>1010){
digitalWrite(k2, HIGH);}
else{digitalWrite(k2, LOW);}
delay (60);
if(x>950 && x<1050) {
p1=1;
digitalWrite(k1, LOW);
digitalWrite(k2, LOW);
delay(250);
}
}
if(am == 2){
if(digitalRead(s2)==HIGH){
digitalWrite(k1, HIGH);
}
else{digitalWrite(k1, LOW);}
if(digitalRead(s1)==HIGH){
digitalWrite(k2, HIGH);
}
else{digitalWrite(k2, LOW);}
}
}
if(s<6){
digitalWrite(k1, HIGH);
digitalWrite(k2, LOW);
}
//************saida**fuga*****************************\\\\\\\\\\\\\\\\\
if(digitalRead(s1)==HIGH && digitalRead(s2)==HIGH){
digitalWrite(saida, LOW);
}
if(digitalRead(saida)==HIGH){
digitalWrite(k2, LOW);
digitalWrite(k1, HIGH);
x=2000;
}
//******************************************************
//TEMPORIZADOR
/* tempo = constrain (tempo, 0, 180000);
if (corrente - fuga = 0){
tempo++;
delay(1000);
}
else{tempo = 0;}*/
//******************************************************
x=1000*(tensaoy/tensao);
delay(200);
}
Tags:
Oi NAAJ, boa tarde,
Eu gostaria muito de te ajudar, mas tem 2 problemas:
1o. O seu código está muito pouco comentado, o que me daria muito trabalho de entender o funcionamento
do mesmo e o porque de cada linha dele.
2o. Como você postou direto na área de texto do post, é então ele perde a identação, e fica muito mais difícil
de analisar as "funções", os"ifs" "else", etc., e as vezes perde caracteres.
Experimente postar 2 sinais de "menor que" seguidos, e entenderá o que digo.
Caso você resolva, comentá-lo adequadamente, post como arquivo anexado, ou em site como o www.pastbin.com,
e eu tentarei te ajudar.
Recomendo ler o meu post:
http://labdegaragem.com/forum/topics/sugest-o-de-como-postar
Rui
Bom dia.
Rui, muito obrigado pela dica, vou sim comentar mais o meu algorítimo, e postar a minha solução assim que eu terminar de comentar, pois ja esta resolvido.
Consegui com um exemplo consegui uma biblioteca e exemplos na internet.
Att.
Nelson Junior.
Nelson da uma olhada no exemplo Blink without Delay! Usar o (if) millis no lugar do delay como uma pseudo base de tempo deve tornar sua tarefa mais distribuida
Bem-vindo a
Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)
© 2024 Criado por Marcelo Rodrigues. Ativado por