7 segment bubble display problems


hi,
i using 7 segment bubble display shown here using thermistor read temperature. thermistor side of things works fine, display update i'm having confusion with.

i followed code @ link , wanted change updatedisp() method sit in while loop waiting display time elapse (which same using delay() call) code other things while checked see if update time had elapsed.

so have changed printdisp() method have attached below @ line 113 , lines 123-127.
however display updates extremely quickly, so flickering, though method call on line 105 tells it should update every 1000ms.

here's code:

code: [select]
/*
* created rui santos, http://randomnerdtutorials.com
* modified by: raphango
* still more changes by: rccursach 2014
* temperature sensor displayed on 4 digit 7 segment common cathode
* 2013
* small portion sparkfun's sevseg libray https://github.com/sparkfun/sevseg
* sparkfun, nathan seidle, 2012 (beerware license). based on http://arduino.cc/playground/main/sevensegmentlibrary dean reading, 2012.
*/

#include <thermistor4.h>

const int digitpins[4] = {9,10,11,12}; //4 common cathode pins of display.
const int clockpin = 2;    //74hc595 pin 2
const int latchpin = 3;    //74hc595 pin 3
const int datapin = 4;     //74hc595 pin 44
const int temppin = 3;     //thermistor temperature sensor pin

unsigned long ti = 0;
unsigned long tf = 0;

//as seen on sparkfun's sevseg library
const byte digit[10] =      //seven segment digits
{
  0b11111100, // 0
  0b01100000, // 1
  0b11011010, // 2
  0b11110010, // 3
  0b01100110, // 4
  0b10110110, // 5
  0b10111110, // 6
  0b11100000, // 7
  0b11111110, // 8
  0b11110110  // 9
};

#define thermistorpin 3

double tempread; 

//define variables we'll connecting to
double setpoint, input, output;
//specify links , initial tuning parameters
double kp = 100, ki = 0.15, kd = 1;

// instance of thermistor object
thermistor4 thermistor;
//various temp variables testing.
unsigned int i, adcaverage;

/////////////////////// used measuring vcc
long sum;
double average;
///////////////////

int digitbuffer[4] = {0};
int digitscan = 0;
float tempc;

void setup(){       
  serial.begin(9600);       
  for(int i=0;i<4;i++)
  {
    pinmode(digitpins[i],output);
  }
  pinmode(temppin, input);
  pinmode(latchpin, output);
  pinmode(clockpin, output);
  pinmode(datapin, output);
  serial.begin(9600);

  float vccvalue = readvcc(); //measurevcc();
 
  printdisp(vccvalue, 1000);

  thermistor.pin = thermistorpin; //set pin number.

  thermistor.setup(); //sets analog read pin internal avr.

  //pow() used elsewhere might used here.
  thermistor.bitresolution = pow(2, 10) - 1; //atmega's have 10bit adc (2^10-1).

  //thermistor.voltagesupply = average;   //4.885;   //4.4481;  // metered supply across voltage divider
  thermistor.voltagesupply = vccvalue;   //4.885;   //4.4481;  // metered supply across voltage divider
 
  thermistor.resistancefixed = 8250;   ///fixed resistor in divider. measured in ohms. meter accuracy.

  thermistor.offset = 0.0; //adjust temperature in kelvin or down little account unforseen variations.

  // steinhart-hart coefficients. taken datasheet provided manufacturer
  thermistor.steinharta1 = 5.99357907117746e-004;   // first steinhart-hart coefficient.
  thermistor.steinharta2 = 2.31247850239102e-004;   // second steinhart-hart coefficient.
  thermistor.steinharta3 = 5.61924102167737e-008;   // third steinhart-hart coefficient.
  thermistor.steinharta4 = 3.23406799250025e-011;   // fourth steinhart-hart coefficient.

}


void loop(){
  thermistor.readcalculate(3);
 
  thermistor.readadc(analogread (thermistor.pin));
  tempread = thermistor.getfarenheit();

  printdisp(tempread, 1000);
  thermistor.voltagesupply = readvcc();
}




