adas em loop.
É só alterar os valores para mudar as frequências.
ESP32_LEDPWM_MAX2.INO ( em anexo)
Exemplo:
void freq248KHz (){ pinMode(18, OUTPUT); // GPIO_18 as Output ledcAttachPin(18, 1); // GPIO_18 attached to PWM Channel 1 ledcSetup(1, 248000, 5); // Channel 1 , freq 248,000 KHz , 5 bit resolution = 32 ledcWrite(1, 8); // Enable frequency with dutty cycle 25%}…
2 programas de irrigação e o arduino nao esta realizando mais o processo. Para que nao fosse necessário usar delays eu estou calculando o tempo de ligar e desligar os setores e a bomba e deixando uma quantidade bem grande de if's para conferir as condições. Acho que pode ser nisso o problema:
O codigo esta muito grande, vou deixar ele em anexo mas vou citar o trecho que acredito ser o problema
void Bomba()//Tempo que a bomba ficará ligada{ delay(1000); while(tBomba >=1) { lcd.clear();lcd.setCursor(0,0);lcd.print("Tempo ");lcd.print(tBomba);lcd.print(" minutos"); lcd.setCursor(0,1);lcd.print("Enter");lcd.setCursor(7,1);lcd.print("(-)");lcd.setCursor(12,1);lcd.print("(+)"); delay(120); if(tBomba>60){tBomba=1;} if(digitalRead(bUp)==LOW){delay(70);tBomba++;} if(digitalRead(bDown)==LOW){delay(70);tBomba--;} if(digitalRead(bEnter)==LOW){delay(70);tB=tBomba;menu=0;tBomba=0;} if(digitalRead(bMode)==LOW){menu=0;tBomba=0;} //Vetores recebem horas e minutos e converte para minutos //Calculo Programa 1//Depois acrescenta o valor do tempo de bomba(tB)//Operação desliga bomba e valvula 4 //Retorna os valores para os vetores com o horario de desligar//Exemplo: Programa 1 - 6:30 com tempo de bomba 10min//Em minutos (6*60)+30+10=400minutos//Tranformando para desligar hora=400/60=6 e minuto=400%60=40
if(h[2]!=0 && h[1]!=0 && h[30]==0 && tB!=0){ h[34]=h[2];h[33]=h[1]; h[34]=h[34]*60;h[34]=h[34]+h[33]+(4*tB);h[33]=h[34]%60;h[34]=h[34]/60; h[8]=h[2];h[7]=h[1]; h[8]=h[8]*60;h[8]=h[8]+h[7]+tB;h[7]=h[8]%60;h[8]=h[8]/60;//1 tempo(desliga 1 e liga 2) h[10]=h[2];h[9]=h[1]; h[10]=h[10]*60;h[10]=h[10]+h[9]+(2*tB);h[9]=h[10]%60;h[10]=h[10]/60;//2 tempo(desliga 2 e liga 3) h[12]=h[2];h[11]=h[1]; h[12]=h[12]*60;h[12]=h[12]+h[11]+(3*tB);h[11]=h[12]%60;h[12]=h[12]/60;//3 tempo(desliga 3 e liga 4) //Calculo Programa 2 if(h[4]!=0 && h[3]!=0 && h[31]==0){ h[14]=h[4];h[15]=h[3]; h[14]=h[14]*60;h[14]=h[14]+h[15]+(4*tB);h[15]=h[14]%60;h[14]=h[14]/60;//Operação Desliga bomba e valvula 4 h[16]=h[4];h[17]=h[3]; h[16]=h[16]*60;h[16]=h[16]+h[17]+tB;h[17]=h[16]%60;h[16]=h[16]/60;//1 tempo(desliga 1 e liga 2) h[18]=h[4];h[19]=h[3]; h[18]=h[18]*60;h[18]=h[18]+h[19]+(2*tB);h[19]=h[18]%60;h[18]=h[18]/60;//2 tempo(desliga 2 e liga 3) h[20]=h[4];h[21]=h[3]; h[20]=h[20]*60;h[20]=h[20]+h[21]+(3*tB);h[21]=h[20]%60;h[20]=h[20]/60;//3 tempo(desliga 3 e liga 4) h[31]=1; //Calculo Programa 3 if(h[6]!=0 && h[5]!=0 && h[32]==0){ h[22]=h[6];h[23]=h[5]; h[22]=h[22]*60;h[22]=h[22]+h[23]+(4*tB);h[23]=h[22]%60;h[22]=h[22]/60;//Operação Desliga bomba e valvula 4 h[24]=h[6];h[25]=h[5]; h[24]=h[24]*60;h[24]=h[24]+h[25]+tB;h[25]=h[24]%60;h[24]=h[24]/60;//1 tempo(desliga 1 e liga 2) h[26]=h[6];h[27]=h[5]; h[26]=h[26]*60;h[26]=h[26]+h[27]+(2*tB);h[27]=h[26]%60;h[26]=h[26]/60;//2 tempo(desliga 2 e liga 3) h[28]=h[6];h[29]=h[5]; h[28]=h[28]*60;h[28]=h[28]+h[29]+(3*tB);h[29]=h[28]%60;h[28]=h[28]/60;//3 tempo(desliga 3 e liga 4) h[32]=1; } }//Fim if Programa 2 h[30]=1;tempo=1; }//Fim if Programa 1 }//Fim While}
if(d[0]=1){//Se apção todos os dias for selecionada //Horarios Para Programa 1 if(h[2]==RTCValues[4] && h[1]==RTCValues[5] && RTCValues[6]==0){digitalWrite(bomba,HIGH);digitalWrite(vs1,LOW);delay(70);}//Liga bomba e valvula 1 if(h[8]==RTCValues[4] && h[7]==RTCValues[5] && RTCValues[6]==0){digitalWrite(vs1,HIGH);digitalWrite(vs2,LOW);delay(70);}//Desliga Valvula 1 e liga Valvula 2 if(h[10]==RTCValues[4] && h[9]==RTCValues[5] && RTCValues[6]==0){digitalWrite(vs2,HIGH);digitalWrite(vs3,LOW);delay(70);}//Desliga Valvula 2 e liga Valvula 3 if(h[12]==RTCValues[4] && h[11]==RTCValues[5] && RTCValues[6]==0){digitalWrite(vs3,HIGH);digitalWrite(vs4,LOW);delay(70);}//Desliga Valvula 3 e liga Valvula 4 if(h[34]==RTCValues[4] && h[33]==RTCValues[5] && RTCValues[6]==0){digitalWrite(bomba,LOW);digitalWrite(vs4,HIGH);delay(70);}//Desliga bomba e desliga Valvula 4 //Horarios Para Programa 2 if(h[4]==RTCValues[4] && h[3]==RTCValues[5] && RTCValues[6]==0){digitalWrite(bomba, HIGH);digitalWrite(vs1,LOW);}//Liga bomba e valvula 1 if(h[16]==RTCValues[4] && h[17]==RTCValues[5] && RTCValues[6]==0){digitalWrite(vs1,HIGH);digitalWrite(vs2,LOW);}//Desliga Valvula 1 e liga Valvula 2 if(h[18]==RTCValues[4] && h[19]==RTCValues[5] && RTCValues[6]==0){digitalWrite(vs2,HIGH);digitalWrite(vs3,LOW);}//Desliga Valvula 2 e liga Valvula 3 if(h[20]==RTCValues[4] && h[21]==RTCValues[5] && RTCValues[6]==0){digitalWrite(vs3,HIGH);digitalWrite(vs4,LOW);}//Desliga Valvula 3 e liga Valvula 4 if(h[14]==RTCValues[4] && h[15]==RTCValues[5] && RTCValues[6]==0){digitalWrite(bomba,LOW);digitalWrite(vs4,HIGH);}//Desliga bomba e desliga Valvula 4 //Horarios Para Programa 3 if(h[6]==RTCValues[4] && h[5]==RTCValues[5] && RTCValues[6]==0){digitalWrite(bomba, HIGH);digitalWrite(vs1,LOW);}//Liga bomba e valvula 1 if(h[24]==RTCValues[4] && h[25]==RTCValues[5] && RTCValues[6]==0){digitalWrite(vs1,HIGH);digitalWrite(vs2,LOW);}//Desliga Valvula 1 e liga Valvula 2 if(h[26]==RTCValues[4] && h[27]==RTCValues[5] && RTCValues[6]==0){digitalWrite(vs2,HIGH);digitalWrite(vs3,LOW);}//Desliga Valvula 2 e liga Valvula 3 if(h[28]==RTCValues[4] && h[29]==RTCValues[5] && RTCValues[6]==0){digitalWrite(vs3,HIGH);digitalWrite(vs4,LOW);}//Desliga Valvula 3 e liga Valvula 4 if(h[22]==RTCValues[4] && h[23]==RTCValues[5] && RTCValues[6]==0){digitalWrite(bomba,LOW);digitalWrite(vs4,HIGH);}//Desliga bomba e desliga Valvula 4 }
As variaveis h[1]...h[6] Recebem os horarios de irrigação. Impares minutos e Pares horas…
1 kHz = OK
15,000 kHz 15 kHz = OK
50,000 kHz 50 KHz = OK
100,000 kHz 100 ou 99 KHz
200,000 kHz 142 kHz
500,006 kHz 143 KHz
1,000001 MHz 143 KHz
Você pode testar ai com o seu ESP32!
As frequências geradas com o ESP32 são incrivelmente precisas!
O pino de geração no ESP32 é o GPIO18.
Mudando para Duty Cycle 50%
void freq248KHz (){ pinMode(18, OUTPUT); // GPIO_18 as Output ledcAttachPin(18, 1); // GPIO_18 attached to PWM Channel 1 ledcSetup(1, 248000, 5); // Channel 1 , freq 248,000 KHz , 5 bit resolution = 32 ledcWrite(1, 16); // Enable frequency with dutty cycle 50%}…
, 17}; //connect to the row pinouts of the keypadbyte colPins[COLS] = {18, 19, 20, 21}; //connect to the column pinouts of the keypad //INICIALIZAÇÃO DO TECLADO
Estou utilizando esta pinagem {14, 15, 16, 17}; {18, 19, 20, 21};
Esse codigo assima e o codigo horiginal da biblioteca KEYPAD CUSTOM onde o arduino responde perfeitamente ao codigo funciona sem problemas.…
0, 1, 2, 3, 4, 6, 7, 16 Teensy 2.0: 5, 6, 7, 8 Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37 Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37 Sanguino: 2, 10, 11
for more information you can read the original wiki in arduino.cc at http://www.arduino.cc/playground/Main/PS2Keyboard or http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html
Like the Original library and example this is under LGPL license.
Modified by Cuninganreset@gmail.com on 2010-03-22 Modified by Paul Stoffregen <paul@pjrc.com> June 2010*/
#include const int DataPin = 8;const int IRQpin = 5;
PS2Keyboard keyboard;
void setup() { delay(1000); keyboard.begin(DataPin, IRQpin); Serial.begin(9600); Serial.println("Keyboard Test:");}
void loop() { if (keyboard.available()) {
// read the next key char c = keyboard.read();
// check for some of the special keys if (c == PS2_ENTER) { Serial.println(); } else if (c == PS2_TAB) { Serial.print("[Tab]"); } else if (c == PS2_ESC) { Serial.print("[ESC]"); } else if (c == PS2_PAGEDOWN) { Serial.print("[PgDn]"); } else if (c == PS2_PAGEUP) { Serial.print("[PgUp]"); } else if (c == PS2_LEFTARROW) { Serial.print("[Left]"); } else if (c == PS2_RIGHTARROW) { Serial.print("[Right]"); } else if (c == PS2_UPARROW) { Serial.print("[Up]"); } else if (c == PS2_DOWNARROW) { Serial.print("[Down]"); } else if (c == PS2_DELETE) { Serial.print("[Del]"); } else {
// otherwise, just print all normal characters Serial.print(c); } }}
----- ele digita os codigos no arduino conforme agente vai apertando qualquer tecla as linhas de testes acima…
Adicionado por Fabio Cimino ao 23:35 em 13 janeiro 2013
tempoSafe*60000; z++){ digitalWrite(ledVerm, HIGH); delay(500); digitalWrite(ledVerm, LOW); delay(500);"
" for(z = 0; z < tempoSafe*60000; z++){" Nesta parte o numero (60000) tá muito elevado, e o teclado bloquearia por 83,3 horas, então no meu eu troquei o 60000 por 18 que bloqueia por 1:30 mim, visto que o numero é multiplo de 5 ou seja 18*5=90 segundos.
Mas eu queria realmente agradecer pelo projeto que eu tava precisando mesmo de um desses e nem sabia por onde começar, parabéns e boa noite! :)…