mitxela.com forum
Welcome. Please log in or register.

self playing xylophone
DAVID Posted: 28 Aug 2018, 02:56 AM
Avatar
I love mcus

Member
Posts: 237
Joined: 10-September 17
hi i recently made a self playing xylophone based on the arduino mega https://youtu.be/randDlbnDiM and it turn out pretty well, the problem is that it hits a note when there is a note on command and then waits 20ms before turning off the solenoid and for the delay i use a simple delay function which stop the mcu so when i play notes at the same time there is a delay between notes. So can somebody help me

Last edit by DAVID at 28 Aug 2018, 11:16 PM

-------------
[top]
mit Posted: 28 Aug 2018, 09:29 AM
Avatar
yeah whatever

Admin
Posts: 538
Joined: 4-May 16
Hi, that's pretty cool. There are several ways you can solve the waiting problem. One way is to use interrupts for the timing.

Configure an interrupt to run from one of the timers, maybe every 1ms. Have an array of counters for the solenoids, and when you turn one of them on, set its counter to 20. In the interrupt routine loop over the counters and if it's more than 0, decrease it, and if it hits zero turn off that solenoid.

The copper pipes look cool, but if you can find some steel pipes or steel rods it might sound better.

-------------
[top]
DAVID Posted: 29 Aug 2018, 12:32 AM
Avatar
I love mcus

Member
Posts: 237
Joined: 10-September 17
thanks mit, i use timer5 for reading which of the pins are high and then wait 20ms and turn it off
so from this

if (MIDI.read()&&MIDI.getChannel()!=10)
{

if(MIDI.getType()==0x90){
for(int a;a!=numpins;a++){
if(MIDI.getData1()==notes[a]+o||MIDI.getData1()==notes2[a]+o){
digitalWrite(pins[a],1);
delay(20);
digitalWrite(pins[a],0);

}

to this

// interrupt routine
void turnoff(void)
{//this is used to turn off the mosfet after changing the correspond variable "state[0-19]" when the pin is on
for(int a;a!=numpins;a++){
if (state[a]>0&&state[a]<41) {

state[a]++;// increase when LED turns on
}
if(state[a]>40) {
digitalWrite(pins[a], 0);
state[a]=0;
}
}
}

  if (MIDI.read()&&MIDI.getChannel()!=10)                // Is there a MIDI message incoming ?
{

if(MIDI.getType()==0x90){
for(int a;a!=numpins;a++){
if(MIDI.getData1()==notes[a]+o||MIDI.getData1()==notes2[a]+o){
digitalWrite(pins[a],1);
state[a]=1;

}


Last edit by DAVID at 31 Aug 2018, 06:15 AM

-------------
[top]
DAVID Posted: 29 Aug 2018, 12:34 AM
Avatar
I love mcus

Member
Posts: 237
Joined: 10-September 17
only bad thing is that the square wave synth from timer 0 gets a bit choppy by timer 5 but is ok
the synth is working fine
https://github.com/theawsomeavr/self-playing-xylophone
https://youtu.be/P_dYiSwsxfs

Last edit by DAVID at 29 Aug 2018, 03:23 AM

-------------
[top]
alesters1 Posted: 10 Sep 2018, 10:16 PM
Avatar


Member
Posts: 1
Joined: 10-September 18
spam

Last edit by mit at 10 Sep 2018, 10:54 PM

-------------
[top]

Sign in to post a reply.