Need help with the project

byte digitOne[10]= {0x80, 0xF2, 0x48, 0x60, 0x32, 0x24, 0x04, 0xF0, 0x00, 0x30};


int tensdigit;
int unitsdigit;
int counter=0;

void setup(){
 DDRD |= B11111110;
 DDRB |= B00000110;
 PORTD = 0x00;
 PORTB = 0x00;
}

void loop(){
 if(digitalRead(11) == 1){
   for(counter = 0; counter< 100; counter++){
   }
 }

 tensdigit = counter / 10;
 unitsdigit = counter % 10;

 PORTB |= B00000100;
 PORTB &= B11111101;
 shownumber(unitsdigit);
 delay(50);

 PORTB |= B00000010;
 PORTB &= B11111011;
 shownumber(tensdigit);
 delay(50);
}

void shownumber(int number){
 switch (number){
   case 0 :
     PORTD = digitOne[0];
     break;

   case 1:
     PORTD = digitOne[1];
     break;

   case 2:
     PORTD = digitOne[2];
     break;

   case 3:
     PORTD = digitOne[3];
     break;

   case 4:
     PORTD = digitOne[4];
     break;

   case 5:
     PORTD = digitOne[5];
     break;

   case 6:
     PORTD = digitOne[6];
     break;

   case 7:
     PORTD = digitOne[7];
     break;

   case 8:
     PORTD = digitOne[8];
     break;

   case 9:
     PORTD = digitOne[9];
     break;
 }
}

this project doesnt work. can someone help? i just want it to go up when i press the button down but it keeps popping up the same "-"

Is this a school project, if so what class? Explain what you are getting and what you should be getting.

im getting this one with introductions to microcontrollers, after i press the button that is connected to 11, it needs to go up to 99 one by one, thats what i want. What i am getting is the G Led in the 7 SEGMENT display keeps lighting up like in the photo i sent, but it doesnt even change.

Explain the purpose of the empty for loop to us. What was your intention with this line?

void loop(){
  if(digitalRead(11) == 1){
  counter++;
    if(counter==100) 
     counter=0;
    delay(500);

i changed that line like this, but it still doesnt work. it keeps giving me random symbols.
but now the symbols change after i press the button. Every 10 press the left 7 SEG changes, and every press the right one changes as it should. but it doesnt give me right numbers, it gives me random symbols

Your project is wired to only count 0 to 9 on two 7segmentLEDs, not 0 to 99.

9 in the left and 9 on the right. it can go up to 99 that way. im not using only one one 7 segment.

...

I meant 0-99 Counter. and you definitely can do it with two 7 segments display

i changed the Cathode 7 SEGMENT with Anode one, it works right now with the change i made on loop.

The way the original code is written, it will try to show zero until the button is pressed the first time. Once the button press is detected counter goes to 99 without printing any digits and then nothing ever sets counter back to anything other than 99 so it should just keep trying to display 99 over and over and over.

Maybe try showing a different number.

Are you sure the displays are common anode?

Show where you can write 98.

Also... check your segment values. Especially this one...

7segchart
7seg

Ask whoever wrote this about changing shownumber() like

void shownumber(int number) {
  PORTD = digitOne[number];
} 

The original sorta missed the point of using an array.

a7

1 Like

Using Pin 1 (PORTD Bxxxxxx1x) might cause issues while running the sketch. Pin 1 is TX.

I think their segment values are set up inverse of what you'd expect. I think it is an attempt to deal with a common anode display. However from the description of the actual output it appears that may not be what they actually have. Or they may have the display miswired. I'm thinking that they actually have a common cathode display and the light is happening when the common pin is LOW and the segment G pin is HIGH which appears to be what digitOne[0] indicates to do.

That makes sense. 0x00 becomes 0xFF without the DP ... making the number 8.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.