A problem with codes.

Hi everyone,

I put together two codes and when i upload it to my arduino it only shows the temperature. Can anyone help me so i can resolve this problem?

#include <SevSeg.h>
#include <Wire.h>
#include <DHT.h>

#define DHTPIN 11
#define DHTTYPE DHT11
#define DS1307_ADDRESS 0x68

SevSeg display7seg;
DHT dht(DHTPIN, DHTTYPE);
//Clock
int valor = 0;
int minutos_;
int horas_;
int buttonState = 0;
//Buttons for increase minuts and hours
const int buttonPin2 = A1;
const int buttonPin = A0;


byte zero = 0x00;
unsigned long timer;
//for temperature and humidity
byte digit0 = 9;
byte digit1 = 10;
byte digit2 = 12;
byte digit3 = 13;
byte sevenSegmentPins[] = {2, 3, 4, 5, 6, 7, 8};
byte sevenSegment[12][7] =
{
  { 1, 1, 1, 1, 1, 1, 0 }, // = 0
  { 0, 1, 1, 0, 0, 0, 0 }, // = 1
  { 1, 1, 0, 1, 1, 0, 1 }, // = 2
  { 1, 1, 1, 1, 0, 0, 1 }, // = 3
  { 0, 1, 1, 0, 0, 1, 1 }, // = 4
  { 1, 0, 1, 1, 0, 1, 1 }, // = 5
  { 1, 0, 1, 1, 1, 1, 1 }, // = 6
  { 1, 1, 1, 0, 0, 0, 0 }, // = 7
  { 1, 1, 1, 1, 1, 1, 1 }, // = 8
  { 1, 1, 1, 0, 0, 1, 1 }, // = 9
  { 0, 1, 1, 0, 1, 1, 1 }, // = H
  { 0, 0, 0, 1, 1, 1, 1 } // = t
};

void setup()
{    //clock
    dht.begin();
    Wire.begin();
    int displayType = COMMON_CATHODE;
    int digit4 = 14; //Pino Digito1 do display
    int digit5 = 15; //Pino Digito2 do display
    int digit6 = 16; //Pino Digito3 do display
    int digit7 = 17; //Pino Digito4 do display

    int segA = 22; //Pino segmento A
    int segB = 23; //Pino segmento B
    int segC = 24; //Pino segmento C
    int segD = 25; //Pino segmento D
    int segE = 26; //Pino segmento E
    int segF = 27; //Pino segmento F
    int segG = 28; //Pino segmento G
    int segDP = 29; //Pino segmento H
    int numberOfDigits = 4;
    display7seg.Begin(displayType, numberOfDigits, digit4, digit5, digit6, digit7, segA, segB, segC, segD, segE, segF, segG, segDP);
    display7seg.SetBrightness(100);
    timer = millis();
    pinMode(buttonPin, INPUT);
    pinMode(buttonPin2, INPUT);
    //temperature
    pinMode(digit0, OUTPUT); //pin 9
    pinMode(digit1, OUTPUT); //pin 10
    pinMode(digit2, OUTPUT); //pin 12
    pinMode(digit3, OUTPUT); //pin 13
    for (int i = 0; i < 7; i++)
    {
      pinMode(sevenSegmentPins[i], OUTPUT);
    }
    //digitalWrite(dotPin, HIGH);
    digitalWrite(digit0, HIGH);
    digitalWrite(digit1, HIGH);
    digitalWrite(digit2, HIGH);
    digitalWrite(digit3, HIGH);
 }
 
 //funcao segmentwrite
void segmentWrite(byte digit)
  {
    byte pin = 2;
    for (byte i = 0; i < 7; ++i)
    {
      digitalWrite(pin, sevenSegment[digit][i]);
      ++pin;
    }
  }
  
void twoSegmentWrite(int digit)
{
   int digit_1 = digit / 10;
   int digit_2 = digit % 10;

   digitalWrite(digit0, LOW);
   segmentWrite(digit_1);
   delay(5);
   digitalWrite(digit0, HIGH);
   digitalWrite(digit1, LOW);
   segmentWrite(digit_2);
   delay(5);
   digitalWrite(digit1, HIGH);
}

void twoSegmentWrite1(int digit)
{
    int digit_1 = digit / 10;
    int digit_2 = digit % 10;

    digitalWrite(digit2, LOW);
    segmentWrite(digit_1);
    delay(5);
    digitalWrite(digit2, HIGH);
    digitalWrite(digit3, LOW);
    segmentWrite(digit_2);
    delay(5);
    digitalWrite(digit3, HIGH);
}

void twoSegmentWriteWord (int digit)
{
    digitalWrite(digit0, LOW);
    digitalWrite(digit1, HIGH);
    segmentWrite(digit);
    delay(5);
    digitalWrite(digit1, HIGH);
}

void loop()
{ //clock
    char tempString[10]; //Used for sprintf
    Wire.beginTransmission(DS1307_ADDRESS);
    Wire.write(zero);
    Wire.endTransmission();
    Wire.requestFrom(DS1307_ADDRESS, 7);
    int segundos = ConverteparaDecimal(Wire.read());
    int minutos = ConverteparaDecimal(Wire.read());
    int horas = ConverteparaDecimal(Wire.read() & 0b111111);
    sprintf(tempString, "%02d%02d", horas, minutos);
    display7seg.DisplayString(tempString, 3);

    buttonState = digitalRead(buttonPin);
    if (buttonState == HIGH)
    {
      delay(150);
      if (buttonState == HIGH)
      {
        minutos_ = incrementa(minutos);
        SelecionaDataeHora();
      }
    }
    buttonState = digitalRead(buttonPin2);
    if (buttonState == HIGH)
    {
      delay(150);
      if (buttonState == HIGH)
      {
        horas_ = incrementa2(horas);
        SelecionaDataeHora();
      }
    } 
    //get the values of temperature and humidity
float h = dht.readHumidity();
float ta = dht.readTemperature();

twoSegmentWrite(h);
  for (int t=0; t<=99; t++)
    {
     twoSegmentWrite(h);
     twoSegmentWrite1(ta);
    }
} //this lines is just for get hours correctly
void SelecionaDataeHora()
{
      byte segundos = 5;
      byte minutos = minutos_;
      byte horas = horas_;
      Wire.beginTransmission(DS1307_ADDRESS);
      Wire.write(zero);

      Wire.write(ConverteParaBCD(segundos));
      Wire.write(ConverteParaBCD(minutos));
      Wire.write(ConverteParaBCD(horas));
      Wire.write(zero);
      Wire.endTransmission();
}
    
byte ConverteParaBCD(byte val)
{
      //Converte o número de decimal para BCD
      return ( (val / 10 * 16) + (val % 10) );
}

byte ConverteparaDecimal(byte val)
{
  //Converte de BCD para decimal
  return ( (val / 16 * 10) + (val % 16) );
}

int incrementa (int minutos_)
{
  minutos_++;
  if (minutos_ >= 60)
  {
    minutos_ = 0;
    horas_++;
  }
  return minutos_;
}

int incrementa2 (int horas_)
{
  horas_++;
  return horas_;
}

A table is not the right way to post code. I don't think you meant it to be italic did you? Go back and change it to use code tags ([code ] [/code ] or </> in the menu).

Like this mate ?

_Kuga:
I put together two codes and when i upload it to my arduino it only shows the temperature. Can anyone help me so i can resolve this problem?

So you initially had two working example codes? Then you "combined" them to your own non-working code?

And we shall help without knowing anything about the two working codes?

This code at least looks suspicious to me as if you have coded something which you did not want to code:;

  for (int t=0; t<=99; t++)
    {
     twoSegmentWrite(h);
     twoSegmentWrite1(ta);
    }

In your loop you are always doing a loop 99 times:

  • write humidity to 7segments
  • write temperature to 7segments

So after the loop is finished, the last value written is ta/temperature and that's what you can read on the display?

So where is the problem?

This problem is solved. Thanks to those who helped me. I'm still a begginer so i can ask some stupid questions..

I solved the problem, now i just don't know how to make it always showing, without blink to retrieve a value.

i just don't know how to make it always showing, without blink to retrieve a value.

I don't know what you mean by this.

I will try to explain it.

The arduino pick the value from DHT11 but when it sends to displays it have a "refresh" time that shut down the displays. they stay off for 1 sec and i don't know how to remove that time.

Did you get it ? xD

thanks for the help !

_Kuga:
This problem is solved. Thanks to those who helped me. I'm still a begginer so i can ask some stupid questions..

I solved the problem, now i just don't know how to make it always showing, without blink to retrieve a value.

So the meaning of "I solved the problem" seems to be: You solved ONE problem and replaced it with ANOTHER problem?!

Perhaps somebody might give a hint if you post the latest code including the one-problem-replaces-the-other-problem "solution".

Not like.
This isnt a "problem" i just want the displays to stay always on and i don't want them to blink when receive new values. Just that. I don't think the problem is from my code but actually is funcion from the library.

did you get it?

Display shows 60 , after 3 seconds display blink with new information or the same.

_Kuga:
I don't think the problem is from my code

I think it is caused by your code.

_Kuga:
...but actually is funcion from the library.

Very unlikely.