use pot instead of encoder

can anyone help me figure out how to use normal analog potentiometers with this sketch,
instead of the rotary encoders?

  //############### ROTARY ENCODER (DELAY TIME) ######################
    n = digitalRead(encoder0PinA);
    if ((encoder0PinALast == HIGH) && (n == LOW)) {
      if (digitalRead(encoder0PinB) == HIGH)
      {
        if ((current_ms  - decreaseincrease) * subdivisionfactor[arrayid] >= min_delay)        // Stay above the minimum delay time
        {
          current_ms = current_ms - decreaseincrease;
        }
        else
        {
          current_ms = min_delay / subdivisionfactor[arrayid];                                 // Set to min_delay, if the decrease would have exceeded the minimum delay
        }
        current_ms_subdiv = current_ms * subdivisionfactor[arrayid];
        potchangerequired = HIGH;
      }
      else
      {
        if ((current_ms  + decreaseincrease) * subdivisionfactor[arrayid] <= max_delay)                 // Stay under max_delay
        {
          current_ms = current_ms + decreaseincrease;
        }
        else
        {
          current_ms = max_delay / subdivisionfactor[arrayid];                                          // Set to max_delay, if the increase would have exceeded the maximum delay
        }
        current_ms_subdiv = current_ms * subdivisionfactor[arrayid];
        potchangerequired = HIGH;
      }
    }
    encoder0PinALast = n;

Main_Code_PT2399_edit.ino (36.9 KB)

All you have to do is do an analogRead() of that pin to get a value between 0-1023 and then use the map() function to transform it into the minimum-maximum time delay you want.

I tried this but get errors elsewhere in the sketch

 //############### ROTARY ENCODER (DELAY TIME) ######################

  int sensorValue = analogRead(A2);
  float current_ms = sensorValue * (5.0 / 1023.0);

  //n = digitalRead(encoder0PinA);
  //if ((encoder0PinALast == HIGH) && (n == LOW)) {
  if (analogRead(A2))
    {
      if ((current_ms  - decreaseincrease) * subdivisionfactor[arrayid] >= min_delay)        // Stay above the minimum delay time
      {
        current_ms = current_ms - decreaseincrease;
      }
      else
      {
        current_ms = min_delay / subdivisionfactor[arrayid];                                 // Set to min_delay, if the decrease would have exceeded the minimum delay
      }
      current_ms_subdiv = current_ms * subdivisionfactor[arrayid];
      //potchangerequired = HIGH;
    }
    else
    {
      if ((current_ms  + decreaseincrease) * subdivisionfactor[arrayid] <= max_delay)                 // Stay under max_delay
      {
        current_ms = current_ms + decreaseincrease;
      }
      else
      {
        current_ms = max_delay / subdivisionfactor[arrayid];                                          // Set to max_delay, if the increase would have exceeded the maximum delay
      }
      current_ms_subdiv = current_ms * subdivisionfactor[arrayid];
      //potchangerequired = HIGH;
    }
  }
//  encoder0PinALast = n;

get errors elsewhere in the sketch

that you have not posted

/Users/lee/Desktop/Main_Code_PT2399_edit/Main_Code_PT2399_edit.ino: In function 'void loop()':
Main_Code_PT2399_edit:483:26: error: 'decreaseincrease' was not declared in this scope
       if ((current_ms  - decreaseincrease) * subdivisionfactor[arrayid] >= min_delay)        // Stay above the minimum delay time
                          ^~~~~~~~~~~~~~~~
Main_Code_PT2399_edit:496:26: error: 'decreaseincrease' was not declared in this scope
       if ((current_ms  + decreaseincrease) * subdivisionfactor[arrayid] <= max_delay)                 // Stay under max_delay
                          ^~~~~~~~~~~~~~~~
/Users/lee/Desktop/Main_Code_PT2399_edit/Main_Code_PT2399_edit.ino: At global scope:
Main_Code_PT2399_edit:567:3: error: 'readingtapbutton' does not name a type
   readingtapbutton = digitalRead(tapbuttonpin);               // read the state of the button into a local variable
   ^~~~~~~~~~~~~~~~
Main_Code_PT2399_edit:568:3: error: expected unqualified-id before 'if'
   if (readingtapbutton != lasttapbuttonstate)                 // the following loop will only be done, if the button state has changed
   ^~
Main_Code_PT2399_edit:572:3: error: expected unqualified-id before 'if'
   if ((millis() - lastDebounceTime) > debounceDelay)          // the following loop will only be done, if the last change of the button exceeds the debounce time (=is a button press, not noise)
   ^~
Main_Code_PT2399_edit:603:3: error: 'lasttapbuttonstate' does not name a type
   lasttapbuttonstate = readingtapbutton;                    // save the reading to determine whether the button state has changed next time
   ^~~~~~~~~~~~~~~~~~
Main_Code_PT2399_edit:605:3: error: expected unqualified-id before 'if'
   if (millis() - firsttapmillis > 1000)                     // if there is more than 1000 ms between two taps, delta measuremant resumes; it can be longer than max_delay due to subdivision...
   ^~
Main_Code_PT2399_edit:611:3: error: 'blinkfreq' does not name a type
   blinkfreq = current_ms;                                                                      // current_ms_subdiv / subdivisionfactor[arrayid];
   ^~~~~~~~~
Main_Code_PT2399_edit:612:3: error: 'currentMillis' does not name a type
   currentMillis = millis();
   ^~~~~~~~~~~~~
Main_Code_PT2399_edit:613:15: error: expected constructor, destructor, or type conversion before '(' token
   digitalWrite(greenpin, currentgreen);
               ^
Main_Code_PT2399_edit:614:14: error: expected constructor, destructor, or type conversion before '(' token
   analogWrite(redpin, currentred);
              ^
Main_Code_PT2399_edit:615:14: error: expected constructor, destructor, or type conversion before '(' token
   analogWrite(bluepin, currentblue);
              ^
Main_Code_PT2399_edit:616:3: error: expected unqualified-id before 'if'
Multiple libraries were found for "SPI.h"
   if (currentMillis - blinkfreq > lastblinktoggle)
   ^~
Main_Code_PT2399_edit:622:3: error: expected unqualified-id before 'if'
   if (currentMillis - lastblinktoggle > led_lit_time)
   ^~
Main_Code_PT2399_edit:707:1: error: expected declaration before '}' token
 }
 ^
 Used: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI
Multiple libraries were found for "EEPROM.h"
 Used: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/EEPROM
exit status 1
'decreaseincrease' was not declared in this scope

_160403_Main_Code_PT2399_Control.ino (36 KB)

ive tried to remove the things I don't need from the code:
presets, rotary pot mod depth, rotary pot mod freq.

and tried to keep what I need: subdivisions, delay pot (changed to analog pot), the eeprom code

A rudimentary example:

// Use an analog potentiometer as a selector switch

// Number of switch positions, and maximum analog voltage

const byte numberOfPositions = 7;
const uint16_t maxAnalog = 1024;

void setup() {
  Serial.begin(115200);
}
void loop() {
  Serial.println(getSWpos());
}

int getSWpos() {
  return map(analogRead(A5), 0, maxAnalog, 1, numberOfPositions+1);
}
   //############### ROTARY ENCODER (DELAY TIME) ######################

    int sensorValue = analogRead(A2); // i added this
    float current_ms = sensorValue * (5.0 / 1023.0); // i added this

    // n = digitalRead(encoder0PinA);
    // if ((encoder0PinALast == HIGH) && (n == LOW)) {
    
    if (analogRead(A2)) // i added this
    
      //   if (digitalRead(encoder0PinB) == HIGH)
    {
      if ((current_ms  - decreaseincrease) * subdivisionfactor[arrayid] >= min_delay)        // Stay above the minimum delay time
      {
        current_ms = current_ms - decreaseincrease;
      }
      else
      {
        current_ms = min_delay / subdivisionfactor[arrayid];                                 // Set to min_delay, if the decrease would have exceeded the minimum delay
      }
      current_ms_subdiv = current_ms * subdivisionfactor[arrayid];
      potchangerequired = HIGH;
    }
    else
    {
      if ((current_ms  + decreaseincrease) * subdivisionfactor[arrayid] <= max_delay)                 // Stay under max_delay
      {
        current_ms = current_ms + decreaseincrease;
      }
      else
      {
        current_ms = max_delay / subdivisionfactor[arrayid];                                          // Set to max_delay, if the increase would have exceeded the maximum delay
      }
      current_ms_subdiv = current_ms * subdivisionfactor[arrayid];
      potchangerequired = HIGH;
    }
  }
  encoder0PinALast = n;
Arduino: 1.8.10 (Mac OS X), Board: "Arduino Duemilanove or Diecimila, ATmega328P"

/Users/lee/Desktop/_160403_Main_Code_PT2399_Control/_160403_Main_Code_PT2399_Control.ino: In function 'void setup()':
_160403_Main_Code_PT2399_Control:186:3: error: 'setPwmFrequency' was not declared in this scope
   setPwmFrequency(redpin, 1);
   ^~~~~~~~~~~~~~~
/Users/lee/Desktop/_160403_Main_Code_PT2399_Control/_160403_Main_Code_PT2399_Control.ino: In function 'void loop()':
_160403_Main_Code_PT2399_Control:406:13: error: 'digitalPotWrite' was not declared in this scope
             digitalPotWrite(slaveDelayPin, digipot_value);
             ^~~~~~~~~~~~~~~
/Users/lee/Desktop/_160403_Main_Code_PT2399_Control/_160403_Main_Code_PT2399_Control.ino:406:13: note: suggested alternative: 'digitalWrite'
             digitalPotWrite(slaveDelayPin, digipot_value);
             ^~~~~~~~~~~~~~~
             digitalWrite
_160403_Main_Code_PT2399_Control:465:11: error: 'print_settings' was not declared in this scope
           print_settings();
           ^~~~~~~~~~~~~~
/Users/lee/Desktop/_160403_Main_Code_PT2399_Control/_160403_Main_Code_PT2399_Control.ino:465:11: note: suggested alternative: 'presetpin'
           print_settings();
           ^~~~~~~~~~~~~~
           presetpin
_160403_Main_Code_PT2399_Control:534:5: error: 'digitalPotWrite' was not declared in this scope
     digitalPotWrite(slaveModPin, moddepth);
     ^~~~~~~~~~~~~~~
/Users/lee/Desktop/_160403_Main_Code_PT2399_Control/_160403_Main_Code_PT2399_Control.ino:534:5: note: suggested alternative: 'digitalWrite'
     digitalPotWrite(slaveModPin, moddepth);
     ^~~~~~~~~~~~~~~
     digitalWrite
_160403_Main_Code_PT2399_Control:639:9: error: 'digitalPotWrite' was not declared in this scope
         digitalPotWrite(slaveDelayPin, digipot_value);                                                                                                              //Write the value to MCP digital potentiometer
         ^~~~~~~~~~~~~~~
/Users/lee/Desktop/_160403_Main_Code_PT2399_Control/_160403_Main_Code_PT2399_Control.ino:639:9: note: suggested alternative: 'digitalWrite'
         digitalPotWrite(slaveDelayPin, digipot_value);                                                                                                              //Write the value to MCP digital potentiometer
         ^~~~~~~~~~~~~~~
         digitalWrite
/Users/lee/Desktop/_160403_Main_Code_PT2399_Control/_160403_Main_Code_PT2399_Control.ino: At global scope:
_160403_Main_Code_PT2399_Control:704:1: error: expected declaration before '}' token
 }                                                                              // END of LOOP()
 ^
Multiple libraries were found for "SPI.h"
 Used: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI
Multiple libraries were found for "EEPROM.h"
 Used: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/EEPROM
exit status 1
'setPwmFrequency' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

_160403_Main_Code_PT2399_Control.ino (35.8 KB)

EEPROMAnything.h (502 Bytes)

can anyone help me figure out how to use normal analog potentiometers with this sketch,
instead of the rotary encoders?

Please post your best effort at coding this, all error messages (if any) and describe the problems that you are having ?

I commented out everything I don’t need, I made the changes to the ROTARY ENCODER (DELAY TIME)
but I get not declared in this scope errors

Arduino: 1.8.10 (Mac OS X), Board: "Arduino/Genuino Uno"

/Users/lee/Desktop/160428 Taprecise Code Package/Main_Code_PT2399_edit/Main_Code_PT2399_edit.ino: In function 'void loop()':
Main_Code_PT2399_edit:480:24: error: 'decreaseincrease' was not declared in this scope
     if ((current_ms  - decreaseincrease) * subdivisionfactor[arrayid] >= min_delay)        // Stay above the minimum delay time
                        ^~~~~~~~~~~~~~~~
Main_Code_PT2399_edit:493:24: error: 'decreaseincrease' was not declared in this scope
     if ((current_ms  + decreaseincrease) * subdivisionfactor[arrayid] <= max_delay)                 // Stay under max_delay
                        ^~~~~~~~~~~~~~~~
/Users/lee/Desktop/160428 Taprecise Code Package/Main_Code_PT2399_edit/Main_Code_PT2399_edit.ino: At global scope:
Main_Code_PT2399_edit:505:1: error: 'encoder0PinALast' does not name a type
 encoder0PinALast = n;
 ^~~~~~~~~~~~~~~~
Main_Code_PT2399_edit:564:1: error: 'readingtapbutton' does not name a type
 readingtapbutton = digitalRead(tapbuttonpin);               // read the state of the button into a local variable
 ^~~~~~~~~~~~~~~~
Main_Code_PT2399_edit:565:1: error: expected unqualified-id before 'if'
 if (readingtapbutton != lasttapbuttonstate)                 // the following loop will only be done, if the button state has changed
 ^~
Main_Code_PT2399_edit:569:1: error: expected unqualified-id before 'if'
 if ((millis() - lastDebounceTime) > debounceDelay)          // the following loop will only be done, if the last change of the button exceeds the debounce time (=is a button press, not noise)
 ^~
Main_Code_PT2399_edit:600:1: error: 'lasttapbuttonstate' does not name a type
 lasttapbuttonstate = readingtapbutton;                    // save the reading to determine whether the button state has changed next time
 ^~~~~~~~~~~~~~~~~~
Main_Code_PT2399_edit:602:1: error: expected unqualified-id before 'if'
 if (millis() - firsttapmillis > 1000)                     // if there is more than 1000 ms between two taps, delta measuremant resumes; it can be longer than max_delay due to subdivision...
 ^~
Main_Code_PT2399_edit:608:1: error: 'blinkfreq' does not name a type
 blinkfreq = current_ms;                                                                      // current_ms_subdiv / subdivisionfactor[arrayid];
 ^~~~~~~~~
Main_Code_PT2399_edit:609:1: error: 'currentMillis' does not name a type
 currentMillis = millis();
 ^~~~~~~~~~~~~
Main_Code_PT2399_edit:610:13: error: expected constructor, destructor, or type conversion before '(' token
 digitalWrite(greenpin, currentgreen);
             ^
Main_Code_PT2399_edit:611:12: error: expected constructor, destructor, or type conversion before '(' token
 analogWrite(redpin, currentred);
            ^
Main_Code_PT2399_edit:612:12: error: expected constructor, destructor, or type conversion before '(' token
 analogWrite(bluepin, currentblue);
            ^
Main_Code_PT2399_edit:613:1: error: expected unqualified-id before 'if'
 if (currentMillis - blinkfreq > lastblinktoggle)
 ^~
Main_Code_PT2399_edit:619:1: error: expected unqualified-id before 'if'
 if (currentMillis - lastblinktoggle > led_lit_time)
 ^~
Main_Code_PT2399_edit:704:1: error: expected declaration before '}' token
 }
 ^
Multiple libraries were found for "SPI.h"
 Used: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI
Multiple libraries were found for "EEPROM.h"
 Used: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/EEPROM
exit status 1
'decreaseincrease' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Main_Code_PT2399_edit.ino (36.6 KB)

EEPROMAnything.h (502 Bytes)

You commented out the declaration of the variable decreaseincrease, but your code still uses it.
Apparently, you commended out everyting you didn't need plus a bit more.

Your parenthesis also appear to be off since a lot of your code is outside a function.

You can also comment out large blocks of code much easier doing this

#if 0
//... all your code here
#end if

Than commenting out each line individually

fixed that, more problems :o

Arduino: 1.8.10 (Mac OS X), Board: "Arduino/Genuino Uno"

Main_Code_PT2399_edit:564:1: error: 'readingtapbutton' does not name a type
 readingtapbutton = digitalRead(tapbuttonpin);               // read the state of the button into a local variable
 ^~~~~~~~~~~~~~~~
Main_Code_PT2399_edit:565:1: error: expected unqualified-id before 'if'
 if (readingtapbutton != lasttapbuttonstate)                 // the following loop will only be done, if the button state has changed
 ^~
Main_Code_PT2399_edit:569:1: error: expected unqualified-id before 'if'
 if ((millis() - lastDebounceTime) > debounceDelay)          // the following loop will only be done, if the last change of the button exceeds the debounce time (=is a button press, not noise)
 ^~
Main_Code_PT2399_edit:600:1: error: 'lasttapbuttonstate' does not name a type
 lasttapbuttonstate = readingtapbutton;                    // save the reading to determine whether the button state has changed next time
 ^~~~~~~~~~~~~~~~~~
Main_Code_PT2399_edit:602:1: error: expected unqualified-id before 'if'
 if (millis() - firsttapmillis > 1000)                     // if there is more than 1000 ms between two taps, delta measuremant resumes; it can be longer than max_delay due to subdivision...
 ^~
Main_Code_PT2399_edit:608:1: error: 'blinkfreq' does not name a type
 blinkfreq = current_ms;                                                                      // current_ms_subdiv / subdivisionfactor[arrayid];
 ^~~~~~~~~
Main_Code_PT2399_edit:609:1: error: 'currentMillis' does not name a type
 currentMillis = millis();
 ^~~~~~~~~~~~~
Main_Code_PT2399_edit:610:13: error: expected constructor, destructor, or type conversion before '(' token
 digitalWrite(greenpin, currentgreen);
             ^
Main_Code_PT2399_edit:611:12: error: expected constructor, destructor, or type conversion before '(' token
 analogWrite(redpin, currentred);
            ^
Main_Code_PT2399_edit:612:12: error: expected constructor, destructor, or type conversion before '(' token
 analogWrite(bluepin, currentblue);
            ^
Main_Code_PT2399_edit:613:1: error: expected unqualified-id before 'if'
 if (currentMillis - blinkfreq > lastblinktoggle)
 ^~
Main_Code_PT2399_edit:619:1: error: expected unqualified-id before 'if'
 if (currentMillis - lastblinktoggle > led_lit_time)
 ^~
Main_Code_PT2399_edit:704:1: error: expected declaration before '}' token
 }
 ^
Multiple libraries were found for "SPI.h"
 Used: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI
Multiple libraries were found for "EEPROM.h"
 Used: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/EEPROM
exit status 1
'readingtapbutton' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Please post the code that produced those errors

Those errors relate to my other comment - your parenthesis are off. If you auto-format your code (Ctrl-T) you will see the closing '}' for loop followed by a bunch more code. This is wrong. That closing '} needs to be further down your code.

I can't see where the problem is
the braces all look fine to me

When I run into issues like this I'll...

Nevermind, just do this.

Stop trying to hack some code you found into doing what you want. Start over fresh ONLY putting in what you want and (( ONLY THE BITS YOU UNDERSTAND LEAVE OUT EVERYTHING ELSE. )). You can use the code you found that "almost works" as a guide. Then, what you will be working on will no longer be some dark mystery from anothers mind. It'll be in your thinking.

I might even start by laying it out in human.

I want to do this
then this
and if I see this I'll do.. a OR b

You get the picture.

-jim lee

Deleted the brace on line 504
thanks for the tips guys

It didn’t work so I’m back to square one

can anyone help me figure out how to use normal analog potentiometers with this sketch,
instead of the rotary encoders?

Leetut:
It didn’t work so I’m back to square one

can anyone help me figure out how to use normal analog potentiometers with this sketch,
instead of the rotary encoders?

You posted a lot of different versions so we need to see at least, the latest version that you are working on.