Go Down

Topic: Stop sound question (Read 1 time) previous topic - next topic


Jan 07, 2013, 04:38 am Last Edit: Jan 07, 2013, 06:39 am by arduinokov Reason: 1

I got this code SO CLOSE to working but I have just one more hump to get over. I have it set up to play a start up sound (that is supposed to take about 3 seconds) and then, when a button is pushed, go on to play a different sound and light up some LEDs.

The button push and the part after it work perfectly.

The start up sound works well except I need it to STOP after about 3 seconds (when it reaches it's peak) until I push the button to trigger the rest of the festivities.  It is working except it doesn't stop UNTIL I push the button (however long I wait). Could anyone help? I believe the void setup() is where the problem is.  :smiley-red:

Code: [Select]
//LED Pin Variables
const int LEDS=5;
int ledPins[LEDS]={2, 3, 4, 5, 6};//An array to hold the pin each LED is connected to
int ledPin=10;//+ battery test lead connected to digital pin 10
int buttonPin=9;
int buttonState = 0; // variable for reading the pushbutton status

void setup(){
// initialize the pushbutton pin as an input:
       pinMode(buttonPin, INPUT);    
      //Set each pin connected to an LED to output mode (pulling high (on) or low (off))
for(int i=0; i<LEDS; i++) pinMode(ledPins[i], OUTPUT);
for(int i=500; i<2000; i+=6){ // adjust startupsound here
tone(SPEAKER_PIN, i);

   while (digitalRead(buttonPin) != HIGH); {
       // read the state of the pushbutton value:
       buttonState = digitalRead(buttonPin);

//value should be between 0 and 255 inclusive
void present(int value){
analogWrite(ledPin, value);
for(int i=0; i<LEDS; ++i)
digitalWrite(ledPins[i], value>(256*i+128)/LEDS?HIGH:LOW);
//tone(SPEAKER_PIN, map(value, 0, 255, 0, 400));
       tone(SPEAKER_PIN, map(value, 0, 290, 0, 990));


stop using delay and use blink without delay example.... the thing is the delay make your programme unable to receive any instruction for simple delay, using the delay make it easy but for most times it could make your program unresponsive


Jan 07, 2013, 05:52 am Last Edit: Jan 07, 2013, 06:44 am by arduinokov Reason: 1
Solved it. noTone(); worked.



We like it when a plan comes together.

No technical PMs.
The last thing you did is where you should start looking.


Thanks for the replies. I will learn to avoid using delays. It seems a much better way to do it.


Go Up