Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / IRRemote library & tone() on: February 27, 2011, 03:09:23 pm
As described in this thread, there is a bug with the IRRemote library when using the tone() function:

http://arduino.cc/forum/index.php/topic,45265.0.html

Has anyone found a way around this? Are there other sound libraries or IR libraries that I could try?

Thanks.

Ian
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Limited Looping on: November 12, 2008, 12:00:13 am
AlphaBeta, you rock. Thanks for the fast reply.
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: Limited Looping on: November 11, 2008, 11:10:29 pm

Quote

 
/*
* Button
* by DojoDave <http://www.0j0.org>
*
* Turns on and off a light emitting diode(LED) connected to digital  
* pin 13, when pressing a pushbutton attached to pin 7.
*
* http://www.arduino.cc/en/Tutorial/Button
*/
#define MAXIMUM_BEATS 40

int ledInputPin = 13;                // choose the pin for the LED
int ledMimicPin = 12;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for a pushbutton)
int val = 0;                    // variable for reading the pin status
int beatStart[MAXIMUM_BEATS];
int beatDuration[MAXIMUM_BEATS];
int phraseLengthMillis = 1000 * 10;
int phraseTimestamp = -1;
int currentBeat = 0;
int repeatDelay = 1000 * 5;
boolean playback = false;
boolean beatOn = false;
int pauseStart = -1;

void setup() {
  Serial.begin(9600);
  pinMode(ledInputPin, OUTPUT);      // declare LED as output
  pinMode(ledMimicPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare pushbutton as input
  initArray(beatStart, MAXIMUM_BEATS, 0);
  initArray(beatDuration, MAXIMUM_BEATS, 0);
}

int initArray(int a[], int arrayLength, int value) {
  for(int i = 0; i < arrayLength; i++)   {
    a = value;
  }
  return arrayLength;
}

void loop(){
  if (phraseTimestamp < 0)
  {
    phraseTimestamp = millis();
    currentBeat = 0;
  }
  else if (phraseTimestamp + phraseLengthMillis < millis())
  {
    phraseTimestamp = millis();
    Serial.print("New phrase: ");
    Serial.println(phraseTimestamp);
    currentBeat = 0;
  }

  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledInputPin, LOW);  // turn LED OFF
    digitalWrite(ledMimicPin, LOW);  // turn LED ON
    if (beatOn)
    {
      beatDuration[currentBeat] = millis() - beatStart[currentBeat] - phraseTimestamp;
      currentBeat++;
      beatOn = false;
    }
    if (pauseStart <= 0 && !playback)
    {
      pauseStart = millis();
    }
    else if (millis() - pauseStart > repeatDelay && !playback)
    {
      playback = true;
      pauseStart = -1;
    }
  }
  else {
    digitalWrite(ledInputPin, HIGH); // turn LED ON
    digitalWrite(ledMimicPin, HIGH);  // turn LED ON
    if (playback)
    {
      initArray(beatStart, MAXIMUM_BEATS, 0);
      initArray(beatDuration, MAXIMUM_BEATS, 0);
    }

    if (!beatOn)
    {
      beatStart[currentBeat] = millis() - phraseTimestamp;
      beatOn = true;
    }
    playback = false;
    pauseStart = -1;
  }

  if (playback)
  {
    for (int i = 0; i < MAXIMUM_BEATS; i++)
    {
      if (millis() - phraseTimestamp >= beatStart &&
        millis() - phraseTimestamp < beatStart + beatDuration)
        digitalWrite(ledMimicPin, HIGH);  // turn LED ON
      else
        digitalWrite(ledMimicPin, LOW);  // turn LED OFF
    }
  }
}


 
4  Forum 2005-2010 (read only) / Syntax & Programs / Limited Looping on: November 11, 2008, 11:10:16 pm
My program, below, only prints "New Phrase:" three times. As far as I can tell, it should continue printing this line to the serial port every ten seconds, forever. I will post the code in the next message.

Anyone have any ideas what's going wrong?

- Ian
 

Pages: [1]