Issue with coding

I am doing my small assignment project. For my project i am using 1 x potentiometer, 2 x led, 3 x push button and 1 x one digit 7-segment(cathod). I am using pin D2-D4 for pushbuttons, pin D5-D11 for 7 segment and pin D12 and D13 for two leds. Potentiometer is connected to pin A0.

What I intend my program to do is: one led(led2 in the code)will blink with digit change in 7-segment. My three push button changes the speed of 7-segment and led(led2 in the code). The potentiometer is suppose to turn on and off the other led(led1 in the code). It does turn on and off.

I have three function for the speed of 7-segment and led(led2). void c0(200ms), void c1(3000ms) and void c2(1000ms).

So here is the problem. When i turn the potentiometer high it lights the led on but my void c2 function is also executed changing the speed of 7 segment and led(led2).
How can i solve this issue. I don’t want the potentiometer to hinder with my ‘void c2’ function and changing the speed even when it has its own respective button to change to that speed.

It only happens when i turn the potentiometer from low to high.But it doesn’t happen when turning from high to low.I have also used serial monitor to confirm this.

Any help is very much appreciated.

#include <PinChangeInterrupt.h>

const byte interruptPin0 = 2;
const byte interruptPin1 = 3;
const byte interruptPin2 = 4;

const byte ledpin1 = 13;
const byte ledpin2 = 12;

const byte sensorpin = A0;
int sensorvalue = 0;

int reading;
int value;

int segA = 5;
int segB = 6;
int segC = 7;
int segD = 8;
int segE = 9;
int segF = 10;
int segG = 11;

byte seven_seg_digits[10][7] =
{
  {1, 1, 1, 1, 1, 1, 0}, // = 0
  {0, 1, 1, 0, 0, 0, 0}, // = 1
  {1, 1, 0, 1, 1, 0, 1}, // = 2
  {1, 1, 1, 1, 0, 0, 1}, // = 3
  {0, 1, 1, 0, 0, 1, 1}, // = 4
  {1, 0, 1, 1, 0, 1, 1}, // = 5
  {1, 0, 1, 1, 1, 1, 1}, // = 6
  {1, 1, 1, 0, 0, 0, 0}, // = 7
  {1, 1, 1, 1, 1, 1, 1}, // = 8
  {1, 1, 1, 1, 0, 1, 1}, // = 9
};

int dtime = 1000;

void setup() {

  pinMode (segA , OUTPUT);
  pinMode (segB , OUTPUT);
  pinMode (segC , OUTPUT);
  pinMode (segD , OUTPUT);
  pinMode (segE , OUTPUT);
  pinMode (segF , OUTPUT);
  pinMode (segG , OUTPUT);
  writeDot(0);

  pinMode(ledpin1, OUTPUT);
  pinMode(ledpin2, OUTPUT);

  pinMode(interruptPin0, INPUT);
  pinMode(interruptPin1, INPUT);
  pinMode(interruptPin2, INPUT);

  attachInterrupt(digitalPinToInterrupt(interruptPin0), c0, RISING);
  attachInterrupt(digitalPinToInterrupt(interruptPin1), c1, RISING);
  attachPCINT(digitalPinToPCINT(interruptPin2), c2, RISING);

  Serial.begin(9600);
}

void writeDot(byte dot) {
  digitalWrite(segG, dot);
}

void sevenSegWrite(byte digit)
{
  byte pin = 5;
  for (byte segCount = 0; segCount < 7; ++segCount)
  {
    digitalWrite(pin, seven_seg_digits[digit][segCount]);
    ++pin;
  }
}

void c0() {
  dtime = 200;
  Serial.println(dtime);
}

void c1() {
  dtime = 3000;
  Serial.println(dtime);
}

void c2() {
  dtime = 1000;
  Serial.println(dtime);
}

void loop() {

  int sensorValue = analogRead(sensorpin);
  float voltage = sensorValue * (5.0 / 1023.0);
  Serial.print(sensorValue);
  Serial.print(" ");
  Serial.println(voltage);

  for (byte count = 0; count < 10; count++) {
    
    
    sevenSegWrite(count);
    Serial.println(count);
    digitalWrite(ledpin2, HIGH);
    delay(dtime);
    digitalWrite(ledpin2, LOW);
    delay(100);

    reading = analogRead(sensorpin);
    value = map(reading,A0,1024,A0,255);
    analogWrite(ledpin1,value);
  }  
}

sketch_jul03a.ino (2.2 KB)

If you stop using delay(), you won't need interrupts to read the switches, and your code will be orders of magnitude simpler.

Look at the blink without delay example, without delay.

On any given pass through loop(), it is, or is not, time to do something. If it is, do it, and record when you did it, so that next time around, you have a new reference.