Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Setting a fixed on/high-time for digital output on: February 26, 2009, 12:26:09 pm
Thanks very much chaps (gosh Ed -- you've made my head spin! Will take a while for that to sink in, thanks).

It's not pretty, but everything seems to work nicely with multiple notes without slowing or queuing (had to switch the status LED to use millis too -- forgot about that). Also moved things along pins-wise, to get a full octave (+ high note) of pins, so 13 output pins plus an LED pin. Will have to tidy further though.
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Setting a fixed on/high-time for digital output on: February 26, 2009, 10:59:06 am
Okay, I'm trying to expand this to address 13 outputs, and for that I need to do something similar to dynamically renaming a variable to update millis timings for different pics.

I've probably described that horrendously, so perhaps looking at my mishmash of code will help:

Code:
void playNote(byte note, byte velocity) {
  int value = LOW;
  if (velocity > 10) {
    value = HIGH;
  }else{
    value = LOW;
  }
  if (note >= 36 && note < 44) {
    byte myPin = note - 34; // work out which pin to send note to
    digitalWrite(myPin, value);
    previousMillisX = millis(); // reset the note-on time for this solenoid pin
  }
}

It's the 'previousMillisX' part at the end I'd love some help with -- is there any way I can rename 'previousMillis' dynamically to append the pin number denoted by 'myPin' (in place of the X -- used here just to show where the number would go), so that the millis time can be stored for the correct pin as listed at the top?

I'm fairly certain there'll be a better way to achieve this than what I'm attempting, but I'm too green to be able to figure out how. Perhaps I should set up an array for the previousMillis values?
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: Setting a fixed on/high-time for digital output on: February 26, 2009, 05:44:10 am
Brilliant -- got it working, I think! Thanks again. smiley
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Setting a fixed on/high-time for digital output on: February 25, 2009, 08:09:41 am
Thanks Cross -- I shall persevere with millis() and try and get something going. As I'm using 12 solenoids, I'll have to address each solenoid's timing separately to have the correct on-time, which might bulk up the coding a bit. Yep -- currently driving the solenoids via a transistor and a 12v wall wart. Shouldn't have more than 3 or 4 solenoids running concurrently anyway. smiley
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Setting a fixed on/high-time for digital output on: February 24, 2009, 06:33:35 am
Thanks Cross -- yep, you've got it. I'll have another look, but I'm not very proficient with coding, and millis() seems a bit more complex than just using delay. It'd be nice to be able to do this in software, as otherwise I'll need a monostable for every solenoid I intend to drive (in this case a chromatic octave, 12 solenoids -- all the spare digi pins I think).
6  Forum 2005-2010 (read only) / Syntax & Programs / Setting a fixed on/high-time for digital output on: February 23, 2009, 12:56:55 pm
Hi folks,

Apologies for the probable n00bishness of this question, but is it possible to code a monostable for a digital output, i.e. output goes low after x amount of time, regardless of whether the output control's still on/high or not?

I've used a simple delay to turn a solenoid off after 10ms, after being activated by a MIDI-in key, so even if the key is held it still goes off after 10ms, but of course this also stops the program for 10ms, throwing the timing off if there are multiple key presses.

I've looked at millis() to see if I can use that to set an off time to 10s, but I haven't been able to get it to work due to a severe case of n00bism. I've based the MIDI stuff on Kuki's excellent code, btw.

If it's not possible to code something without monkeying with the timing, perhaps it's possible to read an analog input from a pot, set to control this gate time at all?

Any help would be magnificent, thanks.
7  Forum 2005-2010 (read only) / Interfacing / Re: works: MIDI-IN: code + schematics on: January 26, 2010, 02:15:33 pm
Hey guys,

I've managed to get a small instrument working using this code, but I've also encountered the same problem as Captain Credible (reply #41 on page 3), in that through some MIDI interfaces I can't play more than one note.

If I connect the instrument directly to my MIDI keyboard, I can play polyphonically, but if I play through my keyboard into MIDI-OX and out through a separate MIDI interface (a MOTU MIDI Express XT) I can only play monophonically.

Does anyone have an idea as to why this might be happening?

At first I thought it was because of the note-off differences, between actually specifying a note-off message (128) and a note-on with velocity = 0, but as far as I can tell they both do the note-on, vel=0 thing.

I've been racking my brain all day over this, but I'm truly stumped. Any help would be very gratefully received.

MIDI portion of code below:

Code:
 if (Serial.available() > 0) {
    blink();
    incomingByte = Serial.read();
    if (incomingByte == 144) {
      action = 1;
    }else if (incomingByte == 128) {
      action = 0;
    }else if ((action == 0) && (note == 0)) {
      note = incomingByte;
      playNote(note, 0);
      note = 0;
      velocity = 0;
      action = 2;
    }else if ((action == 1) && (note == 0)) {
      note = incomingByte;
    }else if ((action == 1) && (note != 0)) {
      velocity = incomingByte;
      playNote(note, velocity);
      note = 0;
      velocity = 0;
      action = 0;
    }else{
    }
  }
8  Forum 2005-2010 (read only) / Interfacing / Re: works: MIDI-IN: code + schematics on: February 22, 2009, 12:03:31 pm
Firstly, I'm trying to put together my own MIDI instrument, and found this code indispensable -- thanks Kuk!

But, as a programming n00b, I don't really understand the why 'action' is necessary -- would anyone mind explaining that to me, please. smiley

Also, just to check -- in the initial code, the blink subroutine (was that the correct term?) isn't used is it?

Again, thanks for the very helpful code.
9  Forum 2005-2010 (read only) / Interfacing / Re: Recommended source for solenoids in the UK on: February 21, 2009, 09:04:57 am
Thanks very much for the reply!

Yep, I twigged when I saw Grumpy Mike's MIDI glockenspiel -- he'd put a screw-ring around the end of the plunger to stop it falling out when not active, and also had some foam to stop it clicking when it fell back.

I might try and get some of those tiny grommets to dampen the active click as well as the falling due to gravity when it rests. Think I saw some at B&Q...
10  Forum 2005-2010 (read only) / Interfacing / Recommended source for solenoids in the UK on: February 20, 2009, 06:19:48 pm
Hi folks,

As a total newbie, I'm just trying to put together a little percussion instrument, using 12v 'push' solenoids, but so far I've got a couple of the cheaper ones from Farnell and I'm not sure if they travel far enough when energised to be of use. Can anyone share advice on where to buy decent solenoids, please? I like the look of those Black Knight ones by PED, but they're also quite pricey, and possibly a little more powerful than necessary.

Also, I may as well get a stupid question out the way too. I got these solenoids as they were labelled as 'push', but I was under impression that the thick end of the rod was the 'front' of the solenoid, rather than the thin end. Unless I've been sold the wrong components, it would appear the thin end is actually the front (which shoots/pushes outwards when energised) -- is this correct? In which case the plunger will fall out if the solenoid's pointed upwards, which is less than optimal.
11  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Quick Q about discrete transistor vs. arrays on: March 01, 2009, 09:37:21 am
Thanks Ed -- it's just be for 12ms bursts, so I'm hoping I should be okay with a relatively lightweight array. smiley Not enough time for much of a heat build-up. Shall pore over some datasheets!
12  Forum 2005-2010 (read only) / Frequently-Asked Questions / Quick Q about discrete transistor vs. arrays on: February 27, 2009, 07:16:01 am
Hi folks,

I'm currently using a small TIP102 Darlington transistor for my needs, but will need to scale this up 13x, so I thought I'd probably be better of with a couple of 8-way Darlington arrays instead. Please can you advise me on whether this is correct:

I'm using this chip (probably overkill for my needs, current-wise, not to mention expensive) -- could I substitute this array for a bunch of TIP102? Using them to switch 12v solenoids on.
Pages: [1]