Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Exiting switch case or if statement on: July 27, 2009, 04:20:31 pm
Hello - just want to thank the both of you for your help, and also to confirm that I did get it working as desired - after several readings, I also now understand what is going on!

Just for the record, this didn't work in in switching the boolean:
trigger != trigger;

But this did: trigger = !trigger;

Thanks again!

2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Exiting switch case or if statement on: July 25, 2009, 06:18:42 pm
Thank you Andy and Roy -
 
Andy - I will update my arduino code tomorrow and post back whether or not the default setting fixes things - I have to admit that I am not sure I understand what you are doing with the boolean bit - though yes, trigger should indeed be a two state value.

Roy - thanks for looking - I am calling the method with another method which alternates button states, onpauseswitch(), which is being run in the main loop:

void onpauseSwitch()
{
 int val;
 int val2;
 val = digitalRead(playpin);      // read input value and store it in val
  delay(0);                         // 10 milliseconds is a good amount of time
  val2 = digitalRead(playpin);     // read the input again to check for bounces
  if (val == val2) {                 // make sure we got 2 consistant readings!
    if (val != buttonState) {          // the button state has changed!
      if (val == LOW) {                // check if the button is pressed
        if (playpauseswitch == 0) {          // if its off
          playpauseswitch = 1;           // turn lights on!
        
        } else {
          if (playpauseswitch == 1) {        // if its all-on
            playpauseswitch = 0;             // make it blink!
        
           }
    
        }
      }
    }
  }
  buttonState = val;                 // save the new state in our variable
}

3  Forum 2005-2010 (read only) / Syntax & Programs / Exiting switch case or if statement on: July 25, 2009, 02:24:38 pm
Hello.

I am using a switch case to trigger a file on my waveshield - the problem I am having is that as far as I can tell, it keeps running the case, sending a constant stream of ones, which has the effect of stuttering it.

What happens is that when I go into the 'off' switch case, it actually run the sample completely, because it stops sending the 'on' trigger constantly.

What I am asking is this: is there any way to make a switch case execute only once, then stop executing? Here is my switch case - it:

int playtrigger2() {
   int trig;
   switch(playpauseswitch) { // all-off
   case 0: trig = 1; Serial.println("play"); break;
   case 1: trig = 0; Serial.println("stop"); break;
   }
  return trig;
  
}


Cheers, Jeremy
4  Forum 2005-2010 (read only) / Syntax & Programs / Order of execution in my Waveshield code. on: April 16, 2009, 04:44:52 pm
Hello. I successfully merged my Arduino waveshield sketch, which plays back different files according to which number is sent to the serial port, with some sample code from the Waveshield's sit which allows for pitch control.

 I've got it so that I can control the pitch from a potentiometer, but it only changes the pitch at the beginning of each triggered sound - I have monitored the analogRead to see that I am getting continuous readings - but I am not able to get continuous control of the pitch.

I have a feeling I have just not put the code in the right place - i'm hoping someone with more experienced eyes can see where I might have gone wrong. I commented out bits that were interfering with the normal function of the sketch, but kept them there in case they are necessary. Code follows, thank you for looking!

#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"


AF_Wave card;
File f;
Wavefile wave;
#define redled 9
void setup() {

 

 
  // set up serial port
  Serial.begin(9600);
  
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(redled, OUTPUT);




  // open memory card
  if (!card.init_card()) {
    putstring_nl("Card init failed!"); return;
  }
  if (!card.open_partition()) {
    putstring_nl("No partition!"); return;
  }
  if (!card.open_filesys()) {
    putstring_nl("Couldn't open filesys"); return;
  }
  if (!card.open_rootdir()) {
    putstring_nl("Couldn't open dir"); return;
  }
}

void loop() {
 Serial.println(analogRead(5), DEC);
 char c = 0;
 if(Serial.available()) {
   c = Serial.read();
 int16_t potval;
 uint32_t newsamplerate;
 int16_t lastpotval = 0;
 #define HYSTERESIS 3
 //Serial.println(c, BYTE);
  switch (c) {
   case '1':
     playfile("1.WAV");
     break;
   case '2':
     playfile("2.WAV");
     break;
   case '3':
     playfile("3.WAV");
     break;
   case '4':
     playfile("4.WAV");
     break;
   case '5':
     playfile("5.WAV");
     break;
   case '6':
     playfile("6.WAV");
     break;
   case '7':
     playfile("7.WAV");
     break;
   case '8':
     playfile("8.WAV");
     break;
   default:
   Serial.println("dogs and cats");
  
  }
 }
}