void printdisp(float value, int msec) {
  tf = millis();
  cleardisp();
  //int digitthree, digittwo, digitone, digitzero;
  digitbuffer[3] = int(value / 100); // return hundreds value
  digitbuffer[2] = int(((value - (digitbuffer[3] * 100))) / 10);  // return tens value
  digitbuffer[1] = int ((value - (digitbuffer[3] * 100) - (digitbuffer[2] * 10))); // return units value
  digitbuffer[0] = int ((value - (digitbuffer[3] * 100) - (digitbuffer[2] * 10) - (digitbuffer[1])) * 10);  // return first decimal place value

 
  //get displayed until msec milliseconds passed
  //unsigned long ti = millis();
  ti = millis();
  if(tf-ti > msec){
    tf = ti;
    updatedisp();
  }
}

//writes temperature on display
void updatedisp() {
  (int = 0; < 4; i++) {
    cleardisp();
    digitalwrite(digitpins[i], low); //changed low turning leds on.

    if (i == 1) //add decimal dot
      shiftout(datapin, clockpin, lsbfirst, digit[digitbuffer[i]] | 0b00000001);
    else
      shiftout(datapin, clockpin, lsbfirst, digit[digitbuffer[i]]);

    digitalwrite(latchpin, high);
    digitalwrite(latchpin, low);

    delay(5); //if not delayed, digits seen brurry, if value 8 migth see display frickering.
  }
}

void cleardisp() {
  (byte j = 0; j < 4; j++) {
    digitalwrite(digitpins[j], high); // turns display off. changed high
  }
}


long readvcc() {
  long result;
  // read 1.1v reference against avcc
  admux = _bv(refs0) | _bv(mux3) | _bv(mux2) | _bv(mux1);
  delay(2); // wait vref settle
  adcsra |= _bv(adsc); // convert
  while (bit_is_set(adcsra, adsc));
  result = adcl;
  result |= adch << 8;
  result = 1125300l / result; // back-calculate avcc in mv
  return result;
}

i've made progress. updates display once per second now, flashes goes dark rest of second.
heres current code:
code: [select]
/*
* created rui santos, http://randomnerdtutorials.com
* modified by: raphango
* still more changes by: rccursach 2014
* temperature sensor displayed on 4 digit 7 segment common cathode
* 2013
* small portion sparkfun's sevseg libray https://github.com/sparkfun/sevseg
* sparkfun, nathan seidle, 2012 (beerware license). based on http://arduino.cc/playground/main/sevensegmentlibrary dean reading, 2012.
*/

#include <thermistor4.h>

const int digitpins[4] = {9,10,11,12}; //4 common cathode pins of display.
const int clockpin = 2;    //74hc595 pin 2
const int latchpin = 3;    //74hc595 pin 3
const int datapin = 4;     //74hc595 pin 44
const int temppin = 3;     //thermistor temperature sensor pin

long ti = 0;
long tf = 0;

//as seen on sparkfun's sevseg library
const byte digit[10] =      //seven segment digits
{
  0b11111100, // 0
  0b01100000, // 1
  0b11011010, // 2
  0b11110010, // 3
  0b01100110, // 4
  0b10110110, // 5
  0b10111110, // 6
  0b11100000, // 7
  0b11111110, // 8
  0b11110110  // 9
};

#define thermistorpin 3

double tempread; 
long temptimenow = 0;
long temptimelast = 0;

//define variables we'll connecting to
double setpoint, input, output;
//specify links , initial tuning parameters
double kp = 100, ki = 0.15, kd = 1;

// instance of thermistor object
thermistor4 thermistor;
//various temp variables testing.
unsigned int i, adcaverage;

/////////////////////// used measuring vcc
long sum;
double average;
///////////////////

int digitbuffer[4] = {0};
int digitscan = 0;
float tempc;

