Numbers not Display

So I've done some playing around and found that there isn't anything wrong with my counter code. However for whatever reason, when the counter counts up on my serial modem, the display isn't showing the corresponding numbers. Just zero. All the coding is there, it just seems that something isn't in the right place. I need help ASAP..

#include <ir_Lego_PF_BitStreamEncoder.h>
#include <boarddefs.h>
#include <IRremoteInt.h>
#include <IRremote.h>


//Define Sensor Pin
const int RECV_PIN = 22;

//Define LED Constants
const int bluePin = 26;
const int greenPin = 28;
const int redPin = 24;

//Define IR Reciever and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;

//Button Definition
boolean Power = false;
boolean Play = false;

//Define Integer to Remember Toggle State
int togglestate = 0;

unsigned long time;
unsigned long time2;
int counter = 0;
int counterDir = 1;
bool mainCounter = false;

//Define Pins of 4 digit 7 segment Display
int SevensegPins[7] = {2,3,4,5,6,7,8};

byte SevensegDigits[10][7] = 
{
  {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, LOW}, // 0
  {LOW,  HIGH, HIGH, LOW,  LOW,  LOW,  LOW}, // 1
  {HIGH, HIGH, LOW,  HIGH, HIGH, LOW,  LOW}, // 2
  {HIGH, HIGH, HIGH, HIGH, LOW,  LOW,  HIGH},// 3 
  {LOW,  HIGH, HIGH, LOW,  LOW,  HIGH, HIGH},// 4
  {HIGH, LOW,  HIGH, HIGH, LOW,  HIGH, HIGH},// 5
  {HIGH, LOW,  HIGH, HIGH, HIGH, HIGH, HIGH},// 6
  {HIGH, HIGH, HIGH, LOW,  LOW,  LOW,  LOW}, // 7
  {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH},// 8 
  {HIGH, HIGH, HIGH, HIGH, LOW,  HIGH, HIGH} // 9
};

//Define Digital Pins of Display
int d4 = 12;
int d3 = 11;
int d2 = 10;
int d1 = 9;

//Math
long i = 0; //i represents value displayed on display
long y = 60000; //y represents start time of count down
int x = 100;
int del = 5; //value is the degree of fine tuning the clock
int count = 0; //Set count=0. Here count is a count value that increases by 1 every 0.1 second, which means 1 second is counted when the value is 10

//Timer
int timer = 500;
int value;

void setup() {

  Serial.begin(9600);
  irrecv.enableIRIn();

  //Set LEDs as Outputs
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

  //Set LED Display Pins as Outputs
  pinMode(d1, OUTPUT);
  pinMode(d2, OUTPUT);
  pinMode(d3, OUTPUT);
  pinMode(d4, OUTPUT);
  for (int i=0; i < 7; i++) pinMode(SevensegPins[i], OUTPUT);
  time = millis();
}

void loop() {

  time2 = millis();
  if (mainCounter == true && time2 - time >= 1000) {
    counter += counterDir;
    if (counter >= 60) counterDir = -1;
    if (counter <= 0) {
      counterDir = 1;
      mainCounter = false;
    }
    Serial.print("counter = ");
    Serial.println(counter);
    time = time2;
  }

  if (irrecv.decode(&results)) {
    int value = results.value;
    Serial.println(value);
    switch (value) {
      case 0xFFA25D:
        //Power ON/OFF
        Power = !Power;
        if (Power) {
          digitalWrite(bluePin, 0xFF);
          digitalWrite(redPin, 0x00);
          digitalWrite(greenPin, 0x00);
          digitalWrite(d1, LOW);
          digitalWrite(d2, LOW);
          digitalWrite(d3, LOW);
          digitalWrite(d4, LOW);
        }
        if (!Power) {
          digitalWrite(bluePin, LOW);
          digitalWrite(redPin, LOW);
          digitalWrite(greenPin, LOW);
          digitalWrite(d1, HIGH);
          digitalWrite(d2, HIGH);
          digitalWrite(d3, HIGH);
          digitalWrite(d4, HIGH);
        }
        delay(1500);
        break;
    }
    switch (value) {
      case 0xFF22DD:
        //Play/Pause
        Play = !Play;
        if (Play) {
          mainCounter = true;
          digitalWrite(bluePin, 0x00);
          digitalWrite(redPin, 0x00);
          digitalWrite(greenPin, 0xFF);

          clear7segDigit(0);
          set7segDigit(0, (i / 1000)); // get the value of thousand
          select7segDigit(0);
          delay(del);//delay 5ms

          clear7segDigit(1);
          set7segDigit(1, (i % 1000) / 100); // get the value of hundred
          select7segDigit(1);
          delay(del);//delay 5ms

          clear7segDigit(2);
          set7segDigit(2, i % 100 / 10); //get the value of ten
          select7segDigit(2);
          delay(del);//delay 5ms

          clear7segDigit(3);
          set7segDigit(3, i % 10); //Get the value of single digit
          select7segDigit(3);
          delay(del);//delay 5ms
        }
        if (!Play) { //Pause
          mainCounter = false;
          digitalWrite(bluePin, 0xFF);
          digitalWrite(redPin, 0x00);
          digitalWrite(greenPin, 0x00);
        }
        delay(1500);
        break;
    }
    irrecv.resume();
  }

}

