Potentiometer + 7447 + 7 segment display 0-9

Greetings.
As the subject mentioned,I’m trying to use Potentiometer to control 7447 to display number from 0-9.
and so far,I’ve only managed to wrote normal 0-9 counter…how do I adjust my code to fit the Potentiometer to control it?

Any help is grateful.

my code:

byte bcd_code[10][4] = {
  {0,0,0,0},
  {0,0,0,1},
  {0,0,1,0},
  {0,0,1,1},
  {0,1,0,0},
  {0,1,0,1},
  {0,1,1,0},
  {0,1,1,1},
  {1,0,0,0},
  {1,0,0,1}
};
 
void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
 
}
 
void disp(byte d) {
  for(byte i=0; i<4; i++) {
    digitalWrite(5-i, bcd_code[d][i]);
  }
}
void loop() {
   
  for(byte i=0; i<10; i++) {
    disp(i);
    delay(1000);    
  }
}

You should wire the potentiometer to an analog pin. You can then analogRead() from that pin. This will give you a value between 0 (for 0V) and 1023 (for 5V). You then convert this 0..1023 value into a 0..9 value, and display that.

Hint map(value, fromLow, fromHigh, toLow, toHigh)

https://www.arduino.cc/reference/en/language/functions/math/map/

Jobi-Wan: You should wire the potentiometer to an analog pin. You can then analogRead() from that pin. This will give you a value between 0 (for 0V) and 1023 (for 5V). You then convert this 0..1023 value into a 0..9 value, and display that.

I knew I had to use analogRead() and to map() it,but my biggest question is,how to map() the bcd_code part to collaborate with potentiometer?or bcd_code part is the one I should map() it?

Thanks.

larryd: Hint map(value, fromLow, fromHigh, toLow, toHigh)

https://www.arduino.cc/reference/en/language/functions/math/map/

I knew I had to map it,but how to map the bcd_code to it?can I have a little more specific detail? Thanks.

If you only have one digit, 0-9, then you don’t need to convert to BCD.

larryd: If you only have one digit, 0-9, the you don’t need to convert to BCD.

Just after the reply,an idea came through and I made it. Thanks.