Segment display











up vote
0
down vote

favorite












I am hoping that someone can guide me on this, I am at a total loss and have no idea what i need to change. I put this code together by bits and pieces from other examples I have seen. I am trying to get get the display to display the word 'End' once the countdown time has completed its cycle, I just dont understand the code to mke any further changes to the display part.



This is basically what the code does. I use a rotary and put in a time, I press the rotary switch and the timer starts counting down while displaying the value in the 4 digit 7-segment tube display. At the end of the countdown the tube diplay goes blank, instead of blank I want to display the word "End" how can I make this possible?



I know the catch is in the function setDigit() but I dont know anything about working with 7-segment display, this is my first time.



const int PinCLK = 3;  // Rotary CLK signal
const int PinDT = 2; // Rotary DT signal
const int PinSW = 0; // Rotary switch
int lastCount = 0;
volatile int virtualPosition = 0;
int timeCount = 0; // count in tenths of seconds
int sequence_Num = 0;

char disp[4];
const int PinSCLK = 10;
const int PinRCLK = 11;
const int PinDIO = 12;
int Display[4];
unsigned long prev = 0;
unsigned long waitMS = 0;

void isr()
{
static unsigned long lastInterruptTime = 0;
unsigned long interruptTime = millis();

// If interrupts come faster than 5
if(interruptTime - lastInterruptTime > 5)
{
if(digitalRead(PinDT) == LOW)
{
virtualPosition = virtualPosition+10;
}
else
{
virtualPosition = virtualPosition-10;
}

virtualPosition = min(1000, max(0, virtualPosition));
}

lastInterruptTime = interruptTime; // Keep track of when we were here last (no more than every 5ms)
}

void displayCount()
{
showDisplay();
for(int i = 0; i < 4; i++)
{
setDigit(i, Display[i]);
}
}

void setDigit(int dig, int character)
{
// 0 1 2 3 4 5 6 7 for 8 digit array
int digits = {128, 64, 32, 16, 8, 4, 2, 1};

// 21 items character set (0-9)0-9, (10-19)0.-9., (72)- (73) space
int characters = {3, 159, 37, 13, 153, 73, 65, 31, 1, 9, 2, 158, 36, 12, 152, 72, 64, 30, 0, 8, 255};

digitalWrite(PinRCLK, LOW);
shiftOut(PinDIO, PinSCLK, LSBFIRST, characters[character]);
shiftOut(PinDIO, PinSCLK, LSBFIRST, digits[dig]);
digitalWrite(PinRCLK, HIGH);
}

void showDisplay()
{
for(int i = 0; i < 4; i++)
{
int val = disp[i];
if ((val >= 32) && (val <= 47))
{
switch(val)
{
case 45 : val = 20;
break;
default : val = 20;
break;
}
}
else if ((val >= 48) && (val <= 57))
{
val -= 48;
}
Display[i] = val;
}
}

void wait(unsigned long milsec)
{
prev = millis();
waitMS = milsec;
}

void showText(char a, char b , char c, char d)
{
disp[0] = d;
disp[1] = c;
disp[2] = b;
disp[3] = a;
}

void setTimer(bool inc)
{
displayCount();
if(millis() > (prev + waitMS))
{
if(inc)
{
if(timeCount = virtualPosition)
{ // NOTE: This incrementer continues to count although the display 'int period' has occured
showText(' ', virtualPosition / 1000 % 10, virtualPosition / 100 % 10 + 10, virtualPosition / 10 % 10);
if(timeCount < virtualPosition)
{
timeCount++;
}
wait(9); // Delay to compensates for lag to count in increments of 9 milliseconds
}
}
else
{
if(timeCount <= virtualPosition)
{
showText(' ', (timeCount / 1000) % 10, (timeCount / 100) % 10 + 10, (timeCount / 10) % 10);
timeCount--;
}
wait(9);
if(timeCount == 0)
{
timeCount = virtualPosition;
sequence_Num = 1;
delay(2000);
}
}
}
}