void select7segDigit (int digit)
{ 
  //The 7-segment LED display is a common-cathode one. So also use digitalWrite to set d1 as high and the LED will go out
  digitalWrite(d1, HIGH);
  digitalWrite(d2, HIGH);
  digitalWrite(d3, HIGH);
  digitalWrite(d4, HIGH);

  switch (digit)
  {
    case 0:
      digitalWrite(d1, LOW);//Light d1 up
      break;
    case 1:
      digitalWrite(d2, LOW); //Light d2 up
      break;
    case 2:
      digitalWrite(d3, LOW); //Light d3 up
      break;
    default:
      digitalWrite(d4, LOW); //Light d4 up
      break;
  }
}

void set7segDigit(int digit, int number) //clear the 7-segment display screen
{
  select7segDigit(digit);
  for (int i=0; i < 7; i++) digitalWrite(SevensegPins[i], SevensegDigits[number][i]);
}

void clear7segDigit(int digit) //clear the 7-segment display screen
{
  select7segDigit(digit);
  for (int i=0; i < 7; i++) digitalWrite(SevensegPins[i], LOW);
}/code]

Please post some actual serial output from the program (text, not an image please). Also, what's the hurry? Is this an overdue assignment?

aarg:
Please post some actual serial output from the program (text, not an image please). Also, what's the hurry? Is this an overdue assignment?

It's due next week, I have everything else working except for the display showing what the counter does on the Modem.

On the Modem, after I press play on my remote, the Counter starts counting up and down on the serial modem, so I know that my counter is indeed working properly. It says as follows:

The number of the button I press
counter = 1
counter = 2 and so on until it reaches 60.
......
counter = 60
counter = 59 and counts back down to 0.
......
counter = 1
counter = 0

It says it on the serial modem, just not on my 4 digit display.

Do you mean "the monitor"?

aarg:
Do you mean "the monitor"?

yes. On my screen it just calls it /dev/cu.usbmodem14101.

But I think I found exactly where the issue is. For whatever reason, it's somewhere between pickNumber(()) and void pickNumber. And I don't know how to fix it. I've been trying to fix this problem for two weeks and just now figured out where the problem is.

akeller5:
yes. On my screen it just calls it /dev/cu.usbmodem14101.

But I think I found exactly where the issue is. For whatever reason, it's somewhere between pickNumber(()) and void pickNumber. And I don't know how to fix it. I've been trying to fix this problem for two weeks and just now figured out where the problem is.

Well, you have a variable 'counter' that you print as you say, however that variable is never accessed by any of the 7 segment code. So it's easy to see why the display doesn't count. There is no such function 'pickNumber' in your code. Did you post the wrong sketch?

aarg:
Well, you have a variable 'counter' that you print as you say, however that variable is never accessed by any of the 7 segment code. So it's easy to see why the display doesn't count.

Okay, so how do I get the variable to access the 7 segment code?

Could it be that the variable counter never goes anywhere near the display code?

akeller5:
Okay, so how do I get the variable to access the 7 segment code?

Don't you mean, how do I get the 7 segment code to access the variable? Your question is too broad. Can you be more specific? What part are you having trouble with? You did say, "all the coding is there".

I put the simplified version with the arrays. So here's the unsimplified version the code with pickNumber(). But I don't know how to get the variable counter to talk with the coding for the display. So when the counter counts on the serial monitor, I want the display to show what I'm seeing on the monitor.

