store different values into two variables from rotary encoder

ebeowulf17

Joined Aug 12, 2014
3,307
Ummm i've put them back into the place they were and now all resets zero on the second pass
Code:
ENC_SWstate =digitalRead(ENC_SW);
if (ENC_SWstate == LOW && prevENC_SWstate == HIGH)
{
delay(50); //debounce period
ENC_SWstate =digitalRead(ENC_SW);
if (ENC_SWstate == LOW) //stable LOW
{
Counter1 = w1Value /10<<1;
Serial.print("Pass:");
Serial.println(Counter);
Serial.print("Counter:");
Serial.println(Counter1);
Serial.print("W1:");
Serial.println(w1Value);
Serial.print("W2:");
Serial.println(WeldTime);
Serial.print("pValue:");
Serial.println(pValue);
Serial.println(" ");
confMenu =1;
Counter++;
}
}
prevENC_SWstate = ENC_SWstate;
while (confMenu ==1)
{
ENC_SWstate =digitalRead(ENC_SW);
if (ENC_SWstate != prevENC_SWstate)
{
if (ENC_SWstate == LOW)
{
select +=1;
select = select %4;
if (select ==0)
{
noInterrupts();
Counter1 = w1Value /10<<1;
interrupts();
}
if (select ==1)
{
noInterrupts();
Counter1 = WeldTime /10<<1;
interrupts();
}
if (select ==2)
{
noInterrupts();
Counter1 = pValue /10<<1;
interrupts();
}
}
prevENC_SWstate = ENC_SWstate;
}

switch (select)
{
case0: //W1
clearSelectPointer(1);
lcd.setCursor(0, 0);
lcd.print(">");
w1Value =readEncoder() %6*10;
if (w1Value <=0)
{
w1Value =0;
}
lcd.setCursor(1, 0);
lcd.print("W1:");
lcd.print(w1Value);
lcd.print(" ");
break;

case1: //W2
clearSelectPointer(2);
lcd.setCursor(0, 1);
lcd.print(">");
WeldTime =readEncoder() %51*10;
if (WeldTime <=0)
{
WeldTime =0;
}
lcd.setCursor(1, 1);
lcd.print("W2:");
lcd.print(WeldTime); //lcd.setCursor(5, 1);
lcd.print(" ");
break;

case2: //P
clearSelectPointer(3);
lcd.setCursor(8, 1);
lcd.print(">");
pValue =readEncoder() %11*10;
if (pValue <=0)
{
pValue =0;
}
lcd.setCursor(9, 1);
lcd.print("P:");
lcd.print(pValue);
lcd.print("%");
lcd.print(" ");
break;
default:
clearSelectPointer(4);
confMenu =0;
select =0;
break;
}
}
here is the output
Hmph. Could you post your compete code again, including functions and interrupts?

I'd like to see what else changed. We were much closer than this on earlier attempts. I won't be available for a few hours, but I'll take a look this evening. I don't have an Arduino free to run this on, but I'll try converting it to C and running it on my computer to see if I can catch the bug.

Cheers!
 

ebeowulf17

Joined Aug 12, 2014
3,307
Ok, I've tested what I can in my C editor/compiler (codeblocks.) I had to comment out a LOT of code because I'm not using LCD displays or a rotary encoder (I replaced the rotary encoder lines with code that responds to keyboard inputs.) Anyway, the math is all working as I expected - it takes two increments or decrements from the rotary encoder to achieve one step change in either direction because of the unnecessary bit shift operations, but it's basically functional. The numbers are maintained through each cycle and nothing resets to zero.

However, among the many things I had to comment out in order the get this working in C instead of on an Arduino were the hardware interrupts. Once I had confirmed that the basic math with the modulos, the x10 multiplications, and the bit shifts was all working as expected, I searched for any other lines of code that can reset the Counter1 rotary encoder variable, and I found this:
Code:
byte resetFlag = false;

****************************************************************************

attachPCINT(digitalPinToPCINT(ENC_SW), resetENC, RISING);

