potential meter to 7 display

i have a project where i need an output on a 7segment display. but i only get the number 4 on my display can anyone help me

/*
/*
  besturing lego machine.
  
*/
// the setup routine runs once when you press reset:

const int A = 2;
const int B = 3;
const int C = 4;
const int D = 5;
const int E = 6;
const int F = 7;
const int G = 8;
const int seg5 = 9;
const int seg1 = 10;
const int motor = 11;
int wachttijd = 4;

void setup() {
  //alle uitgangen
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(seg5, OUTPUT);
  pinMode(seg1, OUTPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}
                   

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int potmeter = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float wachttijd = -potmeter * (6 / 1023.0)+10;
  // print out the value you read:
  Serial.println(wachttijd);
 
// output 4
  if (3.9 <= wachttijd <= 4.4){
    digitalWrite(2, 0);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 0);
    digitalWrite(6, 0);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 0);
    digitalWrite(10, 0);
    delay(1);
    }
  // output 4.5
  else if (4.5 <= wachttijd <= 4.9){
    digitalWrite(2, 0);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 0);
    digitalWrite(6, 0);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 1);
    digitalWrite(10, 0);
    delay(1);
    }
  // output 5
  else if (5 <= wachttijd <= 5.4){
    digitalWrite(2, 1);
    digitalWrite(3, 0);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 0);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 0);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 5.5
  else if (wachttijd <= 5.9){
    digitalWrite(2, 1);
    digitalWrite(3, 0);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 0);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 1);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 6
  else if (wachttijd <= 6.4){
    digitalWrite(2, 1);
    digitalWrite(3, 0);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 1);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 0);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 6.5
  else if (wachttijd <= 6.9){
    digitalWrite(2, 1);
    digitalWrite(3, 0);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 1);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 1);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 7
  else if (wachttijd <= 7.4){
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 0);
    digitalWrite(6, 0);
    digitalWrite(7, 0);
    digitalWrite(8, 0);
    digitalWrite(9, 0);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 7.5
  else if (wachttijd <= 7.9){
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 0);
    digitalWrite(6, 0);
    digitalWrite(7, 0);
    digitalWrite(8, 0);
    digitalWrite(9, 1);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 8
  else if (wachttijd <= 8.4){
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 1);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 0);
    digitalWrite(10, 0);
    delay(1);
  }
    // output 8.5
  else if (wachttijd <= 8.9){
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 1);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 1);
    digitalWrite(10, 0);
    delay(1);
  }
    // output 9
  else if (wachttijd <= 9.4){
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 0);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 0);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 9.5
    else if (wachttijd <= 9.9){
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 0);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 1);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 10
  else{
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 1);
    digitalWrite(7, 1);
    digitalWrite(8, 0);
    digitalWrite(9, 0);
    digitalWrite(10, 1);
    delay(1);
  }
}
}

this is my code

greetings
Mathijs van Dongen

(deleted)

@cacapedo, analWrite()? Really?

@phoxyboy, please change your post to use code tags, not a quote. See How to use this forum.

And why not grab SevenSeg library to do it? And if you insist on doing it yourself, loop up arrays. That will save you A LOT of code :wink:

spycatcher2k:

if (3.9 <= wachttijd <= 4.4)

Does not do what you think, if you think it means ‘between’ the values then have it wrong.

if ((3.9 >= wachttijd) & (wachttijd <= 4.4))

is what should be used

I have now this error

exit status 1
lvalue required as unary '&' operand

i have done it like this

/*
  besturing lego machine.
  
*/
// the setup routine runs once when you press reset:

const int A = 2;
const int B = 3;
const int C = 4;
const int D = 5;
const int E = 6;
const int F = 7;
const int G = 8;
const int seg5 = 9;
const int seg1 = 10;
const int motor = 11;
int wachttijd = 4;

void setup() {
  //alle uitgangen
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(seg5, OUTPUT);
  pinMode(seg1, OUTPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}
                   

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int potmeter = analogRead(A0);
  float wachttijd = -potmeter * (6 / 1023.0)+10;
  // print out the value you read:
  Serial.println(wachttijd);
 
// output 4
  if ((3.9 >= wachttijd) & (wachttijd <= 4.4)){
    digitalWrite(2, 0);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 0);
    digitalWrite(6, 0);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 0);
    digitalWrite(10, 0);
    delay(1);
    }
  // output 4.5
  else if ((4.5 >= wachttijd) & (wachttijd <= 4.9)){
    digitalWrite(2, 0);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 0);
    digitalWrite(6, 0);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 1);
    digitalWrite(10, 0);
    delay(1);
    }
  // output 5
  else if ((5 >= wachttijd) & (wachttijd <= 5.4)){
    digitalWrite(2, 1);
    digitalWrite(3, 0);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 0);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 0);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 5.5
  else if ((5.5 >= wachttijd) & (wachttijd <= 5.9)){
    digitalWrite(2, 1);
    digitalWrite(3, 0);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 0);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 1);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 6
  else if ((6 >= wachttijd) & (wachttijd <= 6.4)){
    digitalWrite(2, 1);
    digitalWrite(3, 0);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 1);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 0);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 6.5
  else if ((6.5 >= wachttijd) & (wachttijd <= 6.9)){
    digitalWrite(2, 1);
    digitalWrite(3, 0);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 1);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 1);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 7
  else if ((7 >= wachttijd) & (wachttijd <= 7.4)){
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 0);
    digitalWrite(6, 0);
    digitalWrite(7, 0);
    digitalWrite(8, 0);
    digitalWrite(9, 0);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 7.5
  else if ((7.5 >= wachttijd) & (wachttijd <= 7.9)){
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 0);
    digitalWrite(6, 0);
    digitalWrite(7, 0);
    digitalWrite(8, 0);
    digitalWrite(9, 1);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 8
  else if ((8 >= wachttijd) & (wachttijd <= 8.4)){
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 1);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 0);
    digitalWrite(10, 0);
    delay(1);
  }
    // output 8.5
  else if ((8.5 >= wachttijd) & (wachttijd <= 8.9)){
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 1);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 1);
    digitalWrite(10, 0);
    delay(1);
  }
    // output 9
  else if ((9 >= wachttijd) & (wachttijd <= 9.4)){
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 0);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 0);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 9.5
    else if (9.5 >= wachttijd) & (wachttijd <= 9.9)){
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 0);
    digitalWrite(7, 1);
    digitalWrite(8, 1);
    digitalWrite(9, 1);
    digitalWrite(10, 0);
    delay(1);
  }
  // output 10
  else{
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(4, 1);
    digitalWrite(5, 1);
    digitalWrite(6, 1);
    digitalWrite(7, 1);
    digitalWrite(8, 0);
    digitalWrite(9, 0);
    digitalWrite(10, 1);
    delay(1);
  }
}

(deleted)

My example was incorrect also

It's still wrong. The boolean AND operator is &&, not &.

septillion:
@cacapedo, analWrite()? Really?

@cacapedo is currently enjoying a forum timeout.

PaulS:
It's still wrong. The boolean AND operator is &&, not &.

Or is it?
The main advantage to using logical AND is that it allows short-circuit evaluation, to avoid unwanted side-effects, like dereferencing a null pointer is code like if (p && p->flag) where if the left-most expression evaluates false, the right-hand expression isn't evaluated.
In numeric expressions, such side-effects don't normally exist (divide by zero being an obvious exception), and a simple '&' works just as well, albeit without the minor optimisation that short-circuiting allows.
I'm not saying it's right, but it's a sort-of allowable.

(deleted)