how to speed up reaction on 7seg display

Hi there,

I’ve just bought http://www.gravitech.us/7segmentshield.html and tried to sketch something to read on it voltage values coming out from analog pin 0 connected to a potentiometer.

Here’s the code:

#include <Wire.h>
const byte LedDrive = 0x38; // the setup routine runs once when you press reset:
const int lookup[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  Wire.begin();  // join I2C bus (address optional for master)
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  Wire.beginTransmission(LedDrive);
  Wire.write(0);
  Wire.write(B01000111); // init the 7-segment driver - see data sheet 
  Wire.endTransmission();
  
  
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  int voltage = sensorValue * (5.0 / 1023.0)*1000;
  // print out the value you read:
  Serial.println(voltage);
  delay(500);
  
  
  {
  displayNumber(voltage);
  delay(500);
    } 
  } 

 void displayNumber( int number)
{
 number = constrain(number, 0, 5000); 
 Wire.beginTransmission(LedDrive); 
 Wire.write(1);
 for(int i =0; i < 4; i++)
  {
    byte digit = number % 10; 
    {
      Wire.write(lookup[digit]); 
     }
    number = number/10;
   }
 Wire.endTransmission(); 
 
 }

I think it works quite well, but now my questions are:

  1. when I play with the potentiometer, values on display changes not immediatly but after half of a second, more or less. Why?
  2. How can I improve this? May I correct it via software or it’s something connected to the hardware?

Thanks a lot for your kind answers,

Gianni

values on display changes not immediatly but after half of a second, more or less. Why?

I'm just guessing but maybe

 delay(500);

has something to do with it.


Rob

Thank you Rob,

I don't think the problem is that one, because in the serial monitor it works properly, and the delay is the same...

Thank you!

Gianni

Hard to see why it isn't your delays that are causing your issue. Easy enough to test too. Reduce or remove both of them - do things improve? If you do remove them entirely, you might want to increase the baud rate; better yet, comment out the serial.print altogether.

Hi there,

I've removed both delays and things improved, you were right, thank you very much. I've noticed that if I remove even the serial.print, leds work the same but they are flickering more. Why does it happen?

Thank you,

Gianni

because it updates even faster?

tip: before copying code to the forum press CTRL-T to auto format to improve readability