Seven segment display countdown with piezo buzzer makes the display flash

Hello!

I'm building an airsoft prop bomb, and I've gotten so far with it that it's working, but I've got a little annoying feature in it that I don't like.

My seven segment display flashes, everytime piezo buzzer beeps or a button is pressed.

I don't know what's causing it, but I'm using Arduino Uno at the moment, and I've tried using it through different pins, and I'm going to change this to Arduino Mega2560 later, but I would like to get it working before that. It seems to be somehow related to piezo buzzer and buttons, as when the countdown on the display goes down without the buzzer, it doesn't flash, and even when it's stopped and I use beeper through button, or set it to beep on its own, it stll flashes.

Does anyone know how to get it so that it doesn't make the display flash?

Here's my prototype so far: http://www.youtube.com/watch?v=M8Ijk0JxXDI and you can see from that what I mean. Without buzzer it just changes the last number without flashing.

Thanks!

If you are using any delay() calls in the buzzer code, it would interrupt the multiplexing of the LEDs. If you're using multiplexing, that is. You didn't supply any code or schematics so that's just a guess.

Hard to say without code listing. Probable suspect is loss of display updates during other actions (which likely have delay() used).

TanHadron: If you are using any delay() calls in the buzzer code, it would interrupt the multiplexing of the LEDs. If you're using multiplexing, that is. You didn't supply any code or schematics so that's just a guess.

That's actually a pretty good guess TanHadron, thank you very much, that solved the problem of where it's coming from.

Now I'm having a tough time figuring out how to get the beep or buttons work properly, as my beep is working with this

void beep(unsigned char delayms){
  analogWrite(A5, 150);      // turn it on, pin and value
                           
  delay(delayms);          // wait for a delayms ms
  analogWrite(A5, 0);       // off
  delay(delayms);          // wait for a delayms ms
}

and in loop the main part is

if(start == 1){ // if start button is pressed
  if (millis() - timer >= 1000){ // if one second has passed
    timer = millis();
    minutes--; //what shows on the screen
    i++;  // related to seconds displaying correctly
    beep(50); //beep
      if(button5 == HIGH){ // if defuse button is pressed
    defuseTimer++; // add 1 to defuse timer
      }
}

On everyother button except button5, I use delay, because if I don't, the buttons will just do their work 3-4 times in one press. Any idea how to get beep or buttons to work without delay()?

Use the blink without delay style of code you have here

if (millis() - timer >= 1000){ // if one second has passed timer = millis();

for the buttons. When you detect a button is pressed, grab the time, then don't read the button again until some time has passed. Effect is the same, but you are not sitting in delay() somewhere waiting for the time to lapse.

All right!

Now I understand delay() better, it must have in this case gotten my countdown to fall behind, and now I got it to work properly. Thank you so much!

That's a pretty spiffy looking device. Right out of the movies.

Make sure, when you're defusing it, that you clip the RED wire and not the BLUE one. :)

Thanks TanHadron! :)

I got the buttons to work correctly, but now I'm having trouble with the beep. I tried using blink without delay style on it, but it keeps beeping non-stop.

I've tested out plenty of different kinds of styles to get it work, but can't do it, and can't figure out why this doesn't work:

void beep(unsigned char delayms){

     analogWrite(A5, 150);  // turn it on, pin and value   
     newMillis = millis();
     if(millis() - newMillis >= delayms){
       analogWrite(A5, 0); // off
     }   
}

I'm calling beep(50);, so I assumed this would set the sound on, and after that amount of time it would turn it of, but, in this case it seems to end running beep, before the if -gets to turn the sound off. So, any ideas?

Yeah. I don't have all your code, so I can only guess again, but I expect that the code to turn off the beeper is in the beep() function and not the main loop() function.

     if(millis() - newMillis >= delayms){
       analogWrite(A5, 0); // off
     }

That code in the beep() function never gets executed because newMillis gets set right before it. You should move it somewhere in the loop() function, and maybe create some sort of state variable so the main function knows that the beeper is beeping, and newMillis is valid and should be checked.