****************************************************************************

void resetENC()
{
  if (resetFlag == false)
  {
    Counter1 = 0;
  }
}
It looks like there's a resetFlag variable that gets initialized as false, and then gets checked any time the encoder switch is released. If the flag is false (which it always will be since there aren't any other lines of code that modify it,) then it resets the Counter1 variable to 0. Perhaps this is the source of all the zero-resets?

I don't see any benefit in having the encoder reset to zero when the button is pressed - at least not in terms of the section we've been discussing which is used to set parameters (confMenu.) Is that reset needed for other aspects of operation? If not, I'd eliminate that resetENC function entirely. If it is needed for other functions, maybe handle it with conditionals in other loops as needed, instead of handling it with an interrupt which triggers it during the parameter setting in the configuration menu.

Here's the output of my test-code. On the pass 0 I set each of the three variables to different values, then I cycled through the next pass just pressing enter (equivalent of you pressing the encoder switch, but not changing any values,) then I changed values again on pass 2. Everything worked as expected (but I didn't have the resetENC() function being called by interrupts, and I believe that's the difference.)
Begin main loop

Pass: 0
Encoder: 0
W1: 0
W2: 0
pValue: 0

Press =/- to change W1. W1 set to 20
Press =/- to change W2. W2 set to 10
Press =/- to change P. P set to 30

Pass: 1
Encoder: 4
W1: 20
W2: 10
pValue: 30

Press =/- to change W1. W1 set to 20
Press =/- to change W2. W2 set to 10
Press =/- to change P. P set to 30

Pass: 2
Encoder: 4
W1: 20
W2: 10
pValue: 30

Press =/- to change W1. W1 set to 10
Press =/- to change W2. W2 set to 20
Press =/- to change P. P set to 50

Pass: 3
Encoder: 2
W1: 10
W2: 20
pValue: 50

Press =/- to change W1. W1 set to 10
Press =/- to change W2. W2 set to 20
Press =/- to change P. P set to 50

Pass: 4
Encoder: 2
W1: 10
W2: 20
pValue: 50
 

ebeowulf17

