countdown timer. - Meditation bell

Hey Y'all. Im as green as it gets here. So don't get too tarzan on me.

Im trying to build a meditation timer. and I've been taking baby steps. So far I have successfully used a 5v signal to fire a 12v solenoid. I have ran a loop to count from 0 to 9 on a single 7 segment LED display using a shift register.

the next mile stone i wish to reach is to get down the interface with the single digit 7 segment led, the shift register and a rotary encoder. I would like the sketch so when the encoder is spun clockwise it will count to 9 and if spun counter-clockwise it will subtract to 0

this is what i am using 1

  1. 7 segment led (common cathode)
  2. ran by a SN74HC595N shift register
  3. rotary encoder with push button.
  4. all on a Digispark

I have been struggling with the interface between the rotary encoder and the shift register. I can't seem to find a good example of how to output (what i am calling) encoderValue to the led display

I also don't know where to put constrains on the counting like encoderValue must be <10 and >-1??

I feel like i need to insert this bit of code in the sketch but not sure where.
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, (encoderValue));
digitalWrite(latchPin, HIGH); delay(1000);
delay(1000);

could someone point out what i am totally doing wrong or maybe point me in a direction where someone may have already done this code before?

I've attached what i am trying to get to work

roatary_and_led_rev-A.ino (1.81 KB)

Hey Y'all. Im as green as it gets here. So don't get too tarzan on me.

Im trying to build a meditation timer. and I've been taking baby steps. So far I have successfully used a 5v signal to fire a 12v solenoid. I have ran a loop to count from 0 to 9 on a single 7 segment LED display using a shift register.

the next mile stone i wish to reach is to get down the interface with the single digit 7 segment led, the shift register and a rotary encoder. I would like the sketch so when the encoder is spun clockwise it will count to 9 and if spun counter-clockwise it will subtract to 0

this is what i am using 1

  1. 7 segment led (common cathode)
  2. ran by a SN74HC595N shift register
  3. rotary encoder with push button.
  4. all on a Digispark

I have been struggling with the interface between the rotary encoder and the shift register. I can't seem to find a good example of how to output (what i am calling) encoderValue to the led display

I also don't know where to put constrains on the counting like encoderValue must be <10 and >-1??

I feel like i need to insert this bit of code in the sketch but not sure where.
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, (encoderValue));
digitalWrite(latchPin, HIGH); delay(1000);
delay(1000);

could someone point out what i am totally doing wrong or maybe point me in a direction where someone may have already done this code before?

I've attached what i am trying to get to work

roatary_and_led_rev-A.ino (1.81 KB)

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Also please do not cross post, more than one posting of the same thread will only lead to confusion.

Tom.... :slight_smile:

I feel like i need to insert this bit of code in the sketch but not sure where.
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, (encoderValue));
digitalWrite(latchPin, HIGH); delay(1000);
delay(1000);

Where does that read the encoder value? Where does that constrain the encoder value?

Why are there two delays()?

Do you want us to wait two days to respond to your request for help?

When do you want the encoder value to be shown on the 7 segment display?

Please don't cross post(http://forum.arduino.cc/index.php?topic=427286. It's against the forum rules and wastes peoples time due to duplicate effort.

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.

Do not cross-post. Threads merged.

Thanks for your patience with me I didn't mean to create such a clutter with my problems.

I would like to add a image of how all this is wired together. i don't show the 12v power coming into the digispark.

void loop(){
 if(digitalRead(encoderPbsPin)){
   //button is not being pushed
 
 
 }else{
   //button is being pushed
 }


What rubbish formatting.

void loop()
{
   if(digitalRead(encoderPbsPin))
   {
      //button is not being pushed
   }
   else
   {
      //button is being pushed
   }
}

is a hell of a lot easier (for me) to read, and to understand where to add code.

If you want to display the encoder reading when the switch is not being pressed, the comment surely provides a clue where to put code to do that.

While it might have been easy to explain why there were 2 delay(), you have not explained why you have ANY delay().

long lastencoderValue = 0;

Variable names are supposed to use camelCase. Your camel is missing a hump.