void setup()
{
Serial.begin(9600); // Just whilst we debug, view output on serial monitor
pinMode(PinCLK, INPUT); // Rotary pulses are INPUTs
pinMode(PinDT, INPUT); // Rotary pulses are INPUTs
pinMode(PinSW, INPUT_PULLUP); // use the in-built PULLUP so we don't need a resistor

attachInterrupt(digitalPinToInterrupt(PinCLK), isr, LOW); // Attach the routine to service the interrupts
pinMode(PinRCLK, OUTPUT); // latch
pinMode(PinDIO, OUTPUT);
pinMode(PinSCLK, OUTPUT);

lastCount = virtualPosition;
sequence_Num = 1;
}

void loop()
{
// Is someone pressing the rotary switch?
if((!digitalRead(PinSW)))
{
while(!digitalRead(PinSW))
delay(9);
sequence_Num = 2;
}

switch(sequence_Num)
{
case 1:
setTimer(true);
break;
case 2:
setTimer(false);
break;
}
}


Appreciate any help and explaining so I can understand for future use.



Thanks










share|improve this question


























    up vote
    0
    down vote

    favorite












    I am hoping that someone can guide me on this, I am at a total loss and have no idea what i need to change. I put this code together by bits and pieces from other examples I have seen. I am trying to get get the display to display the word 'End' once the countdown time has completed its cycle, I just dont understand the code to mke any further changes to the display part.



    This is basically what the code does. I use a rotary and put in a time, I press the rotary switch and the timer starts counting down while displaying the value in the 4 digit 7-segment tube display. At the end of the countdown the tube diplay goes blank, instead of blank I want to display the word "End" how can I make this possible?



    I know the catch is in the function setDigit() but I dont know anything about working with 7-segment display, this is my first time.



    const int PinCLK = 3;  // Rotary CLK signal
    const int PinDT = 2; // Rotary DT signal
    const int PinSW = 0; // Rotary switch
    int lastCount = 0;
    volatile int virtualPosition = 0;
    int timeCount = 0; // count in tenths of seconds
    int sequence_Num = 0;

    char disp[4];
    const int PinSCLK = 10;
    const int PinRCLK = 11;
    const int PinDIO = 12;
    int Display[4];
    unsigned long prev = 0;
    unsigned long waitMS = 0;

    void isr()
    {
    static unsigned long lastInterruptTime = 0;
    unsigned long interruptTime = millis();

    // If interrupts come faster than 5
    if(interruptTime - lastInterruptTime > 5)
    {
    if(digitalRead(PinDT) == LOW)
    {
    virtualPosition = virtualPosition+10;
    }
    else
    {
    virtualPosition = virtualPosition-10;
    }

    virtualPosition = min(1000, max(0, virtualPosition));
    }

    lastInterruptTime = interruptTime; // Keep track of when we were here last (no more than every 5ms)
    }

    void displayCount()
    {
    showDisplay();
    for(int i = 0; i < 4; i++)
    {
    setDigit(i, Display[i]);
    }
    }

    void setDigit(int dig, int character)
    {
    // 0 1 2 3 4 5 6 7 for 8 digit array
    int digits = {128, 64, 32, 16, 8, 4, 2, 1};

    // 21 items character set (0-9)0-9, (10-19)0.-9., (72)- (73) space
    int characters = {3, 159, 37, 13, 153, 73, 65, 31, 1, 9, 2, 158, 36, 12, 152, 72, 64, 30, 0, 8, 255};

    digitalWrite(PinRCLK, LOW);
    shiftOut(PinDIO, PinSCLK, LSBFIRST, characters[character]);
    shiftOut(PinDIO, PinSCLK, LSBFIRST, digits[dig]);
    digitalWrite(PinRCLK, HIGH);
    }

    void showDisplay()
    {
    for(int i = 0; i < 4; i++)
    {
    int val = disp[i];
    if ((val >= 32) && (val <= 47))
    {
    switch(val)
    {
    case 45 : val = 20;
    break;
    default : val = 20;
    break;
    }
    }
    else if ((val >= 48) && (val <= 57))
    {
    val -= 48;
    }
    Display[i] = val;
    }
    }

    void wait(unsigned long milsec)
    {
    prev = millis();
    waitMS = milsec;
    }

    void showText(char a, char b , char c, char d)
    {
    disp[0] = d;
    disp[1] = c;
    disp[2] = b;
    disp[3] = a;
    }

    void setTimer(bool inc)
    {
    displayCount();
    if(millis() > (prev + waitMS))
    {
    if(inc)
    {
    if(timeCount = virtualPosition)
    { // NOTE: This incrementer continues to count although the display 'int period' has occured
    showText(' ', virtualPosition / 1000 % 10, virtualPosition / 100 % 10 + 10, virtualPosition / 10 % 10);
    if(timeCount < virtualPosition)
    {
    timeCount++;
    }
    wait(9); // Delay to compensates for lag to count in increments of 9 milliseconds
    }
    }
    else
    {
    if(timeCount <= virtualPosition)
    {
    showText(' ', (timeCount / 1000) % 10, (timeCount / 100) % 10 + 10, (timeCount / 10) % 10);
    timeCount--;
    }
    wait(9);
    if(timeCount == 0)
    {
    timeCount = virtualPosition;
    sequence_Num = 1;
    delay(2000);
    }
    }
    }
    }

    void setup()
    {
    Serial.begin(9600); // Just whilst we debug, view output on serial monitor
    pinMode(PinCLK, INPUT); // Rotary pulses are INPUTs
    pinMode(PinDT, INPUT); // Rotary pulses are INPUTs
    pinMode(PinSW, INPUT_PULLUP); // use the in-built PULLUP so we don't need a resistor

    attachInterrupt(digitalPinToInterrupt(PinCLK), isr, LOW); // Attach the routine to service the interrupts
    pinMode(PinRCLK, OUTPUT); // latch
    pinMode(PinDIO, OUTPUT);
    pinMode(PinSCLK, OUTPUT);

    lastCount = virtualPosition;
    sequence_Num = 1;
    }

    void loop()
    {
    // Is someone pressing the rotary switch?
    if((!digitalRead(PinSW)))
    {
    while(!digitalRead(PinSW))
    delay(9);
    sequence_Num = 2;
    }

    switch(sequence_Num)
    {
    case 1:
    setTimer(true);
    break;
    case 2:
    setTimer(false);
    break;
    }
    }


    Appreciate any help and explaining so I can understand for future use.



    Thanks










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am hoping that someone can guide me on this, I am at a total loss and have no idea what i need to change. I put this code together by bits and pieces from other examples I have seen. I am trying to get get the display to display the word 'End' once the countdown time has completed its cycle, I just dont understand the code to mke any further changes to the display part.



      This is basically what the code does. I use a rotary and put in a time, I press the rotary switch and the timer starts counting down while displaying the value in the 4 digit 7-segment tube display. At the end of the countdown the tube diplay goes blank, instead of blank I want to display the word "End" how can I make this possible?



      I know the catch is in the function setDigit() but I dont know anything about working with 7-segment display, this is my first time.



      const int PinCLK = 3;  // Rotary CLK signal
      const int PinDT = 2; // Rotary DT signal
      const int PinSW = 0; // Rotary switch
      int lastCount = 0;
      volatile int virtualPosition = 0;
      int timeCount = 0; // count in tenths of seconds
      int sequence_Num = 0;

      char disp[4];
      const int PinSCLK = 10;
      const int PinRCLK = 11;
      const int PinDIO = 12;
      int Display[4];
      unsigned long prev = 0;
      unsigned long waitMS = 0;

      void isr()
      {
      static unsigned long lastInterruptTime = 0;
      unsigned long interruptTime = millis();

      // If interrupts come faster than 5
      if(interruptTime - lastInterruptTime > 5)
      {
      if(digitalRead(PinDT) == LOW)
      {
      virtualPosition = virtualPosition+10;
      }
      else
      {
      virtualPosition = virtualPosition-10;
      }

      virtualPosition = min(1000, max(0, virtualPosition));
      }

      lastInterruptTime = interruptTime; // Keep track of when we were here last (no more than every 5ms)
      }

      void displayCount()
      {
      showDisplay();
      for(int i = 0; i < 4; i++)
      {
      setDigit(i, Display[i]);
      }
      }

      void setDigit(int dig, int character)
      {
      // 0 1 2 3 4 5 6 7 for 8 digit array
      int digits = {128, 64, 32, 16, 8, 4, 2, 1};

      // 21 items character set (0-9)0-9, (10-19)0.-9., (72)- (73) space
      int characters = {3, 159, 37, 13, 153, 73, 65, 31, 1, 9, 2, 158, 36, 12, 152, 72, 64, 30, 0, 8, 255};

      digitalWrite(PinRCLK, LOW);
      shiftOut(PinDIO, PinSCLK, LSBFIRST, characters[character]);
      shiftOut(PinDIO, PinSCLK, LSBFIRST, digits[dig]);
      digitalWrite(PinRCLK, HIGH);
      }

      void showDisplay()
      {
      for(int i = 0; i < 4; i++)
      {
      int val = disp[i];
      if ((val >= 32) && (val <= 47))
      {
      switch(val)
      {
      case 45 : val = 20;
      break;
      default : val = 20;
      break;
      }
      }
      else if ((val >= 48) && (val <= 57))
      {
      val -= 48;
      }
      Display[i] = val;
      }
      }

      void wait(unsigned long milsec)
      {
      prev = millis();
      waitMS = milsec;
      }

      void showText(char a, char b , char c, char d)
      {
      disp[0] = d;
      disp[1] = c;
      disp[2] = b;
      disp[3] = a;
      }

      void setTimer(bool inc)
      {
      displayCount();
      if(millis() > (prev + waitMS))
      {
      if(inc)
      {
      if(timeCount = virtualPosition)
      { // NOTE: This incrementer continues to count although the display 'int period' has occured
      showText(' ', virtualPosition / 1000 % 10, virtualPosition / 100 % 10 + 10, virtualPosition / 10 % 10);
      if(timeCount < virtualPosition)
      {
      timeCount++;
      }
      wait(9); // Delay to compensates for lag to count in increments of 9 milliseconds
      }
      }
      else
      {
      if(timeCount <= virtualPosition)
      {
      showText(' ', (timeCount / 1000) % 10, (timeCount / 100) % 10 + 10, (timeCount / 10) % 10);
      timeCount--;
      }
      wait(9);
      if(timeCount == 0)
      {
      timeCount = virtualPosition;
      sequence_Num = 1;
      delay(2000);
      }
      }
      }
      }

      void setup()
      {
      Serial.begin(9600); // Just whilst we debug, view output on serial monitor
      pinMode(PinCLK, INPUT); // Rotary pulses are INPUTs
      pinMode(PinDT, INPUT); // Rotary pulses are INPUTs
      pinMode(PinSW, INPUT_PULLUP); // use the in-built PULLUP so we don't need a resistor

      attachInterrupt(digitalPinToInterrupt(PinCLK), isr, LOW); // Attach the routine to service the interrupts
      pinMode(PinRCLK, OUTPUT); // latch
      pinMode(PinDIO, OUTPUT);
      pinMode(PinSCLK, OUTPUT);

      lastCount = virtualPosition;
      sequence_Num = 1;
      }

      void loop()
      {
      // Is someone pressing the rotary switch?
      if((!digitalRead(PinSW)))
      {
      while(!digitalRead(PinSW))
      delay(9);
      sequence_Num = 2;
      }

      switch(sequence_Num)
      {
      case 1:
      setTimer(true);
      break;
      case 2:
      setTimer(false);
      break;
      }
      }


      Appreciate any help and explaining so I can understand for future use.



      Thanks










      share|improve this question













      I am hoping that someone can guide me on this, I am at a total loss and have no idea what i need to change. I put this code together by bits and pieces from other examples I have seen. I am trying to get get the display to display the word 'End' once the countdown time has completed its cycle, I just dont understand the code to mke any further changes to the display part.



      This is basically what the code does. I use a rotary and put in a time, I press the rotary switch and the timer starts counting down while displaying the value in the 4 digit 7-segment tube display. At the end of the countdown the tube diplay goes blank, instead of blank I want to display the word "End" how can I make this possible?



      I know the catch is in the function setDigit() but I dont know anything about working with 7-segment display, this is my first time.



      const int PinCLK = 3;  // Rotary CLK signal
      const int PinDT = 2; // Rotary DT signal
      const int PinSW = 0; // Rotary switch
      int lastCount = 0;
      volatile int virtualPosition = 0;
      int timeCount = 0; // count in tenths of seconds
      int sequence_Num = 0;

      char disp[4];
      const int PinSCLK = 10;
      const int PinRCLK = 11;
      const int PinDIO = 12;
      int Display[4];
      unsigned long prev = 0;
      unsigned long waitMS = 0;

      void isr()
      {
      static unsigned long lastInterruptTime = 0;
      unsigned long interruptTime = millis();

      // If interrupts come faster than 5
      if(interruptTime - lastInterruptTime > 5)
      {
      if(digitalRead(PinDT) == LOW)
      {
      virtualPosition = virtualPosition+10;
      }
      else
      {
      virtualPosition = virtualPosition-10;
      }

      virtualPosition = min(1000, max(0, virtualPosition));
      }

      lastInterruptTime = interruptTime; // Keep track of when we were here last (no more than every 5ms)
      }

      void displayCount()
      {
      showDisplay();
      for(int i = 0; i < 4; i++)
      {
      setDigit(i, Display[i]);
      }
      }

      void setDigit(int dig, int character)
      {
      // 0 1 2 3 4 5 6 7 for 8 digit array
      int digits = {128, 64, 32, 16, 8, 4, 2, 1};

      // 21 items character set (0-9)0-9, (10-19)0.-9., (72)- (73) space
      int characters = {3, 159, 37, 13, 153, 73, 65, 31, 1, 9, 2, 158, 36, 12, 152, 72, 64, 30, 0, 8, 255};

      digitalWrite(PinRCLK, LOW);
      shiftOut(PinDIO, PinSCLK, LSBFIRST, characters[character]);
      shiftOut(PinDIO, PinSCLK, LSBFIRST, digits[dig]);
      digitalWrite(PinRCLK, HIGH);
      }

      void showDisplay()
      {
      for(int i = 0; i < 4; i++)
      {
      int val = disp[i];
      if ((val >= 32) && (val <= 47))
      {
      switch(val)
      {
      case 45 : val = 20;
      break;
      default : val = 20;
      break;
      }
      }
      else if ((val >= 48) && (val <= 57))
      {
      val -= 48;
      }
      Display[i] = val;
      }
      }

      void wait(unsigned long milsec)
      {
      prev = millis();
      waitMS = milsec;
      }

      void showText(char a, char b , char c, char d)
      {
      disp[0] = d;
      disp[1] = c;
      disp[2] = b;
      disp[3] = a;
      }

      void setTimer(bool inc)
      {
      displayCount();
      if(millis() > (prev + waitMS))
      {
      if(inc)
      {
      if(timeCount = virtualPosition)
      { // NOTE: This incrementer continues to count although the display 'int period' has occured
      showText(' ', virtualPosition / 1000 % 10, virtualPosition / 100 % 10 + 10, virtualPosition / 10 % 10);
      if(timeCount < virtualPosition)
      {
      timeCount++;
      }
      wait(9); // Delay to compensates for lag to count in increments of 9 milliseconds
      }
      }
      else
      {
      if(timeCount <= virtualPosition)
      {
      showText(' ', (timeCount / 1000) % 10, (timeCount / 100) % 10 + 10, (timeCount / 10) % 10);
      timeCount--;
      }
      wait(9);
      if(timeCount == 0)
      {
      timeCount = virtualPosition;
      sequence_Num = 1;
      delay(2000);
      }
      }
      }
      }

      void setup()
      {
      Serial.begin(9600); // Just whilst we debug, view output on serial monitor
      pinMode(PinCLK, INPUT); // Rotary pulses are INPUTs
      pinMode(PinDT, INPUT); // Rotary pulses are INPUTs
      pinMode(PinSW, INPUT_PULLUP); // use the in-built PULLUP so we don't need a resistor

      attachInterrupt(digitalPinToInterrupt(PinCLK), isr, LOW); // Attach the routine to service the interrupts
      pinMode(PinRCLK, OUTPUT); // latch
      pinMode(PinDIO, OUTPUT);
      pinMode(PinSCLK, OUTPUT);

      lastCount = virtualPosition;
      sequence_Num = 1;
      }

      void loop()
      {
      // Is someone pressing the rotary switch?
      if((!digitalRead(PinSW)))
      {
      while(!digitalRead(PinSW))
      delay(9);
      sequence_Num = 2;
      }

      switch(sequence_Num)
      {
      case 1:
      setTimer(true);
      break;
      case 2:
      setTimer(false);
      break;
      }
      }


      Appreciate any help and explaining so I can understand for future use.



      Thanks







      arduino segment






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 at 17:33









      sledgehammer

      4918




      4918





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435924%2fsegment-display%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435924%2fsegment-display%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          How to ignore python UserWarning in pytest?

          Alexandru Averescu