That said, it looks like pin 32 is free, so you could set that as a digital output, and then find the bit of the code that deals with the sequencer, probably somewhere near here, and adjust it to toggle pin 32. You’d have to take some care on whether you wanted triggers or gates, but it should be doable.
From a bit of googling, I think a way to do what you suggest is to create a variable which is the original tempo in milliseconds, then use that to delay a toggle?
Yeah, I’m not sure the schematic matches the code - in the schematic both 37 and 32 look unconnected, but now I’m looking a little more closely at the code it looks like they’re both used. Maybe you could use pin 13, I think that’s connected to the onboard LED, but it shouldn’t get in the way of anything and would blink in time.
Maybe something like this in the code would do the trick, inside the if that checks if playstate is true.
int clock = tempo / 2.0;
int clock_timer = 1;
int clock_val = 0;
if (millis() - clock > clock_timer) {
clock_val = clock_val ^ 1;
digitalWrite(whateverpin, clock_val);
clock_timer = millis();
}
We’re dividing the tempo by 2, so it goes twice as fast - then we’re toggling it with an XOR.
Thanks, that’s really helpful. I have very little coding experience, so I’m not entirely sure I can follow what your code is doing… but I will start buying parts and give it a go!
Looking over the code and schematic, I think they’ve missed the play/pause button and the play/pause indicator LED from both the schematic and stripboard. Which accounts for 32 and 37.
When I get to building it, I’ll double check all the pins line up between the code and everything else, but either way I think there’s enough to go on to figure it out.
I don’t think it’s a good idea to include any delays into the main loop, especially on a drum machine for timing, you are just asking for problems
Better to initialize a counter at the same time you set the output high and then increment the counter in the loop until it reaches a set number of ms then set the output low
I agree 32 & 37 are in use for play LED and PLAY/PAUSE
Whats wrong with using pins 0 or 1, they are normally used for MIDI or serial 1 but they don’t seem to be in use at all on this design.
He’s also wasted a ton of pins for buttons and pots etc, I would add a couple of 74HC165 shift registers and read in upto 16 buttons/switches with 3 pins instead of 16.
Doesn’t surprise me about the schematics and code, I built his poly6 design from GitHub, it left a lot to be desired in terms of schematics and code. I’m no expert but I produce something slightly better.
Just for clarity, it sounds like you’re saying don’t do my initial idea but jaradical’s code should work? Or were you suggesting a different approach entirely?
With regards to freeing up pins on the teensy, is the benefit of that being able to implement more features if I wanted, or is there a performance benefit to using fewer pins?
I didn’t like your code with delays in, never a good idea in a loop.
I’ve not studied Jaradicals code, maybe it will work.
I have just implemented a clock LED and output from an incoming midi clock and basically I turn the light on when I see a clock message and then count in millisec and when its greater than 40ms I turn it off again. Of course I count 24 clock cycles each time to cope with the 24PPQN before each light on event.
As for freeing up pins, of course you dont need to in this design as 0, 1 and 13 are available, but if you needed more options in the future then a shift register can give you lots and lots of inputs or outputs depending on what type are used with 3 wires per inputs or outputs. I use the RoxMux library to support inputs and outputs.
I would also like to mention that his schematic is very poor, he puts VCC on some switches, but no mention of VCC as a source and on a Teensy 4.1 VCC would be the 3.3V pin, not 5V. Als the pots pins 1 & 3 are just floating in mid air and are 100K in value, obviously they connect between 0v and VCC 3.3V which he does note at the top of the diagram, but its not super clear and the value should really be 10K lin for a Teensy, not super important, but recommended. He then says except the tempo knob, well how does the tempo knob connect, I presume he means that there are some resistors possibly from the legs to VCC and ground but he doesn’t show them or state values.
Also, not 100% sure about this, but some of the pots don’t match their numbers in the schematics
A9 and A10 seem reversed, A9 is HH tone and A10 is reverb.
A15 is shown as delay time, but is coded as Swing and no mention of swing.
It’s almost exactly what I was looking for in terms of a drum machine to go alongside my modular.
I’ll have a think whether it’s worth what sounds like quite a lot of working out or if I look elsewhere.
The released version of this, the crum drum, looks great but it a bit too much money for me at the minute. There’s also a few complaints about power supply noise which has put me off a little…