void setup(){       
  serial.begin(9600);       
  for(int i=0;i<4;i++)
  {
    pinmode(digitpins[i],output);
  }
  pinmode(temppin, input);
  pinmode(latchpin, output);
  pinmode(clockpin, output);
  pinmode(datapin, output);
  serial.begin(9600);

  float vccvalue = readvcc(); //measurevcc();
 
  printdisp(vccvalue, 1000);

  thermistor.pin = thermistorpin; //set pin number.

  thermistor.setup(); //sets analog read pin internal avr.

  //pow() used elsewhere might used here.
  thermistor.bitresolution = pow(2, 10) - 1; //atmega's have 10bit adc (2^10-1).

  //thermistor.voltagesupply = average;   //4.885;   //4.4481;  // metered supply across voltage divider
  thermistor.voltagesupply = vccvalue;   //4.885;   //4.4481;  // metered supply across voltage divider
 
  thermistor.resistancefixed = 8250;   ///fixed resistor in divider. measured in ohms. meter accuracy.

  thermistor.offset = 0.0; //adjust temperature in kelvin or down little account unforseen variations.

  // steinhart-hart coefficients. taken datasheet provided manufacturer
  thermistor.steinharta1 = 5.99357907117746e-004;   // first steinhart-hart coefficient.
  thermistor.steinharta2 = 2.31247850239102e-004;   // second steinhart-hart coefficient.
  thermistor.steinharta3 = 5.61924102167737e-008;   // third steinhart-hart coefficient.
  thermistor.steinharta4 = 3.23406799250025e-011;   // fourth steinhart-hart coefficient.

}


void loop(){
  thermistor.readcalculate(3);
 
  thermistor.readadc(analogread (thermistor.pin));
  tempread = thermistor.getfarenheit();
  temptimenow = millis();
 
  printdisp(tempread, 1000);
  if(temptimenow - temptimelast > 1000){
    serial.println("gets here");
    updatedisp();
    temptimelast = temptimenow;
  }

 
  thermistor.voltagesupply = readvcc();
 
}




void printdisp(float value, int msec) {
  //tf = millis();
  cleardisp();
  //int digitthree, digittwo, digitone, digitzero;
  digitbuffer[3] = int(value / 100); // return hundreds value
  digitbuffer[2] = int(((value - (digitbuffer[3] * 100))) / 10);  // return tens value
  digitbuffer[1] = int ((value - (digitbuffer[3] * 100) - (digitbuffer[2] * 10))); // return units value
  digitbuffer[0] = int ((value - (digitbuffer[3] * 100) - (digitbuffer[2] * 10) - (digitbuffer[1])) * 10);  // return first decimal place value

}

//writes temperature on display
void updatedisp() {
  (int = 0; < 4; i++) {
    cleardisp();
    digitalwrite(digitpins[i], low); //changed low turning leds on.

    if (i == 1) //add decimal dot
      shiftout(datapin, clockpin, lsbfirst, digit[digitbuffer[i]] | 0b00000001);
    else
      shiftout(datapin, clockpin, lsbfirst, digit[digitbuffer[i]]);

    digitalwrite(latchpin, high);
    digitalwrite(latchpin, low);

    delay(5); //if not delayed, digits seen brurry, if value 8 migth see display frickering.
  }
}

void cleardisp() {
  (byte j = 0; j < 4; j++) {
    digitalwrite(digitpins[j], high); // turns display off. changed high
  }
}


long readvcc() {
  long result;
  // read 1.1v reference against avcc
  admux = _bv(refs0) | _bv(mux3) | _bv(mux2) | _bv(mux1);
  delay(2); // wait vref settle
  adcsra |= _bv(adsc); // convert
  while (bit_is_set(adcsra, adsc));
  result = adcl;
  result |= adch << 8;
  result = 1125300l / result; // back-calculate avcc in mv
  return result;
}



Arduino Forum > Using Arduino > Displays > 7 segment bubble display problems


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???