void playfile(char *name) {
  Serial.print("bang");
 int16_t potval;
 uint32_t newsamplerate;
 int16_t lastpotval = 0;
 #define HYSTERESIS 3

 
  // stop any file already playing
  if (wave.isplaying) {  
    wave.stop();
  }
  // close file if open
  card.close_file(f);
  // play specified file
  
  f = card.open_file(name);
  if (f && wave.create(f)) {
  wave.play();
     // while (wave.isplaying) {
     potval = analogRead(5);
     //if ( ((potval - lastpotval) > HYSTERESIS) || ((lastpotval - potval) > HYSTERESIS)) {
         putstring("pot = "); Serial.println(potval, DEC);
         putstring("tickspersam = "); Serial.print(wave.dwSamplesPerSec, DEC); putstring(" -> ");
         newsamplerate = wave.dwSamplesPerSec;
         newsamplerate *= potval;
        newsamplerate /= 512;   // we want to 'split' between sped up and slowed down.
        if (newsamplerate > 24000) {
          newsamplerate = 24000;  
        }
        wave.setSampleRate(newsamplerate);
        
        Serial.println(newsamplerate, DEC);
        lastpotval = potval;
     //}
     //delay(100);
   //}

  
}
}
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Trouble with my switch case on: April 12, 2009, 06:28:44 pm
Success! I switched the data type to char for the switch input. Thank you for mentioning that, I hadn't thought of it. I also replaced my switch structure with yours - am I correct that the '1' specifies is as an ascii equivalent? Also, I replaced my if(Serial.available) with a when(Serial.available). Also seems to be working well! Thank you both for your help.

Best Regards, Jeremy
6  Forum 2005-2010 (read only) / Syntax & Programs / Trouble with my switch case on: April 12, 2009, 04:32:13 pm
Hello. I have been having some problems using the Arduino Waveshield, and I've reduced them to something wrong with my switch case statement - I want it to play different sounds when I feed it numbers via the serial monitor in the IDE, but it's not even getting to the switch case - I know this because I included a default, which constantly spits out the line "dogs and cats", and doesn't stop when I send one of the number keys into the serial port.

I am aware I am probably doing something really simple worng - precisely what that thing might be is what I hope to ascertain with this post smiley

Here is my code:

#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"


AF_Wave card;
File f;
Wavefile wave;
#define redled 9
void setup() {

 
  // set up serial port
  Serial.begin(9600);
  
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(redled, OUTPUT);




  // open memory card
  if (!card.init_card()) {
    putstring_nl("Card init failed!"); return;
  }
  if (!card.open_partition()) {
    putstring_nl("No partition!"); return;
  }
  if (!card.open_filesys()) {
    putstring_nl("Couldn't open filesys"); return;
  }
  if (!card.open_rootdir()) {
    putstring_nl("Couldn't open dir"); return;
  }
}

void loop() {
int c = 0;
 if (Serial.available()) {
     c = Serial.read();
 //Serial.println(c, BYTE);
 }
 
   switch (c) {
    case 1:
      playfile("1.WAV")
      break;
    case 2:
      playfile("2.WAV");
      break;
    case 3:
      playfile("3.WAV");
      break;
    case 4:
      playfile("4.WAV");
      break;
    case 5:
      playfile("5.WAV");
      break;
    case 6:
      playfile("6.WAV");
    default:
    Serial.println("dogs and cats");
   }
  }

 

void playfile(char *name) {
  Serial.print("bang");
  // stop any file already playing
  if (wave.isplaying) {
    wave.stop();
    card.close_file(f);
  }
  // close file if open
  
  // play specified file
  f = card.open_file(name);
  if (f && wave.create(f)) {
    wave.play();
  }
}
7  Forum 2005-2010 (read only) / Interfacing / Re: Using MaxMSP to control servos on: February 05, 2007, 11:52:31 am
Thank for your reply Daniel, that's what I needed to know. It will take me a bit to get my head around SimpleMessage System, but it's good to know it can be done!
8  Forum 2005-2010 (read only) / Interfacing / Using MaxMSP to control servos on: February 03, 2007, 07:36:51 am
I am starting to plan a project that will use amongst other things, two servos. I have not purchased a contoller board yet. I am most attracted to Arduino, due to the community as well it's value and flexibility.
  My question is this: How possible is it at the current stage of development to use MaxMSP to control the Arduino's outputs to drive servos and other motors? Has anyone had any success with this? I notice the Arduino2Max patch has no stated output control- will this change at any point?
 