#include <ir_Lego_PF_BitStreamEncoder.h>
#include <boarddefs.h>
#include <IRremoteInt.h>
#include <IRremote.h>


//Define Sensor Pin
const int RECV_PIN = 22;

//Define LED Constants
const int bluePin = 26;
const int greenPin = 28;
const int redPin = 24;

//Define IR Reciever and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;

//Button Definition
boolean Power = false;
boolean Play = false;

//Define Integer to Remember Toggle State
int togglestate = 0;

unsigned long time;
unsigned long time2;
int counter = 0;
int counterDir = 1;
bool mainCounter = false;

//Define Number Pins
int a = 2;
int b = 3;
int c = 4;
int d = 5;
int e = 6;
int f = 7;
int g = 8;

//Define Digital Pins of Display
int d4 = 12;
int d3 = 11;
int d2 = 10;
int d1 = 9;

//Math
long i = 0; //i represents value displayed on display
long y = 60000; //y represents start time of count down
int x = 100;
int del = 5; //value is the degree of fine tuning the clock
int count = 0; //Set count=0. Here count is a count value that increases by 1 every 0.1 second, which means 1 second is counted when the value is 10

//Timer
int timer = 500;
int value;

void setup() {

  Serial.begin(9600);
  irrecv.enableIRIn();

  //Set LEDs as Outputs
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

 //Set All LED Display Pins as Outputs
  pinMode(d1, OUTPUT);
  pinMode(d2, OUTPUT);
  pinMode(d3, OUTPUT);
  pinMode(d4, OUTPUT);
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);

  time = millis();
}

void loop() {

  time2 = millis();
  if (mainCounter == true && time2 - time >= 1000) {
    counter += counterDir;
    if (counter >= 60) counterDir = -1;
    if (counter <= 0) {
      counterDir = 1;
      mainCounter = false;
    }
    Serial.print("counter = ");
    Serial.println(counter);
    time = time2;
  }

  if (irrecv.decode(&results)) {
    int value = results.value;
    Serial.println(value);
    switch (value) {
      case 0xFFA25D:
        //Power ON/OFF
        Power = !Power;
        if (Power) {
          digitalWrite(bluePin, 0xFF);
          digitalWrite(redPin, 0x00);
          digitalWrite(greenPin, 0x00);
          digitalWrite(d1, LOW);
          digitalWrite(d2, LOW);
          digitalWrite(d3, LOW);
          digitalWrite(d4, LOW);
        }
        if (!Power) {
          digitalWrite(bluePin, LOW);
          digitalWrite(redPin, LOW);
          digitalWrite(greenPin, LOW);
          digitalWrite(d1, HIGH);
          digitalWrite(d2, HIGH);
          digitalWrite(d3, HIGH);
          digitalWrite(d4, HIGH);
        }
        delay(1500);
        break;
    }
    switch (value) {
      case 0xFF22DD:
        //Play/Pause
        Play = !Play;
        if (Play) {
          digitalWrite(bluePin, 0x00);
          digitalWrite(redPin, 0x00);
          digitalWrite(greenPin, 0xFF);

          if (mainCounter = true){
              pickDigit(0);
              pickNumber((i/1000)); // get the value of thousand
              delay(del);//delay 5ms
    
              pickDigit(1);
              pickNumber((i%1000)/100); // get the value of hundred
              delay(del);//delay 5ms
    
              pickDigit(2);
              pickNumber(i%100/10); //get the value of ten
              delay(del);//delay 5ms
    
              pickDigit(3);
              pickNumber(i%10); //Get the value of single digit
              delay(del);//delay 5ms
          }
        }
        if (!Play) { //Pause
          mainCounter = false;
          digitalWrite(bluePin, 0xFF);
          digitalWrite(redPin, 0x00);
          digitalWrite(greenPin, 0x00);
        }
        delay(1500);
        break;
    }
    irrecv.resume();
  }
}