Joined Aug 12, 2014
3,307
Oh, I almost forgot, I'll share the modified code that I was testing in C. Like I said, I commented out a lot of stuff that wouldn't make sense when running on a computer instead of an Arduino, and I had to redifine byte variables as ints, and booleans as _Bools, and I added a function called "checkButtons()" in order to read keyboard button presses instead of rotary encoder inputs, but all the basic logic and flow is intact:
Code:
#include <stdio.h>
#include <conio.h>      // for kbhit()
//#include <Arduino.h>
//#include <EEPROM.h>
//#include <NTC_Thermistor.h>
//#include <PinChangeInterrupt.h>
//#include <Servo.h>
//#include <Wire.h>
//#include <hd44780.h>
//#include <hd44780ioClass/hd44780_I2Cexp.h>
//hd44780_I2Cexp lcd;
//Servo myServo;
// Const Variables and pin assinged
const int ENC_SW = 3;   // Encoder Switch
const int rdy = 4;      // READY LED
const int servoPin = 6; // Servo
const int ENC_PinA = 7;  // PIN A of Encoder
const int bzr = 5;      // Buzzer
const int ENC_PinB = 8;  // PIN B of Encoder
const int buttonPin = 9; // Weld button
const int cs = 10;      // Contact Sense
const int TRIAC = 1;    // Load
const int shortPress = 1;
const int longPress = 2;
const int longerPress = 3;
const int tgr_dly = 5084;  // delay after zero cross at peak sine - average of 50/60Hz
const int shortTime = 200; // if equal longTime there is no unrecorded press
const int longTime = 500;
const int longerTime = 2000;
const int pause = 450;    // pause value between dual pulses
const int delayTime = 50; // bounce delay for Encoder Switch
// Variables
#define Temp A6  // NTC PIN
#define RR 10000 // Reference Resistance
#define NR 10000 // Nominal Resistance
#define NT 25    // Nominal Temperature
#define B_Val 3435
// NTC_Thermistor *thermistor;
int zCd = 2; // Zero Crossing Detect
int weldCont = 0;
int menuSelect = 0;
int stayInMenu = 0;
int weldExitFlag = 0;
int previousButtonState = 1;
int buttonState = 1;
int prevENC_SWstate = 1;
int ENC_SWstate = 1;
int buttonFlag;
int resetFlag = 0;
int manualWeld = 0;
int testLoop = 1;
int cs_State;
int prevCS_State;
int currCS_State;
int congMenu1;
int confMenu;
int rdyState;
int WeldVal;
int ENC_PinAState = 0;
int ENC_PinALastState = 0;
int WeldTime; // read value from rotaryEncoder()
int prevRotaryVal;
int W2Addr = 110;       // Address block to store W2 value
int PreWeldAddr = 120;  // Address block to store PreWeld time
int startSrvAddr = 130; // Address block to store servo Start degree
int endSrvAddr = 140;   // Address block to store servo end degree
int W2;
int pre;
int SrvPotMap1;
int SrvPotMap2;
int counter;            // Auto weld counter
int WeldStepValue = 10; // Value of POT in milliseconds
int OldWeldStepValue;   // Old value of POT
int PotValue;           // Actual POT value
int ConfigureVal;
int w1Value;
int pValue;
int select;
int Counter1;
int Counter;
unsigned long TimeStamp;
unsigned long ENC_SWpressDuration;
unsigned long buttonPressStartTimeStamp;
unsigned long buttonPressDuration;
unsigned long timeCheck = 1000; // time to check zero cross error
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long prevT;
unsigned long currT;
unsigned long delayT = 500;
_Bool startTimeout = 0; // zc sense error timeout
volatile _Bool zeroCrossingFlag = 0;
//void setup()
//{
//  lcd.clear();
//  lcd.begin(16, 2);
//  thermistor = new NTC_Thermistor(Temp, RR, NR, NT, B_Val);
//  ServoReturn();
//  pre = EEPROM.read(PreWeldAddr);
//  SrvPotMap1 = EEPROM.read(endSrvAddr);
//  SrvPotMap2 = EEPROM.read(startSrvAddr);
//  W2 = EEPROM.read(W2Addr);
//  pinMode(buttonPin, INPUT_PULLUP);
//  pinMode(ENC_PinA, INPUT_PULLUP);
//  pinMode(ENC_PinB, INPUT_PULLUP);
//  pinMode(zCd, INPUT_PULLUP);
//  pinMode(cs, INPUT_PULLUP);
//  pinMode(ENC_SW, INPUT_PULLUP);
//  pinMode(servoPin, OUTPUT);
//  pinMode(TRIAC, OUTPUT);
//  pinMode(rdy, OUTPUT);
//  pinMode(bzr, OUTPUT);
//  pinMode(A2, INPUT);
//  pinMode(A4, INPUT_PULLUP);
//  pinMode(A5, INPUT_PULLUP);
//  attachInterrupt(0, setFlag, FALLING); // zero cross
//  attachPCINT(digitalPinToPCINT(ENC_PinA), rotaryEncoder, CHANGE);
//  attachPCINT(digitalPinToPCINT(ENC_SW), resetENC, RISING);
//  attachPCINT(digitalPinToPCINT(buttonPin), WeldExit, CHANGE);
//  delay(10);
//  lcd.clear();
//  lcd.setCursor(0, 0);
//  lcd.print("Max Weld");
//  lcd.setCursor(12, 0);
//  lcd.print("v3.0");
//  lcd.setCursor(0, 1);
//  lcd.print("GT Designs");
//  delay(2000);
//  lcd.clear();
//  Display();
//  startupTone();
//  Serial.begin(115200);
//}

