Go Down

Topic: (another) arduino sequencer thread. (Read 1 time) previous topic - next topic

awambawamb

Hi guys.

this is my first project - quite a simple one. it's an 8-step sequencer project you can see on http://www.beavisaudio.com/projects/digital/ArduinoPunkConsole/

you can get the code from the link above - but if needed, i can post it here.

I'm using and Arduino Uno. I did the wiring correctly, but unfortunately i have to keep pressing the start/stop button to hear it while i'd like to push it one time to start it and one time to stop it. here's the piece of code i *think* it's related to my problem:

Code: [Select]


// misc housekeeping
int duration = 50;
int pitchval = 1;
int fPlayMode = true;
int lastPushedStep = -1;

// Initialize the tempo
int tempo = 100;

void setup()
{
  // setup pin modes (Digital pins are input by default, but
  // I like to set 'em explicitly just so the code is clear.
  pinMode (DigitalInSwitch0, INPUT);
  pinMode (DigitalInSwitch1, INPUT);
  pinMode (DigitalInSwitch2, INPUT);
  pinMode (DigitalInSwitch3, INPUT);
  pinMode (DigitalInSwitch4, INPUT);
  pinMode (DigitalInSwitch5, INPUT);
  pinMode (DigitalInSwitch6, INPUT);
  pinMode (DigitalInSwitch7, INPUT);               
  pinMode (DigitalInStartStop, INPUT);
  pinMode (DigitalOutSignal, OUTPUT); 
  pinMode (DigitalOutLED, OUTPUT);

void loop()
{
  // Main sequence loop 
  for (int i=0; i<8; i++)
  {   
    // Are we playing or stopping?
    fPlayMode = digitalRead (DigitalInStartStop);
    digitalWrite (DigitalOutLED, HIGH);

    // Check the Hardware
     readSwitches();
     readPots();

    // Make the noise
    if (fPlayMode)
    {
      freqout (steps[i], duration);
    }
    digitalWrite (DigitalOutLED, LOW);

    // Pause between steps
    delay (tempo);       
  }
}




...and that's all for now.
thanks in advance!

Max

PeterH

At the moment you're simply reading whether the button is down to start the replay sequence:
Code: [Select]

fPlayMode = digitalRead (DigitalInStartStop);


What you're trying to do needs you to detect when the button state changes from unpressed to pressed; each time that happens, toggle the state of fPlayMode. To detect button state changes you need to remember the previous state and see whether the current state is different; afterwards, save the current state as the new previous state ready for next time.
I only provide help via the forum - please do not contact me for private consultancy.

awambawamb

at least now I have a trace, but I don't have any clue about how to code it. any help?

PaulS

It looks like you should move the code to read the switch state out of the for loop. Of course, the fact that you aren't detecting edges, as PeterH points out, is also a problem.

Code: [Select]
  // I like to set 'em explicitly just so the code is clear.
  pinMode (DigitalInSwitch0, INPUT);
  pinMode (DigitalInSwitch1, INPUT);
  pinMode (DigitalInSwitch2, INPUT);
  pinMode (DigitalInSwitch3, INPUT);
  pinMode (DigitalInSwitch4, INPUT);
  pinMode (DigitalInSwitch5, INPUT);
  pinMode (DigitalInSwitch6, INPUT);
  pinMode (DigitalInSwitch7, INPUT);           

Actually declaring and valuing, and using, these variables would also be a good idea.

awambawamb

I think that the code is quite old, right? for instance, when i check the code it keeps telling me that "BYTE" is no more used.

Go Up