easy first. Two delays because of typo.
I would like the current encoder value to always be on display, unless the push button on the encoder is pressed. Once the pushbutton is pressed a countdown timer will commence from selected encoder value.
I guess i am not sure how to display the current encoder Value on the display.
below is the current sketch. I believe that encoderValue should start at zero and that number should be manipulated when the encoder is turned. (see bottom of sketch)
//shift register
int latchPin = 2; //pin 12 on the 595
int dataPin = 3; //pin 14 on the 595
int clockPin = 4; //pin 11 on the 595
//encoder
int encoderPin1 = 0;
int encoderPin2 = 1;
int encoderPbsPin = 5; //PBS Push button switch
volatile int lastEncoded = 0;
volatile long encoderValue = 0;
long lastencoderValue = 0;
int lastMSB = 0;
int lastLSB = 0;
//numbers
int segment[10] = {63,6,91,79,102,109,125,7,127,111 }; // for common cathode
//int segment[9] = {192,249,164,176,153,146,130,248,128 }; // for common anode
void setup(){
//Encoder void setup
pinMode(encoderPin1, INPUT);
pinMode(encoderPin2, INPUT);
pinMode(encoderPbsPin, INPUT);
digitalWrite(encoderPin1, HIGH); //turn pullup resistor on
digitalWrite(encoderPin2, HIGH); //turn pullup resistor on
digitalWrite(encoderPbsPin, HIGH); //turn pullup resistor on
//call updateEncoder() when any high/low change seen
//on interrupt 0 (pin1), or interrupt 1 (pin 2)
attachInterrupt(0, updateEncoder, CHANGE);
attachInterrupt(1, updateEncoder, CHANGE);
//shiftregister
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop(){
if(digitalRead(encoderPbsPin)){
//button is not being pushed
}else{
//button is being pushed
}
}
void updateEncoder(){
int MSB = digitalRead(encoderPin1); //MSB = Most significant bit
int LSB = digitalRead(encoderPin2); // LSB = least significant bit
int encoded = (MSB << 1) |LSB; // concerting the 2 pin value to a single number
int sum = (lastEncoded <<2) | encoded; // adding it to the previous encoded value
if(sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) encoderValue ++;
if(sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) encoderValue --;
lastEncoded = encoded; //store this value for next time
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.