void pickDigit(int x)  //light up a 7-segment display
{
  //The 7-segment LED display is a common-cathode one. So also use digitalWrite to set d1 as high and the LED will go out
  digitalWrite(d1, HIGH);
  digitalWrite(d2, HIGH);
  digitalWrite(d3, HIGH);
  digitalWrite(d4, HIGH);
 
  switch(x)
  {
    case 0: 
    digitalWrite(d1, LOW);//Light d1 up 
    break;
    case 1: 
    digitalWrite(d2, LOW); //Light d2 up 
    break;
    case 2: 
    digitalWrite(d3, LOW); //Light d3 up 
    break;
  default: 
    digitalWrite(d4, LOW); //Light d4 up 
    break;
  }
}
//The function is to control the 7-segment LED display to display numbers. Here x is the number to be displayed. It is an integer from 0 to 9   
void pickNumber(int i)
{
  switch(i)
  {
    default: 
      digitalWrite(a, HIGH);
      digitalWrite(b, HIGH);
      digitalWrite(c, HIGH);
      digitalWrite(d, HIGH);
      digitalWrite(e, HIGH);
      digitalWrite(f, HIGH);
      digitalWrite(g, LOW); 
    break;
    case 1: 
      digitalWrite(a, LOW);
      digitalWrite(b, HIGH);
      digitalWrite(c, HIGH);
      digitalWrite(d, LOW);
      digitalWrite(e, LOW);
      digitalWrite(f, LOW);
      digitalWrite(g, LOW);
    break;
    case 2: 
      digitalWrite(a, HIGH);
      digitalWrite(b, HIGH);
      digitalWrite(c, LOW);
      digitalWrite(d, HIGH);
      digitalWrite(e, HIGH);
      digitalWrite(f, LOW);
      digitalWrite(g, HIGH);
    break;
    case 3: 
     digitalWrite(a, HIGH);
     digitalWrite(b, HIGH);
     digitalWrite(c, HIGH);
     digitalWrite(d, HIGH);
     digitalWrite(e, LOW);
     digitalWrite(f, LOW);
     digitalWrite(g, HIGH);
    break;
    case 4: 
     digitalWrite(a, LOW);
     digitalWrite(b, HIGH);
     digitalWrite(c, HIGH);
     digitalWrite(d, LOW);
     digitalWrite(e, LOW);
     digitalWrite(f, HIGH);
     digitalWrite(g, HIGH);
    break;
  case 5: 
    digitalWrite(a, HIGH);
    digitalWrite(b, LOW);
    digitalWrite(c, HIGH);
    digitalWrite(d, HIGH);
    digitalWrite(e, LOW);
    digitalWrite(f, HIGH);
    digitalWrite(g, HIGH);
    break;
  case 6: 
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
    break;
  case 7: 
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
    break;
  case 8: 
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
    break;
  case 9: 
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
    break;
  }
}  
/code]

if (mainCounter = true){Oops

TheMemberFormerlyKnownAsAWOL:
if (mainCounter = true){Oops

I put that in there as way of trying to get it to "access" the counter, but it didn't make a difference.

Maybe it didn't make a difference because it isn't a comparison, it's an assignment. The comparison for equality is '=='.

...and mainCounter is a boolean, so a comparison for true is superfluous

...and badly named, since the name suggests a counter rather than a counter enable.

So where exactly do I need to put == for the main counter? I put == underneath Play, where it says mainCounter = true; to mainCounter == true, and the display wouldn't turn on or even display the zero like it did before I changed it to mainCounter == true. So that way it wouldn't be an assignment but equal. Or should I maybe do "if (mainCounter = true) == counterEnable"? and then add something regarding if the counter is enabled then the display should turn on the respective numbers corresponding with the counter?? I want the display to show the numbers that I'm reading off of the serial monitor. Would that work?

It's a Boolean; you don't need to compare it to anything.

if(mainCounter)

akeller5:
Or should I maybe do "if (mainCounter = true) == counterEnable"?

It looks like you didn't understand my post. I was not talking about introducing any new variables, just naming them better. If you put that together with TMFKAAWOL's suggestion, you get:

if (counterEnabled) {

Okay yes. Makes sense. So I know that the variable counter isn't linked to the display codes. I need to somehow have a line connecting the two so that when the counter is true or enabled it will call upon those functions, pickDigit and pickNumber, so that the display will show the counter's outputs. A simplified version of what I'm trying to say is when the main counter is true/enabled, the display should show the output of the counter. And the counter only reads true/enabled when the play input has been pressed.

My question now is, "What line of code will link the variable counter coding to the display coding so that the display reads the outputs of the counter?"

Quite honestly, this is getting silly. Stop hanging around the forum and spend some time with it. Think backwards - look at the display code and decide what controls the number. Then look at the other code and see what produces the number. Then the "dotted line" will become obvious. If not, sleep on it, and look at it in the morning.