Farkas.József Creative Commons License 2022.02.02 0 0 3999

Sikerült megoldani és jól is működik.

 

/*
     Digital Voltmeter using 5x 4-Digit 7-segment Display
     www.circuits4you.com
 */
 
#include <TimerOne.h>
 
//Define 74HC595 Connections with arduino
const int Data=7;
const int Clock=8;
const int Latch=6;
 
const int SEG0=5;
const int SEG1=4;
const int SEG2=3;
const int SEG3=2;
 
int cc = 0;
char Value[20];

const float R1 = 10000;
const float A = 1.130298644e-3, B = 2.347705553e-4, C = 0.7858666791e-7;  // Steinhart-Hart and Hart Coefficients
 
//Refer Table 4.1 7-Segment Decoding
const char SegData[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

// Sajat PINek
const int bemenetek[] = {A0, A1, A2, A3, A4};
const int szivattyuKazanPIN = 9;
const int szivattyuFutesPIN = 10;
const int termosztatPIN = 11;
const int fokapcsoloPIN = 12;

//=============================================================
//                Setup
//=============================================================
void setup() {                
  // initialize the digital pin as an output.
  Serial.begin(9600);
  pinMode(Data, OUTPUT);
  pinMode(Clock, OUTPUT);
  pinMode(Latch, OUTPUT);
  pinMode(SEG0, OUTPUT);
  pinMode(SEG1, OUTPUT);
  pinMode(SEG2, OUTPUT);
  pinMode(SEG3, OUTPUT);
  pinMode(szivattyuKazanPIN, OUTPUT);
  pinMode(szivattyuFutesPIN, OUTPUT);
 
    //Initialize Display Scanner
  cc=0;
  Timer1.initialize(2500); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
  Timer1.attachInterrupt( timerIsr ); // attach the service routine here
}
//=============================================================
//               Loop
//=============================================================
void loop() {
  char Volt[4];
  float R2;
  float logR2;
  float T;
  int i;
  int Voltage;
  float homersekletek[] = {0,0,0,0,0};
  for ( i=0 ; i<5 ; i++ ) {
    Voltage = analogRead(bemenetek[i]);
    R2 = R1* (1023.0 / (1023-(float)Voltage) - 1.0);
    logR2 = log(R2);
    T = (1.0 / ((A + B*logR2 + C*logR2*logR2*logR2)));  // Steinhart and Hart Equation. T  =(1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
    T =  T - 273.15;
    Serial.print("Erzekelo:");
    Serial.println(i);
    Serial.print("Voltage:");
    Serial.println(Voltage);
    Serial.print("Homerseklet:");
    Serial.println(T);
    //  Voltage = (5000/1024.0) * (1023-Voltage);  //Scaling of 0 to 5V i.e. 0 to 1023 to 0 to 10 (in 10 steps)
    sprintf(Volt,"%04d",(int)(T*10));    //We get ASCII array in Volt
    Value[4*i]=Volt[0] & 0x0F;//Anding with 0x0F to remove upper nibble
    Value[(4*i)+1]=Volt[1] & 0x0F;
    Value[(4*i)+2]=Volt[2] & 0x0F;
    Value[(4*i)+3]=Volt[3] & 0x0F;
    homersekletek[i] = (float)T;
  }
  if ( homersekletek[4] > 80 && homersekletek[1] > 85 ) {
    digitalWrite(szivattyuKazanPIN, HIGH);
    digitalWrite(szivattyuFutesPIN, HIGH);
   } else {
    if ( digitalRead(fokapcsoloPIN) == HIGH ) {
      int termosztat = digitalRead(termosztatPIN);
      if ( homersekletek[0] <= 30 ) {
        digitalWrite(szivattyuFutesPIN, LOW);
      } else if ( termosztat == HIGH ) {
        digitalWrite(szivattyuFutesPIN, HIGH);
      } else {
        digitalWrite(szivattyuFutesPIN, LOW);
      }
      if ( homersekletek[1] <= 30 || homersekletek[4] >= homersekletek[1] ) {
        digitalWrite(szivattyuKazanPIN, LOW);
      } else {
        digitalWrite(szivattyuKazanPIN, HIGH);
      }
    } else {
      digitalWrite(szivattyuFutesPIN, LOW);
      digitalWrite(szivattyuKazanPIN, LOW);
    }
  }
  delay(1000);
}
 
//=============================================================
//             Generates Bargraph
//=============================================================
void DisplayDigit(char d) {
  int i;
  for ( i=0 ; i<8 ; i++ ) { //Shift bit by bit data in shift register
    if((d & 0x80)==0x80) {
      digitalWrite(Data,HIGH);
    }
    else {
      digitalWrite(Data,LOW);
    }
    d=d<<1;
    //Give Clock pulse
    digitalWrite(Clock,LOW);        
    digitalWrite(Clock,HIGH);
  }
}
//===================================================================
//            TIMER 1 OVERFLOW INTTERRUPT FOR DISPALY
//===================================================================
void timerIsr()
{
  switch (cc)
  {
    case 0:
      digitalWrite(SEG3,HIGH);
      DisplayDigit(SegData[Value[cc+16]]);
      DisplayDigit(SegData[Value[cc+12]]);
      DisplayDigit(SegData[Value[cc+8]]);
      DisplayDigit(SegData[Value[cc+4]]);
      DisplayDigit(SegData[Value[cc]]);
      digitalWrite(SEG0,LOW);
      break;
    case 1:
      digitalWrite(SEG0,HIGH);
      DisplayDigit(SegData[Value[cc+16]]);
      DisplayDigit(SegData[Value[cc+12]]);
      DisplayDigit(SegData[Value[cc+8]]);
      DisplayDigit(SegData[Value[cc+4]]);
      DisplayDigit(SegData[Value[cc]]);
      digitalWrite(SEG1,LOW);
      break;
    case 2:
      digitalWrite(SEG1,HIGH);
      DisplayDigit(SegData[Value[cc+16]] | 0x80);
      DisplayDigit(SegData[Value[cc+12]] | 0x80);
      DisplayDigit(SegData[Value[cc+8]] | 0x80);
      DisplayDigit(SegData[Value[cc+4]] | 0x80);
      DisplayDigit(SegData[Value[cc]] | 0x80);
      digitalWrite(SEG2,LOW);
      break;
    case 3:
      digitalWrite(SEG2,HIGH);    
      DisplayDigit(SegData[Value[cc+16]]);
      DisplayDigit(SegData[Value[cc+12]]);
      DisplayDigit(SegData[Value[cc+8]]);
      DisplayDigit(SegData[Value[cc+4]]);
      DisplayDigit(SegData[Value[cc]]);
      digitalWrite(SEG3,LOW);      
      break;
  }
  //Latch the data
  digitalWrite(Latch,LOW);
  digitalWrite(Latch,HIGH);
  cc++;
  if(cc==4) {
    cc=0;
  }
    TCNT0=0xcc;
}