// ------------------------------------------------ FUNCTIONS ---------------------------------
//void startupTone()
//{
//  tone(bzr, 2500);
//  delay(120);
//  noTone(bzr);
//  delay(240);
//  tone(bzr, 2500);
//  delay(120);
//  noTone(bzr);
//}
//
//void weldTone()
//{
//  if (manualWeld == 0)
//  {
//    tone(bzr, 2322);
//    delay(70);
//    noTone(bzr);
//    tone(bzr, 2222);
//    delay(70);
//    noTone(bzr);
//  }
//  else
//  {
//    tone(bzr, 3153);
//    delay(50);
//    noTone(bzr);
//  }
//}
//
//void saveSuccess()
//{
//  pinMode(bzr, OUTPUT);
//  tone(bzr, 2025);
//  delay(300);
//  noTone(bzr);
//}
//
//void resetENC()
//{
//  if (resetFlag == 0)
//  {
//    Counter1 = 0;
//  }
//}
//
//void Display()
//{
//  lcd.clear();
//  lcd.setCursor(1, 0);
//  lcd.print("W1:");
//  lcd.print(pre);
//  myServo.detach();
//}
//
//void rotaryEncoder()
//{
//  ENC_PinAState = digitalRead(ENC_PinA);
//  if (digitalRead(ENC_PinB) != ENC_PinAState)
//  {
//    Counter1--;
//  }
//  else
//  {
//    Counter1++;
//  }
//}
_Bool checkButtons()
{

    _Bool up = 0;
    _Bool down = 0;
    _Bool enter = 0;
    if(kbhit())
    {
        char tempKey = getch();
        //printf("%d\n",tempKey);
        if (tempKey==61) // 43='+' and 61='='
        {
            up=1;
            Counter1++;
        }
        if (tempKey==45)
        {
            down=1;
            Counter1--;
        }
        if (tempKey==13) // 10 is enter key? or maybe 13?
        {
            enter=1;
        }
    }
    return enter;

}

int readEncoder()
{
  // noInterrupts();
  int copyCounter = Counter1;
  // interrupts();
  return (copyCounter) >> 1;
}

//void Weld() // Actual weld
//{
//  int wait;
//  if (SrvPotMap1 && SrvPotMap2 == 0)
//  // disables servo when both servo pot values are zero and set wait value
//  {
//    wait = 700;
//  }
//  else
//  {
//    wait = 0;
//  }
//  if (W2 <= 0)
//  {
//    WeldVal = WeldTime;
//  }
//  else
//  {
//    WeldVal = W2;
//  }
//  delay(wait);
//  myServo.attach(servoPin);
//  digitalWrite(rdy, 0);
//  ServoStart();
//  buttonState = digitalRead(buttonPin);
//  zeroCrossingFlag = 0; // set flag 0 and wait for next zero crossing
//  while (!zeroCrossingFlag)
//  {
//  };
//  delayMicroseconds(tgr_dly);
//  digitalWrite(TRIAC, 1);
//  delay(pre); // preWeld time ms
//  digitalWrite(TRIAC, 0);
//  if (WeldVal > 0)
//  {
//    delay(pause);
//    zeroCrossingFlag = 0; // set flag false and wait for next zero crossing
//    while (!zeroCrossingFlag)
//    {
//    };
//    delayMicroseconds(tgr_dly);
//    digitalWrite(TRIAC, 1);
//    delay(WeldVal);
//    digitalWrite(TRIAC, 0);
//  }
//  ServoReturn();
//  myServo.detach();
//  weldTone();
//}
//
//void WeldExit()
//{
//  if (weldCont == true)
//  {
//    weldExitFlag = true; // exit Auto Weld
//  }
//}

