Using Pot Resistance and PWM

Using piezo for sound input - resistance level to find using pot
Using pot to "tune" to now set piezo resistance level
3 lights - below range in range above range - of adjusting pot resist. vs piezo resist. PWM through functions

problems other than structure

cannot PWM lights based on the idea of % differences against resistances

// define counter integers
int i = 0;
int ii = 0;
int iii=0;
int fadeAway =0;

const int switchP = 13;

// colorMEASUREPINident
const int rMP1 = 11;
const int rMP2 = 10;
const int rMP3 = 9;
const int gMP = 5;
const int bMPa = 4;
const int yMP = 3;
const int bMPb = 2;
const int pizP = A1;
const int potP = A0;
// colorMEASUREPINident

int switchState = 0;
int prevswitchState = 0;

int knockVal = 0;
int knockVal1 = 0;
int potVal1 = 0;
int potVal = 0;

float knockAverage;
float potAverage;

float potMapVal, knockMapVal;

void setup() {

// monitor ready
Serial.begin(9600);
Serial.println("Serial Monitor Setup Done");

// input output pin declaration assignment

// colorMEASUREPINident
pinMode(rMP1,OUTPUT);
pinMode(rMP2,OUTPUT);
pinMode(rMP3,OUTPUT);
pinMode(gMP,OUTPUT);
pinMode(bMPa,OUTPUT);
pinMode(bMPb,OUTPUT);
pinMode(yMP,OUTPUT);
pinMode(pizP, INPUT);
pinMode(potP, INPUT);
pinMode(switchP,INPUT);
// colorMEASUREPINident
}

void loop() {

Serial.println("Please Press the Button to begin!");

  Serial.println(analogRead(pizP));
  delay(2000);  


switchState = digitalRead(switchP);

// was button pressed
if (switchState != prevswitchState){

Serial.println("Thanks!!! The Game is receiving sound input for a reference number.");

// iterate to create noise values to average
  for (i; i<3; i++){
    
    knockVal1 = analogRead(pizP);

    digitalWrite(rMP1, HIGH);
  digitalWrite(rMP3, HIGH);
  digitalWrite(bMPa, HIGH);
  digitalWrite(bMPb, HIGH);
  delay(500);
  digitalWrite(rMP1, LOW);
  digitalWrite(rMP3, LOW);
  digitalWrite(bMPa, LOW);
  digitalWrite(bMPb, LOW);
    digitalWrite(rMP2, HIGH);
  digitalWrite(gMP, HIGH);
  digitalWrite(yMP, HIGH);
  delay(500);
  digitalWrite(rMP2, LOW);
  digitalWrite(gMP, LOW);
  digitalWrite(yMP, LOW);
  knockVal += knockVal1;
 
  }  
  delay(2000);
 knockAverage = knockVal/i;
 Serial.println("We have collected enough sound!");
 Serial.println("Next, you will turn the knob to keep the middle red light illuminated!");
 delay(2500);
 Serial.print("all sound values average: ");
 Serial.println(knockAverage);
 delay(1500);
 

 // all code above this line does what its required as is


Serial.println("Remember, turn the knob to keep the middle red light illuminated!");
for (ii; ii < 9999; ii++){
  potVal1 = analogRead(potP);
  potVal += potVal1;
  Serial.println("potVal before addition: ");
  Serial.println(potVal1);
  Serial.println("potVal after addition: ");
  Serial.println(potVal);
  
    potAverage = potVal/ii;
//    potMapVal = map(potAverage, 0, 1023, 0, 255);
//  knockMapVal = map(knockAverage, 0, 1023, 0, 255);
  
// in range potentiometer average 
  while(potAverage >= knockAverage*.8 || potAverage <= knockAverage*1.2)
    {
        
        analogWrite(rMP1, 0);
        analogWrite(rMP2, 255);
        analogWrite(rMP3, 0);
      
      
    }

// lower than knockAverage lighting code
while (potAverage >= knockAverage*.6 || potAverage <= knockAverage*.79){
  analogWrite(rMP1, 130);
  analogWrite(rMP2, 195);
  analogWrite(rMP3, 0);
}

while(potAverage >= knockAverage*.4 || potAverage <= knockAverage*.59){
  analogWrite(rMP1, 195);
  analogWrite(rMP2, 130);
  analogWrite(rMP3, 0);
}


while(potAverage >= knockAverage*.0 || potAverage <= knockAverage*.39){
  analogWrite(rMP1, 255);
  analogWrite(rMP2, 30);
  analogWrite(rMP3, 0);
}
// greater than knockAverage lighting code
while (potAverage >= knockAverage*1.21 || potAverage <= knockAverage*1.4){
  analogWrite(rMP1, 0);
  analogWrite(rMP2, 195);
  analogWrite(rMP3, 130);
}

while(potAverage>=knockAverage*1.41 || potAverage<=knockAverage*1.6){
  analogWrite(rMP1, 0);
  analogWrite(rMP2, 130);
  analogWrite(rMP3, 195);
}
while(potAverage >= knockAverage*1.61 || potAverage <= 1023){
  analogWrite(rMP1, 0);
  analogWrite(rMP2, 30);
  analogWrite(rMP3, 255);
}


  
}
  Serial.println("all pot values average: ");
  Serial.println(potAverage);



Serial.print("Pot average: ");
Serial.println(potMapVal);
Serial.print("Knock average: ");
Serial.println(knockMapVal);

// this curly brace is the push button occured
}
// this curly brace is the push button occured
switchState = 0;
}
  1. potVal gets too big for an int. Use long instead.

  2. If I follow your logic correctly, you should not use a while statement in such cases, it should be an if :

while(potAverage >= knockAverage*.4 || potAverage <= knockAverage*.59){
  analogWrite(rMP1, 195);
  analogWrite(rMP2, 130);
  analogWrite(rMP3, 0);
}

I still, am unable to get the pot resistance measured value to real-time light the LEDS to visually display the range in which the pot resistance is currently in.

am unable to get the pot resistance measured value to real-time

That is because of all those huge delays you are using. You need to get rid of them.

when i run the program, the serial display is showing POT VALUE increase and readings, yet the lights are not changing their lit positions based on the pot value parameters of that function.

if (potVal1 >= knockAverage*.6 || potVal1 <= knockAverage*.79){
analogWrite(rMP1, 130);
analogWrite(rMP2, 195);
analogWrite(rMP3, 0);
potVal1 = analogRead(potP);
}

Post the whole sketch to show your latest code.

// define counter integers
int i = 0;
int ii = 0;
// int iii=0;
// int fadeAway =0;

const int switchP = 13;

// colorMEASUREPINident
const int rMP1 = 11;
const int rMP2 = 10;
const int rMP3 = 9;
const int gMP = 5;
const int bMPa = 4;
const int yMP = 3;
const int bMPb = 2;
const int pizP = A1;
const int potP = A0;
// colorMEASUREPINident

int switchState = 0;
int prevswitchState = 0;

int knockVal = 0;
int knockVal1 = 0;
long potVal1 = 0;
long potVal = 0;

float knockAverage;
float potAverage;

float potMapVal, knockMapVal;

void setup() {

// monitor ready
Serial.begin(9600);
Serial.println("Serial Monitor Setup Done");

// input output pin declaration assignment

// colorMEASUREPINident
pinMode(rMP1,OUTPUT);
pinMode(rMP2,OUTPUT);
pinMode(rMP3,OUTPUT);
pinMode(gMP,OUTPUT);
pinMode(bMPa,OUTPUT);
pinMode(bMPb,OUTPUT);
pinMode(yMP,OUTPUT);
pinMode(pizP, INPUT);
pinMode(potP, INPUT);
pinMode(switchP,INPUT);
// colorMEASUREPINident
}

void loop() 
{
Serial.println("Please Press the Button to begin!");
Serial.println(analogRead(pizP));
delay(200);  

switchState = digitalRead(switchP);
// was button pressed
if (switchState != prevswitchState)
  {
Serial.println("Thanks!!! The Game is receiving sound input for a reference number.");
// iterate to create noise values to average
for (i; i<3; i++)
    {
knockVal1 = analogRead(pizP);
digitalWrite(rMP1, HIGH);
digitalWrite(rMP3, HIGH);
digitalWrite(bMPa, HIGH);
digitalWrite(bMPb, HIGH);
delay(500);
digitalWrite(rMP1, LOW);
digitalWrite(rMP3, LOW);
digitalWrite(bMPa, LOW);
digitalWrite(bMPb, LOW);
digitalWrite(rMP2, HIGH);
digitalWrite(gMP, HIGH);
digitalWrite(yMP, HIGH);
delay(500);
digitalWrite(rMP2, LOW);
digitalWrite(gMP, LOW);
digitalWrite(yMP, LOW);
knockVal += knockVal1;
    }  
 
knockAverage = knockVal/i;
Serial.println("We have collected enough sound!");
Serial.println("Next, you will turn the knob to keep the middle red light illuminated!");
Serial.print("all sound values average: ");
Serial.println(knockAverage);

Serial.println("Remember, turn the knob to keep the middle red light illuminated!");
for (ii; ii < 8; ii++)
    {
potVal1 = analogRead(potP);
potVal += potVal1;
boolean readPot = true;
if(readPot)
      {
if(potVal1 >= knockAverage*.8 || potVal1 <= knockAverage*1.2)
        {
        
analogWrite(rMP1, 0);
analogWrite(rMP2, 255);
analogWrite(rMP3, 0);
potVal1 = analogRead(potP);
delay(2);
        }
if (potVal1 >= knockAverage*.6 || potVal1 <= knockAverage*.79)
        {
analogWrite(rMP1, 130);
analogWrite(rMP2, 195);
analogWrite(rMP3, 0);
potVal1 = analogRead(potP);
        }
if(potVal1 >= knockAverage*.4 || potVal1 <= knockAverage*.59)
        {
analogWrite(rMP1, 195);
analogWrite(rMP2, 130);
analogWrite(rMP3, 0);
potVal1 = analogRead(potP);
        }
if(potVal1 >= 0 || potVal1 <= knockAverage*.39)
        {
analogWrite(rMP1, 255);
analogWrite(rMP2, 30);
analogWrite(rMP3, 0);
potVal1 = analogRead(potP);
        }
if (potVal1 >= knockAverage*1.21 || potVal1 <= knockAverage*1.4)
        {
analogWrite(rMP1, 0);
analogWrite(rMP2, 195);
analogWrite(rMP3, 130);
potVal1 = analogRead(potP);
        }
if(potVal1>=knockAverage*1.41 || potVal1<=knockAverage*1.6)
        {
analogWrite(rMP1, 0);
analogWrite(rMP2, 130);
analogWrite(rMP3, 195);
potVal1 = analogRead(potP);
        }
if(potVal1 >= knockAverage*1.61 || potVal1 <= 1023)
        {
analogWrite(rMP1, 0);
analogWrite(rMP2, 30);
analogWrite(rMP3, 255);
potVal1 = analogRead(potP);
        }
      readPot = false;
      delay(2);
      }
    }
  }
  }
/*
      }
Serial.println("potVal before addition: ");
Serial.println(potVal1);
Serial.println("potVal after addition: ");
Serial.println(potVal);

//   potAverage = potVal/ii;
//    potMapVal = map(potAverage, 0, 1023, 0, 255);
//  knockMapVal = map(knockAverage, 0, 1023, 0, 255);



// lower than knockAverage lighting code

 
// greater than knockAverage lighting code











  
}
  Serial.println("all pot values average: ");
  Serial.println(potAverage);



Serial.print("Pot average: ");
Serial.println(potMapVal);
Serial.print("Knock average: ");
Serial.println(knockMapVal);
// this curly brace is the push button occured
}
// this curly brace is the push button occured
prevswitchState = switchState;
}
*/
 
/* while (millis() < 3000){
    Serial.println(analogRead(pizP));
    for (i; i < 5; i++){
      knockVal += analogRead(pizP);
      delay(500);
      Serial.println(knockVal);
    }
  */  
/*    delay(knockVal1 = analogRead(pizP));
    Serial.print("knock value 1: ");
    Serial.println(knockVal1);
    delay(500);
    knockVal2 = analogRead(pizP);
    Serial.print("knock value 2: ");
    Serial.println(knockVal2);
    delay(500);
    knockVal3 = analogRead(pizP);
    Serial.print("knock value 3: ");
    Serial.println(knockVal3);
    delay(500);
    knockVal4 = analogRead(pizP);
    Serial.print("knock value 4: ");
    Serial.println(knockVal4);
    */

This loop will finish remarkably quickly, considering that you are expecting someone to rotate a potentiometer and watch lights while it is all happening:

Serial.println("Remember, turn the knob to keep the middle red light illuminated!");
   for (ii; ii < 8; ii++)
   {
     . . .
   }

This 'if' statement will always be performed:

      boolean readPot = true;
      if (readPot) 
         { . . . }

Surely you want the potentiometer to be read every loop iteration and not simply when a condition is fulfilled for example:

        if (potVal1 >= knockAverage * .8 || potVal1 <= knockAverage * 1.2)
        {

          analogWrite(rMP1, 0);
          analogWrite(rMP2, 255);
          analogWrite(rMP3, 0);
          potVal1 = analogRead(potP);  // why here ??
          delay(2);
        }

Otherwise the code will get 'stuck' as soon as potval1 no longer matches any of the ranges you have specified in your 'if' conditions.

I thought i covered all numbers created by the pot by having the low end reach 0 with the conditions and the high end being 1023 - the largest number the pot can return.

Trying to have the FOR loop run for 6 seconds to adjust the lights based on the POT reading

currentTime = millis();
additionalTime = currentTime + 6000;

for(currentTime; currentTime < additionalTime;)
    {
potVal1 = analogRead(potP);
potVal += potVal1;
if(potVal1>=0||potVal1<=1023)
    {
readPot = true;
    }
if(readPot)
      {
if(potVal1 >= knockAverage*.8 || potVal1 <= knockAverage*1.2)
        {
analogWrite(rMP1, 0);
analogWrite(rMP2, 255);
analogWrite(rMP3, 0);
potVal1 = analogRead(potP);
break;
        }
if (potVal1 >= knockAverage*.6 || potVal1 <= knockAverage*.79)
        {
analogWrite(rMP1, 130);
analogWrite(rMP2, 195);
analogWrite(rMP3, 0);
potVal1 = analogRead(potP);
break;
        }
if(potVal1 >= knockAverage*.4 || potVal1 <= knockAverage*.59)
        {
analogWrite(rMP1, 195);
analogWrite(rMP2, 130);
analogWrite(rMP3, 0);
potVal1 = analogRead(potP);
break;
        }
if(potVal1 >= 0 || potVal1 <= knockAverage*.39)
        {
analogWrite(rMP1, 255);
analogWrite(rMP2, 30);
analogWrite(rMP3, 0);
break;
        }
if (potVal1 >= knockAverage*1.21 || potVal1 <= knockAverage*1.4)
        {
analogWrite(rMP1, 0);
analogWrite(rMP2, 195);
analogWrite(rMP3, 130);
break;
        }
if(potVal1>=knockAverage*1.41 || potVal1<=knockAverage*1.6)
        {
analogWrite(rMP1, 0);
analogWrite(rMP2, 130);
analogWrite(rMP3, 195);
break;
        }
if(potVal1 >= knockAverage*1.61 || potVal1 <= 1023)
        {
analogWrite(rMP1, 0);
analogWrite(rMP2, 30);
analogWrite(rMP3, 255);
break;
        }
      currentTime = millis();
      }
    }
  }
  }
// define counter integers
int i = 0;
int ii = 0;
// int iii=0;
// int fadeAway =0;
boolean readPot = false;
const int switchP = 13;

// colorMEASUREPINident
const int rMP1 = 11;
const int rMP2 = 10;
const int rMP3 = 9;
const int gMP = 5;
const int bMPa = 4;
const int yMP = 3;
const int bMPb = 2;
const int pizP = A1;
const int potP = A0;
// colorMEASUREPINident

int switchState = 0;
int prevswitchState = 0;

int knockVal = 0;
int knockVal1 = 0;
long potVal1 = 0;
long potVal = 0;
unsigned long currentTime = 0;
unsigned long additionalTime = 0;
float knockAverage;
float potAverage;

float potMapVal, knockMapVal;

void setup() {

// monitor ready
Serial.begin(9600);
Serial.println("Serial Monitor Setup Done");

// input output pin declaration assignment

// colorMEASUREPINident
pinMode(rMP1,OUTPUT);
pinMode(rMP2,OUTPUT);
pinMode(rMP3,OUTPUT);
pinMode(gMP,OUTPUT);
pinMode(bMPa,OUTPUT);
pinMode(bMPb,OUTPUT);
pinMode(yMP,OUTPUT);
pinMode(pizP, INPUT);
pinMode(potP, INPUT);
pinMode(switchP,INPUT);
// colorMEASUREPINident
}

void loop() 
{
Serial.println("Please Press the Button to begin!");
Serial.println(analogRead(pizP));
delay(200);  

switchState = digitalRead(switchP);
// was button pressed
if (switchState != prevswitchState)
  {
Serial.println("Thanks!!! The Game is receiving sound input for a reference number.");
// iterate to create noise values to average
for (i; i<3; i++)
    {
knockVal1 = analogRead(pizP);
digitalWrite(rMP1, HIGH);
digitalWrite(rMP3, HIGH);
digitalWrite(bMPa, HIGH);
digitalWrite(bMPb, HIGH);
delay(500);
digitalWrite(rMP1, LOW);
digitalWrite(rMP3, LOW);
digitalWrite(bMPa, LOW);
digitalWrite(bMPb, LOW);
digitalWrite(rMP2, HIGH);
digitalWrite(gMP, HIGH);
digitalWrite(yMP, HIGH);
delay(500);
digitalWrite(rMP2, LOW);
digitalWrite(gMP, LOW);
digitalWrite(yMP, LOW);
knockVal += knockVal1;
    }  
 
knockAverage = knockVal/i;
Serial.println("We have collected enough sound!");
Serial.println("Next, you will turn the knob to keep the middle red light illuminated!");
Serial.print("all sound values average: ");
Serial.println(knockAverage);

Serial.println("Remember, turn the knob to keep the middle red light illuminated!");

currentTime = millis();
additionalTime = currentTime + 6000;
Serial.println(currentTime);
Serial.println(additionalTime);
for(currentTime; currentTime < additionalTime;)
    {
      Serial.println("in the for loop");
potVal1 = analogRead(potP);
potVal += potVal1;
if(potVal1>=0||potVal1<=1023)
    {
      Serial.println("potval in range");
readPot = true;
    }
if(readPot)
      {
        Serial.println("readPot true");
if(potVal1 >= knockAverage*.8 || potVal1 <= knockAverage*1.2)
        {
analogWrite(rMP1, 0);
analogWrite(rMP2, 255);
analogWrite(rMP3, 0);
potVal1 = analogRead(potP);
        }
if (potVal1 >= knockAverage*.6 || potVal1 <= knockAverage*.79)
        {
analogWrite(rMP1, 130);
analogWrite(rMP2, 195);
analogWrite(rMP3, 0);
potVal1 = analogRead(potP);

        }
if(potVal1 >= knockAverage*.4 || potVal1 <= knockAverage*.59)
        {
analogWrite(rMP1, 195);
analogWrite(rMP2, 130);
analogWrite(rMP3, 0);
potVal1 = analogRead(potP);

        }
if(potVal1 >= 0 || potVal1 <= knockAverage*.39)
        {
analogWrite(rMP1, 255);
analogWrite(rMP2, 30);
analogWrite(rMP3, 0);

        }
if (potVal1 >= knockAverage*1.21 || potVal1 <= knockAverage*1.4)
        {
analogWrite(rMP1, 0);
analogWrite(rMP2, 195);
analogWrite(rMP3, 130);

        }
if(potVal1>=knockAverage*1.41 || potVal1<=knockAverage*1.6)
        {
analogWrite(rMP1, 0);
analogWrite(rMP2, 130);
analogWrite(rMP3, 195);

        }
if(potVal1 >= knockAverage*1.61 || potVal1 <= 1023)
        {
analogWrite(rMP1, 0);
analogWrite(rMP2, 30);
analogWrite(rMP3, 255);

        }
      currentTime = millis();
      Serial.println("new current time after loops");
      Serial.println(currentTime);
      }
    }
  }
  }
/*
      }
Serial.println("potVal before addition: ");
Serial.println(potVal1);
Serial.println("potVal after addition: ");
Serial.println(potVal);

//   potAverage = potVal/ii;
//    potMapVal = map(potAverage, 0, 1023, 0, 255);
//  knockMapVal = map(knockAverage, 0, 1023, 0, 255);



// lower than knockAverage lighting code

 
// greater than knockAverage lighting code











  
}
  Serial.println("all pot values average: ");
  Serial.println(potAverage);



Serial.print("Pot average: ");
Serial.println(potMapVal);
Serial.print("Knock average: ");
Serial.println(knockMapVal);
// this curly brace is the push button occured
}
// this curly brace is the push button occured
prevswitchState = switchState;
}
*/
 
/* while (millis() < 3000){
    Serial.println(analogRead(pizP));
    for (i; i < 5; i++){
      knockVal += analogRead(pizP);
      delay(500);
      Serial.println(knockVal);
    }
  */  
/*    delay(knockVal1 = analogRead(pizP));
    Serial.print("knock value 1: ");
    Serial.println(knockVal1);
    delay(500);
    knockVal2 = analogRead(pizP);
    Serial.print("knock value 2: ");
    Serial.println(knockVal2);
    delay(500);
    knockVal3 = analogRead(pizP);
    Serial.print("knock value 3: ");
    Serial.println(knockVal3);
    delay(500);
    knockVal4 = analogRead(pizP);
    Serial.print("knock value 4: ");
    Serial.println(knockVal4);
    */

I am able to run through the entire loops using the millis feature. However, the lights are still not adjusting.

Just to get something working, why not simply have a continuous loop which takes the current value of the potentiometer and lights the leds for that analog value.

Once you see how that works, then expand the solution to include average values etc.

for ( ; ; ) { // loop forever

  potVal1 = analogRead(potP);

  if ( potVal1 < 200 ) {
    analogWrite(rMP1, 0);
    analogWrite(rMP2, 255);
    analogWrite(rMP3, 0);

  }
  else ( if potVal1 < 400 ) {
    analogWrite(rMP1, 130);
    analogWrite(rMP2, 195);
    analogWrite(rMP3, 0);
  }
  else ( if potVal < 800 ) {
    analogWrite(rMP1, 195);
    analogWrite(rMP2, 130);
    analogWrite(rMP3, 0);

  }
  else {
    analogWrite(rMP1, 255);
    analogWrite(rMP2, 30);
    analogWrite(rMP3, 0);
  }
}