Let me know if anyone has any feedback or suggestions!


Best, Jeremy
9  Forum 2005-2010 (read only) / Interfacing / Re: interfacing pre-built electret mic w/ preamp on: February 13, 2010, 05:10:46 am
Excellent. Thank you again for all your help!

Best, Jeremy
10  Forum 2005-2010 (read only) / Interfacing / Re: interfacing pre-built electret mic w/ preamp on: February 12, 2010, 03:17:09 pm
Thanks again Richard, I'm glad I asked!

This is making more sense to me now I think. The NYU page circuite would then amount to a have wave rectifier, with the filter providing the averaging...

If that's correct I think I have enough to go on..
11  Forum 2005-2010 (read only) / Interfacing / Re: interfacing pre-built electret mic w/ preamp on: February 12, 2010, 12:18:52 pm
Thank you Richard.

The audio signal will be sent to a speaker which will be in a feedback loop with the microphone - the point of detecting the volume of the audio signal is so the speaker is turned down when it starts to feed back.

I am thinking that the peak detector circuit may be the best best for this, yes?

Also, I found this: http://itp.nyu.edu/physcomp/sensors/Reports/CondenserMicrophones

Might the rectifier/lowpass part of this circuit (minus the amplification bits) work in conjunction with the pre built bit of the circuit, or is this circuit too basic to do all the DC scaling and the like?
12  Forum 2005-2010 (read only) / Interfacing / Re: interfacing pre-built electret mic w/ preamp on: February 12, 2010, 06:52:53 am
Thank you both for getting back to me.

Lefty - I will be using an amp/speaker combination on the other end, so that should be covered. Forgot to mention that bit. smiley

Richard - This is exactly what I meant, I want to send the audio signal to the amp/speakers, while simultaneously sampling its amplitude level with the Arduino.

Any advice or tips on the rectifier filter set up would be appreciated - think I get rectification (converts an ac signal into a DC signal), but the specifics of how to do it (in addition to the filtering) are hazy to me  in the practical realm.

As far as further power conditioning goes, I will cross that bridge when I come to it - for now I was more worried about proper safety as it will be mains powered!

Thanks again, Jeremy



13  Forum 2005-2010 (read only) / Interfacing / interfacing pre-built electret mic w/ preamp on: February 10, 2010, 01:02:34 pm
Hello everyone.

I just purchased this: http://www.quasarelectronics.com/cpm003.htm -

It is an electret mic/preamp combo. I have 2 questions about interfacing it.

Firstly, the documentation states that it wants "mains filtered 12v DC, fused" to operate.

If I plug the Arduino into the mains using a 12v adapter, then use the Vin pin of the Arduino to the + of the modules power input, and then the  - of the modules power input to Arduino ground, will that do the trick?

Secondly, I will be hooking up the output of this unit to speakers, which is straightforward; however, I would also like to use the output level to use as a sensor to an Arduino ADC pin.

WHat might I have to do to convert this to a usable signal to plug into an Arduino pin?

Best, Jeremy
14  Forum 2005-2010 (read only) / Interfacing / Re: wiring multiple maxbotix sensors on: May 15, 2009, 06:32:21 pm
Thank you very much - so just to clarify, the BW needs to connect to 5V on the arduino, in addition to the "+5" pin?
15  Forum 2005-2010 (read only) / Interfacing / Re: wiring multiple maxbotix sensors on: May 15, 2009, 02:50:06 pm
Thank you for responding - It is the EZ1 I am using. Basically I am asking what I need to do on the Arduino side - for instance, what do I do to "pulse" them? Does that just mean switching between high and low on a digital output? Sorry to be so basic, I am quite new to this!

So Mem, are you saying that if I am using the analog output, I don't need to worry about the BW pin?
Pages: [1] 2