//void contactSense()
//{
//  lcd.clear();
//  manualWeld = 1;
//  weldCont = true;
//  weldExitFlag = 0;
//  lcd.setCursor(0, 0);
//  lcd.print("T:");
//  lcd.print(String(thermistor->readCelsius()));
//  lcd.setCursor(0, 1);
//  lcd.print("W2:");
//  lcd.print(WeldTime);
//  tone(bzr, 3256);
//  delay(30);
//  noTone(bzr);
//  delay(100);
//  tone(bzr, 4256);
//  delay(30);
//  noTone(bzr);
//  delay(50);
//  tone(bzr, 5256);
//  delay(30);
//  noTone(bzr);
//  while (weldExitFlag == 0)
//  {
//    currT = millis();
//
//    if (currT - prevT >= delayT)
//    {
//      prevT = currT;
//      if (rdyState == 0)
//      {
//        rdyState = 1;
//      }
//      else
//      {
//        rdyState = 0;
//      }
//      digitalWrite(4, rdyState);
//    }
//    WeldTime += (readEncoder() % 101) * 10;
//    if (WeldTime <= 0)
//    {
//      WeldTime = 0;
//    }
//    lcd.setCursor(0, 1);
//    lcd.print("W2:");
//    lcd.print(WeldTime);
//    zeroCrossingFlag = 0;
//    while (!zeroCrossingFlag)
//    {
//    };
//    delayMicroseconds(8500);
//    digitalWrite(TRIAC, 1);
//    delayMicroseconds(200); // preWeld time ms
//    digitalWrite(TRIAC, 0);
//
//    cs_State = digitalRead(cs);
//    if (cs_State == 1 && prevCS_State == 0)
//    {
//      delay(500);
//      Weld();
//    }
//    if (prevCS_State == 1 && cs_State == 0)
//    {
//      prevCS_State = 0;
//    }
//  }
//  buttonState = 0;
//  previousButtonState = 0;
//}

void setFlag()
{
  zeroCrossingFlag = 1; // interrupt sets flag true
}

