Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

How do I stop speaker from ticking when tracking time?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

How do I stop speaker from ticking when tracking time?

by Mwangsy on Tue Mar 24, 2020 7:50 pm

I am making a speaker based project that requires a code to track elapsed time. I did this by using millis() and unassigned long time. The program works, but I noticed that the speaker would make ticking noises as if it is a clock when I run the program. Is there a way to stop this through code like turning off the sound or speaker or something? Any suggestions would be helpful!

Mwangsy
 
Posts: 14
Joined: Fri Mar 20, 2020 4:35 am

Re: How do I stop speaker from ticking when tracking time?

by adafruit_support_bill on Tue Mar 24, 2020 8:30 pm

Without knowing anything about your code or your circuit, it would be hard to suggest a remedy.

adafruit_support_bill
 
Posts: 78733
Joined: Sat Feb 07, 2009 10:11 am

Re: How do I stop speaker from ticking when tracking time?

by Mwangsy on Wed Mar 25, 2020 3:20 am

The circuit is just a flora board connected to a speaker and some neopixels, the code is the following (I have left out unnecessarily long irrelevant sections):

unsigned long time;

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>

#include "pitches.h"

int melody[] = {
...
#define PIN 6
#define LED_COUNT 2

Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(9600);
  for (int repeat=0; repeat<3; repeat++){
    for (int thisNote = 0; thisNote < 264; thisNote++) {
 
      int noteDuration = 1000/noteDurations[thisNote];
      tone(8, melody[thisNote],noteDuration);
 
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);
 
      noTone(8);
    }
  }
  strip.begin();
  strip.show();
}

void loop() {
  while(time<=28800000){
    strip.setBrightness(0);
    colorWipe(strip.Color(255, 255, 0), 0); // Yellow
    time=millis();
    delay(1000);
    if(time >= (27000000)&& time <=(28800000))
    {
      strip.setBrightness(255);
      for (int lux = 0; lux < 256; lux++)
      {
          strip.setPixelColor(0, strip.Color(lux,lux,0));
          strip.setPixelColor(1, strip.Color(lux,lux,0));
          strip.show();
          delay(7058.8);
      }
    }
  }
  strip.fill((0,0,0));
}

void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}


I think the sound is due to the lines in the code about time, but I am not sure and I can't seem to fix the problem.
Last edited by adafruit_support_bill on Wed Mar 25, 2020 5:13 am, edited 1 time in total.
Reason: Pleas use [code] tags when posting code to the forums

Mwangsy
 
Posts: 14
Joined: Fri Mar 20, 2020 4:35 am

Re: How do I stop speaker from ticking when tracking time?

by adafruit_support_bill on Wed Mar 25, 2020 5:14 am

The circuit is just a flora board connected to a speaker and some neopixels,

There are many ways of connecting things. Please post some photos showing us how you have everything connected.

adafruit_support_bill
 
Posts: 78733
Joined: Sat Feb 07, 2009 10:11 am

Re: How do I stop speaker from ticking when tracking time?

by Mwangsy on Wed Mar 25, 2020 6:26 am

Annotation 2020-03-25 102326.png
Annotation 2020-03-25 102326.png (497.47 KiB) Viewed 62 times

The above is the circuit

Mwangsy
 
Posts: 14
Joined: Fri Mar 20, 2020 4:35 am

Re: How do I stop speaker from ticking when tracking time?

by adafruit_support_bill on Wed Mar 25, 2020 6:34 am

It is not clear from your photo how the speaker is connected. We need to know which pins on the speaker board are connected to which pins on the Flora.
We also need to know how your Neopixels are connected.

adafruit_support_bill
 
Posts: 78733
Joined: Sat Feb 07, 2009 10:11 am

Re: How do I stop speaker from ticking when tracking time?

by Mwangsy on Wed Mar 25, 2020 9:49 am

So for the speaker: + is connected to VBATT, - is connected to ground and signal is connected to D9.
For the neopixels, + is connected to VBATT, - is connected to ground and the arrow pointing away is connected to D6. (there are two neopixels connected in a line)
Both the speaker and the neopixels are connected by conductive threads.

Mwangsy
 
Posts: 14
Joined: Fri Mar 20, 2020 4:35 am

Re: How do I stop speaker from ticking when tracking time?

by adafruit_support_bill on Wed Mar 25, 2020 10:53 am

Most likely, the speaker is ticking because there is a periodic voltage fluctuation on pin 9. I don't see anything in your code that directly changes pin 9 inside your loop.

It is possible that there is some interference caused by writing to the pixels. You can try commenting that out.

adafruit_support_bill
 
Posts: 78733
Joined: Sat Feb 07, 2009 10:11 am

Re: How do I stop speaker from ticking when tracking time?

by Mwangsy on Wed Mar 25, 2020 12:26 pm

Okay, thanks for the help

Mwangsy
 
Posts: 14
Joined: Fri Mar 20, 2020 4:35 am

Please be positive and constructive with your questions and comments.