marrc
Junior Member level 2

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:
</adafruit_max31856.h>
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 <adafruit_max31856.h> // 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;
}
}