//void ServoStart() // Increments to start position from Finish
//{
//  for (int i = SrvPotMap1; i <= SrvPotMap2; i += 1)
//  {
//    myServo.attach(servoPin);
//    myServo.write(i);
//    delay(5);
//  }
//}
//
//void ServoReturn() // Increments to Finish position from Start
//{
//  for (int i = SrvPotMap2; i >= SrvPotMap1; i -= 1)
//  {
//    myServo.write(i);
//    delay(5);
//  }
//}
//
//void configMenu() // End configuration mode.
//{
//  lcd.clear();
//  lcd.setCursor(0, 0);
//  lcd.print("CONFIG MODE");
//  delay(800);
//  lcd.clear();
//  lcd.setCursor(1, 0);
//  lcd.print("Start");
//  lcd.setCursor(7, 0);
//  lcd.print("End");
//  lcd.setCursor(11, 0);
//  lcd.print("Test");
//  lcd.setCursor(1, 1);
//  lcd.print("Exit");
//  myServo.detach();
//}
//
//int clearSelectPointer(int checkPointer)
//{
//  switch (checkPointer)
//  {
//  case 1:                // for select 1
//    lcd.setCursor(0, 1); // 2
//    lcd.print(" ");
//    lcd.setCursor(8, 1); // 3
//    lcd.print(" ");
//    break;
//  case 2:                // for select 2
//    lcd.setCursor(0, 0); // 1
//    lcd.print(" ");
//    lcd.setCursor(8, 1); // 3
//    lcd.print(" ");
//    break;
//  case 3:                // for select 3
//    lcd.setCursor(0, 0); // 1
//    lcd.print(" ");
//    lcd.setCursor(0, 1); // 2
//    lcd.print(" ");
//    break;
//  case 4:
//    lcd.setCursor(0, 0); // 1
//    lcd.print(" ");
//    lcd.setCursor(0, 1); // 2
//    lcd.print(" ");
//    lcd.setCursor(8, 1); //3
//    lcd.print(" ");
//    break;
//  }
//  return (checkPointer);
//}
// ------------------------------------------------ END OF FUNCTIONS --------------------------
int main() // previously void loop()
{
//  lcd.setCursor(1, 1);
//  lcd.print("W2:");
//  lcd.print(WeldTime);
//  lcd.setCursor(9, 0);
//  lcd.print("T:");
//  lcd.print(String(thermistor->readCelsius()));
//  lcd.setCursor(9, 1);
//  lcd.print("P:");
//  digitalWrite(rdy, 1);

//  ENC_SWstate = digitalRead(ENC_SW);

printf("Begin main loop\n");

while(1)
{

  if (checkButtons())
  {
    // delay(50); //debounce period
    // ENC_SWstate = digitalRead(ENC_SW);
    if (1) //stable 0
    {
      Counter1 = w1Value / 10 << 1;
//      Serial.print("Pass:");
//      Serial.println(Counter);
//      Serial.print("Counter:");
//      Serial.println(Counter1);
//      Serial.print("W1:");
//      Serial.println(w1Value);
//      Serial.print("W2:");
//      Serial.println(WeldTime);
//      Serial.print("pValue:");
//      Serial.println(pValue);
//      Serial.println(" ");
        printf("\nPass:    %d\n",Counter);
        printf("Encoder: %d\n",Counter1);
        printf("W1:      %d\n",w1Value);
        printf("W2:      %d\n",WeldTime);
        printf("pValue:  %d\n\n",pValue);
        printf("Press =/- to change W1. ");
      confMenu = 1;
      Counter++;
    }
  }
//  prevENC_SWstate = ENC_SWstate;
  while (confMenu == 1)
  {
    // ENC_SWstate = digitalRead(ENC_SW);
    if (checkButtons())
    {
      if (1)
      {
        select += 1;
        select = select % 4;
        if (select == 0)
        {
          // noInterrupts();
          Counter1 = w1Value / 10 << 1;
          // interrupts();
        }
        if (select == 1)
        {
          // noInterrupts();
          printf("W1 set to %d\n",w1Value);
          printf("Press =/- to change W2. ");
          Counter1 = WeldTime / 10 << 1;
          // interrupts();
        }
        if (select == 2)
        {
          // noInterrupts();
          Counter1 = pValue / 10 << 1;
          printf("W2 set to %d\n",WeldTime);
          printf("Press =/- to change P. ");
          // interrupts();
        }
      }
      // prevENC_SWstate = ENC_SWstate;
    }

    switch (select)
    {
    case 0: //W1
//      clearSelectPointer(1);
//      lcd.setCursor(0, 0);
//      lcd.print(">");
      w1Value = readEncoder() % 6 * 10;
      if (w1Value <= 0)
      {
        w1Value = 0;
      }
//      lcd.setCursor(1, 0);
//      lcd.print("W1:");
//      lcd.print(w1Value);
//      lcd.print("  ");

      break;

    case 1: //W2
//      clearSelectPointer(2);
//      lcd.setCursor(0, 1);
//      lcd.print(">");
      WeldTime = readEncoder() % 51 * 10;
      if (WeldTime <= 0)
      {
        WeldTime = 0;
      }
//      lcd.setCursor(1, 1);
//      lcd.print("W2:");
//      lcd.print(WeldTime); //lcd.setCursor(5, 1);
//      lcd.print("  ");
      break;

    case 2: //P
//      clearSelectPointer(3);
//      lcd.setCursor(8, 1);
//      lcd.print(">");
      pValue = readEncoder() % 11 * 10;
      if (pValue <= 0)
      {
        pValue = 0;
      }
//      lcd.setCursor(9, 1);
//      lcd.print("P:");
//      lcd.print(pValue);
//      lcd.print("%");
//      lcd.print("  ");
      break;
    default:
      // clearSelectPointer(4);
      printf("P set to %d\n",pValue);
      confMenu = 0;
      select = 0;
      break;
    }
  }

if (zeroCrossingFlag)
// exit while loop due to flag set
{
  zeroCrossingFlag = 0;
}

//switch (checkButton())
//{
//case shortPress:
//  lcd.clear();
//  lcd.print("Welding....");
//  Weld();
//  lcd.clear();
//  lcd.setCursor(0, 0);
//  lcd.print("W1:");
//  lcd.print(pre);
//  lcd.setCursor(9, 0);
//  lcd.print("T:");
//  lcd.print(char(0xDF));
//  lcd.print("C");
//  break;
//case longPress:
//  lcd.clear();
//  lcd.setCursor(0, 0);
//  lcd.print("Auto Weld");
//  delay(800);
//  contactSense();
//  break;
//case longerPress:
//  lcd.clear();
//  configMenu();
//  tone(bzr, 2220);
//  delay(30);
//  noTone(bzr);
//  delay(200);
//  tone(bzr, 1200);
//  delay(30);
//  noTone(bzr);
//  delay(200);
//  tone(bzr, 800);
//  delay(30);
//  noTone(bzr);
//  break;
//}
}
}

