Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <Adafruit_GFX.h> incluido en Adafruit_SSD1306.h
- //#include <Adafruit_SPITFT.h>
- #include <Wire.h>
- //#include <Adafruit_SPITFT_Macros.h>
- //#include <gfxfont.h>
- #include <max6675.h>
- #include <Adafruit_SSD1306.h>
- #include <PID_v1.h>
- //TODO
- /*
- REVISAR que onda con los rele y los led
- PROBAR los max 6675
- */
- #define tiempoCiclo 2000
- unsigned long inicioTiempoVentana;
- double setPoint1,setPoint2, input1, input2, output1, output2;
- double kp1 = 10, ki1 = 3, kd1= 400;
- unsigned long respuestaUltimaTemperatura = 0;
- unsigned long lastPIDCalculation = 0;
- PID myPID1(&input1, &output1, &setPoint1, kp1, ki1, kd1, DIRECT);
- PID myPID2(&input2, &output2, &setPoint2, kp1, ki1, kd1, DIRECT);
- //------------
- #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
- Adafruit_SSD1306 display(OLED_RESET);
- #define tc_sck 12
- #define tc_so 11
- MAX6675 tc_1(tc_sck, 8, tc_so); //tc_1.readCelsius()
- MAX6675 tc_2(tc_sck, 7, tc_so);
- #define rele1 5
- #define rele2 3
- #define btn_up 6
- #define btn_down 2
- #define btn_set 4
- #define led_rojo 9// colentando
- #define led_verde 10// llego a temepratura
- #define buzzer 13
- byte setPoint = 35;//valor inicial
- byte posMenu =0; // posicion actual del menu onda primer item, segundo item
- //bool inMenu=0; // esta modificando el itema del menu ? 0 no .. 1 si
- byte contador=90; //90segundos
- bool alarma =0; // esta contando la alarma
- unsigned int millisActual =0;
- unsigned int millisAnterior =0;
- void setup() {
- Serial.begin(9600);
- delay(100); // This delay is needed to let the display to initialize
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize display with the I2C address of 0x3C
- display.clearDisplay(); // Clear the buffer
- display.setRotation(0); // Set orientation. Goes from 0, 1, 2 or 3
- display.setTextColor(WHITE);
- display.setTextWrap(false); // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
- // To override this behavior (so text will run off the right side of the display - useful for
- // scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored
- // with setTextWrap(true).
- display.dim(0); //Set brightness (0 is maximun and 1 is a little dim)
- //------
- myPID1.SetOutputLimits(0, tiempoCiclo);
- myPID1.SetSampleTime(tiempoCiclo);
- myPID1.SetMode(AUTOMATIC);
- myPID2.SetOutputLimits(0, tiempoCiclo);
- myPID2.SetSampleTime(tiempoCiclo);
- myPID2.SetMode(AUTOMATIC);
- inicioTiempoVentana=millis();
- //-----
- pinMode(led_verde,OUTPUT);
- pinMode(led_rojo,OUTPUT);
- pinMode(buzzer,OUTPUT);
- pinMode(rele1,OUTPUT);
- pinMode(rele2,OUTPUT);
- }
- void loop() {
- display.clearDisplay();
- if(digitalRead(btn_up )==LOW){ oledMenu_var( 1 ); }
- if(digitalRead(btn_down)==LOW){ oledMenu_var( 2 ); }
- if(digitalRead(btn_set )==LOW){ oledMenu_var( 3 ); }
- input1= tc_1.readCelsius();
- input2= tc_2.readCelsius();
- setPoint1= setPoint; //setPointn se refiere al detpoint de PID n y "setPoint" es el setpoint modificado desde el menu
- setPoint2= setPoint;//ver deficion myPID2
- myPID1.Compute();
- myPID2.Compute();
- millisActual=millis();
- if (millisActual - inicioTiempoVentana > tiempoCiclo)
- { //time to shift the Relay Window
- inicioTiempoVentana += tiempoCiclo;
- }
- if (output1 > millisActual - inicioTiempoVentana){
- Serial.println(F("RELE HiGH"));
- digitalWrite(rele1,HIGH);
- digitalWrite(rele2,HIGH);
- digitalWrite(led_rojo,HIGH); }
- else {
- Serial.println(F("RELE low"));
- digitalWrite(rele1, LOW);
- digitalWrite(rele2,LOW);
- digitalWrite(led_rojo,LOW);
- }
- if(alarma==true && millisActual - millisAnterior >= 1000 -(75+5) ){//cuenta regresiva del contador
- millisAnterior = millisActual;
- contador--;
- if(contador <=0){
- alarma==false;
- beep2(); }
- }
- oledDisplay(tc_1.readCelsius() ,tc_2.readCelsius() );
- oledMenu_items();
- if(tc_2.readCelsius() >= setPoint){
- //beep1();
- digitalWrite(led_verde, HIGH);
- }
- if(tc_2.readCelsius() < setPoint){
- digitalWrite(led_verde,LOW);
- }
- display.display();
- delay(75);
- }
- void oledDisplay(int pv1, int pv2){
- display.setTextSize(1);
- display.setCursor(5,0);
- display.print(F("pv"));
- display.setTextSize(3);
- display.print(pv1);
- display.print(F("c"));
- display.print(pv2);
- }
- void oledMenu_var(int btn){
- switch(btn){
- case 1://accion boton arriba
- switch(posMenu%3){
- case 0:
- setPoint++;
- break;
- case 1:
- contador+=5;
- break;
- case 2:
- alarma= !alarma;
- break;
- }
- break; // fin case 1
- case 2://accion boton abajo
- switch(posMenu%3){
- case 0:
- setPoint--;
- break;
- case 1:
- contador-=5;
- break;
- case 2:
- alarma= !alarma;
- break;
- }
- break; // fin case 2
- case 3://accion boton set
- posMenu++;
- break;
- }//finswitch
- }//fin oled menu_var
- void oledMenu_items(void){
- byte posY0=25; // esta varieable esta demas
- byte posY1= posY0+7;
- display.setTextSize(1);
- if(posMenu%3==0){
- display.setCursor(0,posY0);
- display.print(F(">"));
- posY1+=8; //como se agrandan los numeros hago mas espacio
- }
- display.setCursor(10,posY0);
- display.print(F("setPoint: "));
- if(posMenu%3==0){display.setTextSize(2);}
- display.print(setPoint);
- display.setTextSize(1);
- display.print(F("c"));
- byte posY2= posY1+7; //
- if(posMenu%3==1){
- display.setCursor(0,posY1);
- display.print(F(">"));
- posY2+=8;
- }
- display.setCursor(10,posY1);
- display.print(F("Timer: "));
- if(posMenu%3==1){display.setTextSize(2); } //agrande letra
- display.print(F("0"));
- byte aux=(int)(contador/60);
- display.print(aux);
- display.print(F(":"));
- if(contador%60<10){ //si el nuemro es de 1 dijito pone el 0 adelante
- display.print(F("0"));
- display.print(contador%60); }
- else{display.print(contador%60); }
- display.setTextSize(1); //achico letra
- if(posMenu%3==2){
- display.setCursor(0,posY2);
- display.print(F(">")); }
- display.setCursor(10,posY2);
- display.print(F("Alarma: "));
- if(posMenu%3==2){display.setTextSize(2);}
- if(alarma==true){ display.print(F("activ.")); }
- else{display.print(F("desctiv.")); }
- display.setTextSize(1);
- }//fin oledMunu_items
- void beep1(void){
- //envia un solo pitido
- }
- void beep2(void){
- // suena como microondas beeeeep beeeeep beeeep
- tone(buzzer,15000,1000);// tono en elpin buzzer, de tantos hz,dura tanto tiempo
- tone(buzzer,0,750);
- tone(buzzer,15000,1000);
- tone(buzzer,0,750);
- tone(buzzer,15000,1000);
- }
- void oledAnimaciones(bool alarma, bool estado){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement