+ Post New Thread
Results 1 to 10 of 10
  1. #1
    Junior Member level 2
    Points: 615, Level: 5

    Join Date
    Mar 2017
    Location
    india
    Posts
    21
    Helped
    0 / 0
    Points
    615
    Level
    5

    problem with arduino

    hi guys!

    I have recently put together a device that can measure and display temperature.

    i am using 2 seven segment displays, one small display for displaying some parameters and 1 large display (4inch height) for displaying the temperature.

    now the problem with the large display is that the right most digit is extra bright while the left three are very dim.

    i am pretty sure its not a wiring issue or hardware problem as i have run a test code that displays all 4 digits with equal brightness on same display.

    please help me so that all 4 digits of large display are equally bright.

    P.S:I am a newbe to arduino so forgive me if my code is a bit messy.

    cheers,
    marrc

    my code is as follows:
    Code:
     
    #include  // inclusion of temperature module library
    int latchPin1=2;  //for small display
    int dataPin1=3;
    int clockPin1=4;
    int D5=5,D6=6,c=0,switchState,dig,dig_1,dig_2,dig_3,dig_4;
    float c1;
    int initialstateD5,finalstateD5,initialstateD6,finalstateD6;
    int latchPin=7;  //for large display
    int dataPin=8;
    int clockPin=9;
    int temp_sens, temp_read, temp_hyst, dig_5, dig_6, dig_7, dig_8;
    //temp_sens=temperature reading of thermocouple, temp_read=temperature on the display, temp_hyst=plateau hysteresis teperature (variable),
    //dig_1, dig_2, dig_3, dig_4 = displayed digits from left to right
    int dev_pc = 0; // plateau temperature deviation margin percentage (+/- %)
    int temp_seek = 400; // temp_seek=tmeperature when plateau detection is initiated
    float time_hyst = c1;//=1.8; // plateau wait time (s)
    int temp_offset=c; // this value will be subtracted from the actual reading with proper -/+ sign
    unsigned long time_res; // time_res=plateau reset time (variable) (ms)
    int refresh = 1; // refresh= display hold time (ms)
    Adafruit_MAX31856 max = Adafruit_MAX31856(10, 11, 12, 13); // CS, SDI, SDO, SCK pins on the module
    
    void setup()
    {
     
      max.begin(); // temperature module initiation
      max.setThermocoupleType(MAX31856_TCTYPE_S); // thermocouple type selection
      pinMode(A3, INPUT_PULLUP); // enabling internal pullup resistance on the Arduino
      pinMode(A5, OUTPUT);
      pinMode (latchPin,OUTPUT);
      pinMode (dataPin,OUTPUT);
      pinMode (clockPin,OUTPUT);
      Serial.begin(9600);
      pinMode (latchPin1,OUTPUT);
    pinMode (dataPin1,OUTPUT);
    pinMode (clockPin1,OUTPUT);
    pinMode (D5,INPUT);  //increment pin
    pinMode (D6,INPUT);  // decrement pin
    pinMode (A4,INPUT);  //counter select
    }
    
    void loop()
    {
      switchState= digitalRead(A4);
      if(switchState==LOW) // whole number counter if a4 low
      {
      // put your main code here, to run repeatedly:
      finalstateD5=digitalRead(D5);
      if(finalstateD5 != initialstateD5)
       {
      delay(1);
      finalstateD5=digitalRead(D5);
      if (finalstateD5==HIGH)
      c++;
      Serial.println(c);
      initialstateD5=finalstateD5;
       }
       
    dig_1 = c/1000;
    dig_2 = (c - 1000 * dig_1) / 100;                     
    dig_3 = (c - 1000 * dig_1 - 100 * dig_2) / 10;    
    dig_4 = c - 1000 * dig_1 - 100 * dig_2 - 10 * dig_3; 
    displayDigit();  //displays offset
    
      finalstateD6=digitalRead(D6);
      if(finalstateD6 != initialstateD6 )
       {
      delay(1);
      finalstateD6=digitalRead(D6);
      if (finalstateD6==HIGH)
      c--;
      initialstateD6=finalstateD6;
       }
       
    dig_1 = c/1000;
    dig_2 = (c - 1000 * dig_1) / 100;                    
    dig_3 = (c - 1000 * dig_1 - 100 * dig_2) / 10;    
    dig_4 = c - 1000 * dig_1 - 100 * dig_2 - 10 * dig_3; 
    displayDigit();
      }
      else
      if (switchState=HIGH) // decimal counter if a4 high
      {
      finalstateD5=digitalRead(D5);
      if(finalstateD5 != initialstateD5)
       {
      delay(1);
      finalstateD5=digitalRead(D5);
      if (finalstateD5==HIGH)
      c1=c1+0.01;
      Serial.println(c1);
     
      initialstateD5=finalstateD5;
       }
       
    dig_1 = c1*100/1000;
    dig_2 = (c1*100 - 1000 * dig_1) / 100;                    
    dig_3 = (c1*100 - 1000 * dig_1 - 100 * dig_2) / 10;   
    dig_4 = c1*100 - 1000 * dig_1 - 100 * dig_2 - 10 * dig_3; 
    displayDigit1(); //displays plateau time
    
      finalstateD6=digitalRead(D6);
      if(finalstateD6 != initialstateD6 )
       {
      delay(1);
      finalstateD6=digitalRead(D6);
      if (finalstateD6==HIGH)
      c1=c1-0.01;
      initialstateD6=finalstateD6;
       }
       
    dig_1 = c1*100/1000;
    dig_2 = (c1*100 - 1000 * dig_1) / 100;                    
    dig_3 = (c1*100 - 1000 * dig_1 - 100 * dig_2) / 10;   
    dig_4 = c1*100 - 1000 * dig_1 - 100 * dig_2 - 10 * dig_3; 
    displayDigit1();
      }
     
      {
        Serial.println("OK");
        digitalWrite(A2, HIGH); // green LED on
       if(digitalRead(A3)==HIGH) // checking if digital pin 17 is high (high if Red LED is off)
      temp_sens = max.readThermocoupleTemperature(); // max.readThermocoupleTemperature()=temperature from module (updated if the condition is met)
      else                                // checking if digital pin 17 is high (low if Red LED is on)
      temp_sens != max.readThermocoupleTemperature(); // max.readThermocoupleTemperature()=temperature from module (not updated if the condition is not met)
      if (temp_sens <= temp_seek) // checking if temperaure is lower than plateau initiation temperature
      {
        digitalWrite(A0, LOW); // red LED off
        digitalWrite(A1, LOW); // amber LED off
        digitalWrite(A2, HIGH); // green LED on, indicating current temperature is lower than temp_seek
      }
      else
      {
        digitalWrite(A0, LOW); // red LED off
        digitalWrite(A1, HIGH); // amber LED on, indicating plateau detection is active
        digitalWrite(A2, LOW); // green LED off
    
        if (temp_sens <= (100 + dev_pc) * temp_hyst / 100 && temp_sens >= (100 - dev_pc) * temp_hyst / 100) // checking if the temperature within the platuea's range
        {
          if (millis() > 1000 * c1) // checking if the waiting time has elapsed
          {
            digitalWrite(A0, HIGH); // red LED on, indicating a plateau is detected
            digitalWrite(A1, LOW); // amber LED off
            digitalWrite(A2, LOW); // green LED off
            digitalWrite(A5, HIGH); // for red relay
          }
        }
        else
        {
          time_res = millis(); // redefining the value of wait time for further iterations
          digitalWrite(A0, LOW); // red LED off
        digitalWrite(A1, HIGH); // amber LED on, indicating plateau detection is active
        digitalWrite(A2, LOW); // green LED off
          temp_hyst = temp_sens; // redefining the value of hysteresis temperature for further iterations
        }
      }
      temp_read = temp_sens-c;
      if (temp_read < 0)
        temp_read = 0;
      if (temp_read > 9999)
        temp_read = 9999;
      dig_5 = temp_read / 1000;                                     // digit 1 temperature value
      dig_6 = (temp_read - 1000 * dig_5) / 100;                     // digit 2 temperature value
      dig_7 = (temp_read - 1000 * dig_5 - 100 * dig_6) / 10;        // digit 3 temperature value
      dig_8 = temp_read - 1000 * dig_5 - 100 * dig_6 - 10 * dig_7;  // digit 4 temperature value
      }
      Serial.println(dig_6);
    getDigit1(dig_5);  // gets digits for large display
    digitalWrite(latchPin,LOW);
    shiftOut(dataPin,clockPin,MSBFIRST,128+63 >> 8);// shifting out zeros
    shiftOut(dataPin,clockPin,MSBFIRST,128+dig);// displaying digit
    digitalWrite(latchPin,HIGH);
    delay(1);
    getDigit1(dig_6);
    Serial.println(dig);
    digitalWrite(latchPin,LOW);
    shiftOut(dataPin,clockPin,MSBFIRST,256+63 >> 8);
    shiftOut(dataPin,clockPin,MSBFIRST,256+dig);
    digitalWrite(latchPin,HIGH);
    delay(1);
    getDigit1(dig_7);
    digitalWrite(latchPin,LOW);
    shiftOut(dataPin,clockPin,MSBFIRST,512+63 >> 8);
    shiftOut(dataPin,clockPin,MSBFIRST,512+dig);
    digitalWrite(latchPin,HIGH);
    delay(1);
    getDigit1(dig_8);
    digitalWrite(latchPin,LOW);
    shiftOut(dataPin,clockPin,MSBFIRST,1024+63 >> 8);
    shiftOut(dataPin,clockPin,MSBFIRST,1024+dig);
    digitalWrite(latchPin,HIGH);
    delay(1);
    }
    void displayDigit()  //displays offset (small display)
    {
      getDigit(dig_1);
      if (c<=-99 && c>=-999)
      dig=191;
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,256+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,256+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
      getDigit(dig_2);
      if(c<=-9 && c>=-99)
      dig=191;
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,512+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,512+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
      getDigit(dig_3);
      if(c<0 && c>=-9)
      dig=191;
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,1024+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,1024+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
      getDigit(dig_4);
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,2048+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,2048+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
    
    }
    void displayDigit1()  //displays plateau time (small display)
    {
      getDigit(dig_1);
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,256+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,256+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
      getDigit(dig_2);
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,512-128+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,512-128+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
      getDigit(dig_3);
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,1024+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,1024+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
      getDigit(dig_4);
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,2048+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,2048+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
    
    }
    void getDigit(int digit)
    {
    if (digit<0)
    digit=-digit;
      switch (digit)
      {
       case 0:
      //dig=64;
      dig=192; //dig+128 for common anode dispaly
      break;
      case 1:
      //dig=121;
      dig=249;
      break;
      case 2:
      //dig=36;
      dig=164;
      break;
      case 3:
      //dig=48;
      dig=176;
      break;
      case 4:
      //dig=25;
      dig=153;
      break;
      case 5:
     // dig=18;
     dig=146;
      break;
      case 6:
      //dig=2;
      dig=130;
      break;
      case 7:
      //dig=120;
      dig=248;
      break;
      case 8:
      //dig=0;
      dig=128;
      break;
      case 9:
      //dig=24;
      dig=152;
      break;
        }
    }
    void getDigit1(int digit)
    {
    
      switch (digit)
      {
      case 0:
      dig=63; //for common catode display
       break;
      case 1:
      dig=6;
      break;
      case 2:
      dig=91;
      break;
      case 3:
      dig=79;
      break;
      case 4:
      dig=102;
      break;
      case 5:
      dig=109;
      break;
      case 6:
      dig=125;
      break;
      case 7:
      dig=7;
      break;
      case 8:
      dig=127;
      break;
      case 9:
      dig=103;
      break;
      }
    }

  2. #2
    Junior Member level 2
    Points: 615, Level: 5

    Join Date
    Mar 2017
    Location
    india
    Posts
    21
    Helped
    0 / 0
    Points
    615
    Level
    5

    Re: problem with arduino

    this is code i am using (some parts were missing):
    Code:
    
     
    #include  // inclusion of temperature module library
    int latchPin1=2;  //for small display
    int dataPin1=3;
    int clockPin1=4;
    int D5=5,D6=6,c=0,switchState,dig,dig_1,dig_2,dig_3,dig_4;
    float c1;
    int initialstateD5,finalstateD5,initialstateD6,finalstateD6;
    int latchPin=7;  //for large display
    int dataPin=8;
    int clockPin=9;
    int temp_sens, temp_read, temp_hyst, dig_5, dig_6, dig_7, dig_8;
    //temp_sens=temperature reading of thermocouple, temp_read=temperature on the display, temp_hyst=plateau hysteresis teperature (variable),
    //dig_1, dig_2, dig_3, dig_4 = displayed digits from left to right
    int dev_pc = 0; // plateau temperature deviation margin percentage (+/- %)
    int temp_seek = 400; // temp_seek=tmeperature when plateau detection is initiated
    float time_hyst = c1;//=1.8; // plateau wait time (s)
    int temp_offset=c; // this value will be subtracted from the actual reading with proper -/+ sign
    unsigned long time_res; // time_res=plateau reset time (variable) (ms)
    int refresh = 1; // refresh= display hold time (ms)
    Adafruit_MAX31856 max = Adafruit_MAX31856(10, 11, 12, 13); // CS, SDI, SDO, SCK pins on the module
    
    void setup()
    {
     
      max.begin(); // temperature module initiation
      max.setThermocoupleType(MAX31856_TCTYPE_S); // thermocouple type selection
      pinMode(A3, INPUT_PULLUP); // enabling internal pullup resistance on the Arduino
      pinMode(A5, OUTPUT);
      pinMode (latchPin,OUTPUT);
      pinMode (dataPin,OUTPUT);
      pinMode (clockPin,OUTPUT);
      Serial.begin(9600);
      pinMode (latchPin1,OUTPUT);
    pinMode (dataPin1,OUTPUT);
    pinMode (clockPin1,OUTPUT);
    pinMode (D5,INPUT);  //increment pin
    pinMode (D6,INPUT);  // decrement pin
    pinMode (A4,INPUT);  //counter select
    }
    
    void loop()
    {
      switchState= digitalRead(A4);
      if(switchState==LOW) // whole number counter if a4 low
      {
      // put your main code here, to run repeatedly:
      finalstateD5=digitalRead(D5);
      if(finalstateD5 != initialstateD5)
       {
      delay(1);
      finalstateD5=digitalRead(D5);
      if (finalstateD5==HIGH)
      c++;
      Serial.println(c);
      initialstateD5=finalstateD5;
       }
       
    dig_1 = c/1000;
    dig_2 = (c - 1000 * dig_1) / 100;                      
    dig_3 = (c - 1000 * dig_1 - 100 * dig_2) / 10;         
    dig_4 = c - 1000 * dig_1 - 100 * dig_2 - 10 * dig_3; 
    displayDigit();  //displays offset
    
      finalstateD6=digitalRead(D6);
      if(finalstateD6 != initialstateD6 )
       {
      delay(1);
      finalstateD6=digitalRead(D6);
      if (finalstateD6==HIGH)
      c--;
      initialstateD6=finalstateD6;
       }
       
    dig_1 = c/1000;
    dig_2 = (c - 1000 * dig_1) / 100;                      
    dig_3 = (c - 1000 * dig_1 - 100 * dig_2) / 10;         
    dig_4 = c - 1000 * dig_1 - 100 * dig_2 - 10 * dig_3; 
    displayDigit();
      }
      else
      if (switchState=HIGH) // decimal counter if a4 high
      {
      finalstateD5=digitalRead(D5);
      if(finalstateD5 != initialstateD5)
       {
      delay(1);
      finalstateD5=digitalRead(D5);
      if (finalstateD5==HIGH)
      c1=c1+0.01;
      Serial.println(c1);
     
      initialstateD5=finalstateD5;
       }
       
    dig_1 = c1*100/1000;
    dig_2 = (c1*100 - 1000 * dig_1) / 100;                      
    dig_3 = (c1*100 - 1000 * dig_1 - 100 * dig_2) / 10;         
    dig_4 = c1*100 - 1000 * dig_1 - 100 * dig_2 - 10 * dig_3; 
    displayDigit1(); //displays plateau time
    
      finalstateD6=digitalRead(D6);
      if(finalstateD6 != initialstateD6 )
       {
      delay(1);
      finalstateD6=digitalRead(D6);
      if (finalstateD6==HIGH)
      c1=c1-0.01;
      initialstateD6=finalstateD6;
       }
       
    dig_1 = c1*100/1000;
    dig_2 = (c1*100 - 1000 * dig_1) / 100;                      
    dig_3 = (c1*100 - 1000 * dig_1 - 100 * dig_2) / 10;        
    dig_4 = c1*100 - 1000 * dig_1 - 100 * dig_2 - 10 * dig_3; 
    displayDigit1();
      }
      uint8_t fault = max.readFault();
      if (fault & MAX31856_FAULT_OPEN)
      {
        Serial.println("open");
        digitalWrite(A0, LOW); // red LED off
        digitalWrite(A1, LOW); // amber relay off
        digitalWrite(A2, LOW); // green relay off
        digitalWrite(A5, LOW); // red relay off
        temp_sens != max.readThermocoupleTemperature(); // max.readThermocoupleTemperature()=temperature from module (not updated if the condition is not met)
      }
      else
      {
        Serial.println("OK");
        digitalWrite(A2, HIGH); // green LED on
       if(digitalRead(A3)==HIGH) // checking if digital pin 17 is high (high if Red LED is off)
      temp_sens = max.readThermocoupleTemperature(); // max.readThermocoupleTemperature()=temperature from module (updated if the condition is met)
      else                                // checking if digital pin 17 is high (low if Red LED is on)
      temp_sens != max.readThermocoupleTemperature(); // max.readThermocoupleTemperature()=temperature from module (not updated if the condition is not met)
      if (temp_sens <= temp_seek) // checking if temperaure is lower than plateau initiation temperature
      {
        digitalWrite(A0, LOW); // red LED off
        digitalWrite(A1, LOW); // amber LED off
        digitalWrite(A2, HIGH); // green LED on, indicating current temperature is lower than temp_seek
      }
      else
      {
        digitalWrite(A0, LOW); // red LED off
        digitalWrite(A1, HIGH); // amber LED on, indicating plateau detection is active
        digitalWrite(A2, LOW); // green LED off
    
        if (temp_sens <= (100 + dev_pc) * temp_hyst / 100 && temp_sens >= (100 - dev_pc) * temp_hyst / 100) // checking if the temperature within the platuea's range
        {
          if (millis() - time_res > 1000 * c1) // checking if the waiting time has elapsed
          {
            digitalWrite(A0, HIGH); // red LED on, indicating a plateau is detected
            digitalWrite(A1, LOW); // amber LED off
            digitalWrite(A2, LOW); // green LED off
            digitalWrite(A5, HIGH); // for red relay
          }
        }
        else
        {
          time_res = millis(); // redefining the value of wait time for further iterations
          digitalWrite(A0, LOW); // red LED off
        digitalWrite(A1, HIGH); // amber LED on, indicating plateau detection is active
        digitalWrite(A2, LOW); // green LED off
          temp_hyst = temp_sens; // redefining the value of hysteresis temperature for further iterations
        }
      }
      temp_read = temp_sens-c;
      if (temp_read < 0)
        temp_read = 0;
      if (temp_read > 9999)
        temp_read = 9999;
      dig_5 = temp_read / 1000;                                     // digit 1 temperature value
      dig_6 = (temp_read - 1000 * dig_5) / 100;                     // digit 2 temperature value
      dig_7 = (temp_read - 1000 * dig_5 - 100 * dig_6) / 10;        // digit 3 temperature value
      dig_8 = temp_read - 1000 * dig_5 - 100 * dig_6 - 10 * dig_7;  // digit 4 temperature value
      }
      Serial.println(dig_6);
    getDigit1(dig_5);  // gets digits for temp display
    digitalWrite(latchPin,LOW);
    shiftOut(dataPin,clockPin,MSBFIRST,128+63 >> 8);// shifting out zeros
    shiftOut(dataPin,clockPin,MSBFIRST,128+dig);// displaying digit
    digitalWrite(latchPin,HIGH);
    delay(1);
    getDigit1(dig_6);
    Serial.println(dig);
    digitalWrite(latchPin,LOW);
    shiftOut(dataPin,clockPin,MSBFIRST,256+63 >> 8);
    shiftOut(dataPin,clockPin,MSBFIRST,256+dig);
    digitalWrite(latchPin,HIGH);
    delay(1);
    getDigit1(dig_7);
    digitalWrite(latchPin,LOW);
    shiftOut(dataPin,clockPin,MSBFIRST,512+63 >> 8);
    shiftOut(dataPin,clockPin,MSBFIRST,512+dig);
    digitalWrite(latchPin,HIGH);
    delay(1);
    getDigit1(dig_8);
    digitalWrite(latchPin,LOW);
    shiftOut(dataPin,clockPin,MSBFIRST,1024+63 >> 8);
    shiftOut(dataPin,clockPin,MSBFIRST,1024+dig);
    digitalWrite(latchPin,HIGH);
    delay(1);
    }
    void displayDigit()  //displays offset
    {
      getDigit(dig_1);
      if (c<=-99 && c>=-999)
      dig=191;
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,256+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,256+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
      getDigit(dig_2);
      if(c<=-9 && c>=-99)
      dig=191;
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,512+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,512+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
      getDigit(dig_3);
      if(c<0 && c>=-9)
      dig=191;
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,1024+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,1024+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
      getDigit(dig_4);
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,2048+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,2048+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
    
    }
    void displayDigit1()  //displays plateau time
    {
      getDigit(dig_1);
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,256+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,256+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
      getDigit(dig_2);
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,512-128+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,512-128+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
      getDigit(dig_3);
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,1024+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,1024+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
      getDigit(dig_4);
      digitalWrite(latchPin1,LOW);
      shiftOut(dataPin1,clockPin1,MSBFIRST,2048+dig>>8);
      shiftOut(dataPin1,clockPin1,MSBFIRST,2048+dig);
      digitalWrite(latchPin1,HIGH);
      delay(1);
    
    }
    void getDigit(int digit)
    {
    if (digit<0)
    digit=-digit;
      switch (digit)
      {
       case 0:
      //dig=64;
      dig=192; //dig+128 for common anode dispaly
      break;
      case 1:
      //dig=121;
      dig=249;
      break;
      case 2:
      //dig=36;
      dig=164;
      break;
      case 3:
      //dig=48;
      dig=176;
      break;
      case 4:
      //dig=25;
      dig=153;
      break;
      case 5:
     // dig=18;
     dig=146;
      break;
      case 6:
      //dig=2;
      dig=130;
      break;
      case 7:
      //dig=120;
      dig=248;
      break;
      case 8:
      //dig=0;
      dig=128;
      break;
      case 9:
      //dig=24;
      dig=152;
      break;
        }
    }
    void getDigit1(int digit)
    {
    
      switch (digit)
      {
      case 0:
      dig=63; //for common catode display
       break;
      case 1:
      dig=6;
      break;
      case 2:
      dig=91;
      break;
      case 3:
      dig=79;
      break;
      case 4:
      dig=102;
      break;
      case 5:
      dig=109;
      break;
      case 6:
      dig=125;
      break;
      case 7:
      dig=7;
      break;
      case 8:
      dig=127;
      break;
      case 9:
      dig=103;
      break;
      }
    }
    Last edited by betwixt; 14th November 2019 at 09:49. Reason: changed quotes to code tags



    •   AltAdvertisement

        
       

  3. #3
    Full Member level 3
    Points: 1,856, Level: 10

    Join Date
    Jul 2014
    Location
    West Coast
    Posts
    177
    Helped
    31 / 31
    Points
    1,856
    Level
    10

    Re: problem with arduino

    In a multiplexed display the brightness of a digit reflects the amount of time the digit is on. The program updates the large display at the end of the loop() function leaving digit 8 on while it begins the loop again. This leaves digit 8 on for a long time compared to the other 3 digits. The program needs to display each digit for a more equal amount of time.



  4. #4
    Advanced Member level 3
    Points: 4,993, Level: 16
    Achievements:
    7 years registered
    PA3040's Avatar
    Join Date
    Aug 2011
    Posts
    866
    Helped
    44 / 44
    Points
    4,993
    Level
    16

    Re: problem with arduino

    Digits refresh rate and delay should be equal for every digits

    Save the values in array and use PORTD for Segments



    •   AltAdvertisement

        
       

  5. #5
    Super Moderator
    Points: 29,873, Level: 42
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,916
    Helped
    1129 / 1129
    Points
    29,873
    Level
    42
    Blog Entries
    9

    Re: problem with arduino

    You are cascading the output of one chip into another input, which in an offboard arrangement like using Arduino can mean a degradation in signal quality; By the way, you have not shown any detail of the assembly. In this case, you may want to increase the delay to see if the signal stays stable any longer.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  6. #6
    Junior Member level 2
    Points: 615, Level: 5

    Join Date
    Mar 2017
    Location
    india
    Posts
    21
    Helped
    0 / 0
    Points
    615
    Level
    5

    Re: problem with arduino

    Quote Originally Posted by FenTrac View Post
    In a multiplexed display the brightness of a digit reflects the amount of time the digit is on. The program updates the large display at the end of the loop() function leaving digit 8 on while it begins the loop again. This leaves digit 8 on for a long time compared to the other 3 digits. The program needs to display each digit for a more equal amount of time.
    sorry for the late reply...actually when i dint get any replies i stopped checking. your reply has given me some hope, but can you help me with the code . what you say makes sense but i just couldnt translate it to code.

    cheers,
    marrc



    •   AltAdvertisement

        
       

  7. #7
    Full Member level 3
    Points: 1,856, Level: 10

    Join Date
    Jul 2014
    Location
    West Coast
    Posts
    177
    Helped
    31 / 31
    Points
    1,856
    Level
    10

    Re: problem with arduino

    When updating the large display, the program has a delay of 1 millisecond after latching the data. A quick way to test whether timing is the problem would be to remove the delay after dig_8 is updated. The delays after the preceding 3 digits could be increased. This could give a quick visual test. Using a scope on arduino pin 2 (latchPin1) may be a way of measuring the timing intervals.

    - - - Updated - - -

    Sorry, correction, a scope could be used on Arduino pin 7 (latchPin) for the large display. (LatchPin1 is for the small display).



  8. #8
    Junior Member level 2
    Points: 615, Level: 5

    Join Date
    Mar 2017
    Location
    india
    Posts
    21
    Helped
    0 / 0
    Points
    615
    Level
    5

    Re: problem with arduino

    Quote Originally Posted by FenTrac View Post
    When updating the large display, the program has a delay of 1 millisecond after latching the data. A quick way to test whether timing is the problem would be to remove the delay after dig_8 is updated. The delays after the preceding 3 digits could be increased. This could give a quick visual test. Using a scope on arduino pin 2 (latchPin1) may be a way of measuring the timing intervals.

    - - - Updated - - -

    Sorry, correction, a scope could be used on Arduino pin 7 (latchPin) for the large display. (LatchPin1 is for the small display).
    hi FenTrac,
    increasing the delay does brighten the digits but they also start blinking.
    now it has boiled down to finding a compromise between digit brightness and digits blinking.
    how to make the digits bright and steady?
    cheers,
    marrc



  9. #9
    Full Member level 3
    Points: 1,856, Level: 10

    Join Date
    Jul 2014
    Location
    West Coast
    Posts
    177
    Helped
    31 / 31
    Points
    1,856
    Level
    10

    Re: problem with arduino

    Blinking or flickering results when the digits on and off cycle is slower than the eyes persistence of vision. With 4 digits each one is off 3/4 of the time. Refresh needs to be done at least 20 times per second or so. The best way to get the timing of each digit equal without using delays would be to use a timer interrupt to signal when a digit should be updated. One digit of the display updated at each interrupt. At the interrupt a digit from both the small and large display could be refreshed. Then, all the delays could be removed from both refresh cycles. There is a lot of information on the internet on using arduino timer interrupts such as:
    https://learn.adafruit.com/multi-tas...-part-2/timers.



  10. #10
    Advanced Member level 2
    Points: 3,310, Level: 13
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    658
    Helped
    50 / 50
    Points
    3,310
    Level
    13

    Re: problem with arduino

    It is better to use TimerOne Arduino library and set it up for 2ms or 3ms interrupt and refresh the display in the ISR (interrupt service routine or callback).



--[[ ]]--