// end of Loop
//int checkButton()
//{
//  int event = 0;
//  buttonState = digitalRead(buttonPin);
//  // button pressed
//  if (buttonState == 0 && previousButtonState == 1)
//  {
//    delay(20);                            // blocking debounce routine
//    buttonState = digitalRead(buttonPin); // read button again
//    if (buttonState == 0 && previousButtonState == 1)
//    {
//      buttonPressStartTimeStamp = millis();
//      startTimeout = true;
//    }
//  }
//  // button released
//  if (buttonState == 1 && previousButtonState == 0)
//  {
//    delay(20);                            // blocking debounce routine
//    buttonState = digitalRead(buttonPin); // read button again
//    if (buttonState == 1 && previousButtonState == 0)
//    {
//      buttonPressDuration = (millis() - buttonPressStartTimeStamp);
//      startTimeout = 0; // duration determined no timeout required
//    }
//  }
//
//  if (buttonPressDuration > 0 && buttonPressDuration <= shortTime)
//  {
//    event = shortPress;
//    buttonPressDuration = 0;
//  }
//
//  if (buttonPressDuration > longTime && buttonPressDuration <= longerTime)
//  {
//    event = longPress;
//    buttonPressDuration = 0;
//    previousButtonState = buttonState;
//  }
//  // button not released and still timing
//  if (buttonState == 0 && startTimeout == true && (millis() - buttonPressStartTimeStamp) > longerTime)
//  {
//    event = longerPress;
//    digitalWrite(rdy, 0);
//    startTimeout = 0;
//  }
//  buttonPressDuration = 0;
//  previousButtonState = buttonState;
//  prevENC_SWstate = ENC_SWstate;
//  return event;
//}
 

Thread Starter

anishkgt

Joined Mar 21, 2017
549
Thank s a lot for your time ebeowulf17.

Just after posted my las post I read your previous post and that reminded me that there was indeed a function that resets the Counter1 to zero. I commented out the pin interrupt for that pin but forgot to comment out the function and initialization of that variable.

I will test it once I get back home and update.
 

Thread Starter

anishkgt

Joined Mar 21, 2017
549
Well well, that was it. All looks good now.
here is the output
Pass:1
Select:0
Counter:0
W1:0
W2:0
pValue:0

Pass:1
Select:1
Counter:0
W1:50
W2:0
pValue:0

Pass:1
Select:2
Counter:0
W1:50
W2:70
pValue:0

Pass:1
Select:3
Counter:18
W1:50
W2:70
pValue:90

Pass:2
Select:0
Counter:10
W1:50
W2:70
pValue:90

Pass:2
Select:2
Counter:18
W1:50
W2:80
pValue:90

Pass:2
Select:3
Counter:24
W1:50
W2:80
pValue:10
Pass:3
Select:0
Counter:10
W1:50
W2:80
pValue:10

Pass:3
Select:1
Counter:16
W1:40
W2:80
pValue:10

Pass:3
Select:1
Counter:16
W1:40
W2:80
pValue:10

Pass:3
Select:2
Counter:2
W1:40
W2:60
pValue:10

Pass:3
Select:2
Counter:2
W1:40
W2:60
pValue:10

Pass:3
Select:3
Counter:4
W1:40
W2:60
pValue:20

Pass:4
Select:0
Counter:8
W1:40
W2:60
pValue:20
 
Top