hexatone horn melody player

Hey, I've a very interesting project of musical air horns, in which we blow 6 horns according to to melody generated from 6 outputs of arduino.
But I,ve a confussion that how can we give commands to arduino to play music through 6 channels.
How can we divide music into this 6 channels so that it produces proper replica of music.
It's is very challenging and fun to do so please help me out how can I do that, thanks.

Screenshot_2015-12-27-12-23-21_1451199227374.jpg

Not too sure what your problem is. Are those air horns electrically controlable? You simply have an array that define what pin you switch on at each step of a tune.
Search for playing a tune with the tone function, it is the same thing.

Note you will also need a driver from the Arduino pins to boost the signal to one that can drive the air horn.

Yeah, driving air horns is not a problem as they are a switched through air compressor valves controlled via MOSFETs connect to arduino pins.
But my problem is how to convert any song and save it into arduino so to play it via 6 outputs.
I've also successfully tried piezo buzzer to playe tune via arduino but that is whole tune playing through one output.
If you have heard of Dixie horns or YouTube it as musical air horns you will get the idea.
Thanks

But my problem is how to convert any song

You can't. You can only convert a song that uses the notes of your air horn.

First work out what notes these are. Then find the position of these on a music stave. Then make a list of what note plays when. In place of the tone values just put the horn number.
So to play a scale it would be horn 0 to 5 in sequence.

byte scale [] = {5, 4, 3, 2, 1, 0};

Associate the horns with pin numbers

byte pins[] = { 4, 5, 6, 10, 12, 13}; or what ever pins you use

Then play them

int horn;
for(int note =0; note <5; note++){
horn = scale[note];
  digitalWrite(pins[horn], HIGH);
delay(300);
  digitalWrite(pins[horn], LOW);
delay(100);
}

mohit-singh:
But my problem is how to convert any song and save it into arduino so to play it via 6 outputs.

Looks like you want to play a six voices polyphonic melody.

Six horns could be represented by six bits within a byte variable.

I'd suggest code like that:

const int QUARTER=250; // quarter note duration
const int HALF=500;
const int FULL=1000;  
const boolean HORNACTIVE=LOW; // for mechanical relays switching on "LOW" signal

const byte hornPins[]={2,3,4,5,6,7};
const byte NUMHORNS=sizeof(hornPins);

struct chord {byte note; int duration;};

const chord melody[]={
 {0b000001, QUARTER}, // one horn, quarter note
 {0b000000, QUARTER}, // no horn, quarter pause
 {0b000011, QUARTER}, // two horns, quarter note
 {0b000000, QUARTER}, // no horn, quarter pause
 {0b000111, QUARTER}, // three horns, quarter note
 {0b000000, QUARTER}, // no horn, quarter pause
 {0b001111, QUARTER}, // four horns, quarter note
 {0b000000, QUARTER}, // no horn, quarter pause
 {0b011111, QUARTER}, // five horns, quarter note
 {0b000000, QUARTER}, // no horn, quarter pause
 {0b111111, QUARTER}, // six horns, quarter note
 {0b000000, FULL}, // no horn, FULL pause
 {0b101010, FULL}, // three horns, FULL note
 {0b000000, QUARTER}, // finally set all horns to OFF
};

const int NUMCHORDS=sizeof(melody)/sizeof(chord);

void playMelody()
{
  for (int i=0;i<NUMCHORDS;i++)
  {
    for (int horn=0;horn<NUMHORNS; horn++)
    {
      boolean state;
      if (bitRead(melody[i].note,horn)) state= HORNACTIVE;
      else state= !HORNACTIVE;
      digitalWrite(hornPins[horn], state);
      Serial.print(bitRead(melody[i].note,horn));
    }
    Serial.print('\t');Serial.println(melody[i].duration);
    delay(melody[i].duration);
  } 
  Serial.println("Ready.\n");
}

void setup() {
  Serial.begin(9600);
  Serial.println("*** CHORD PLAYER ***");
  for (int i=0;i<NUMHORNS;i++)
  {
    digitalWrite(hornPins[i],!HORNACTIVE);
    pinMode(hornPins[i], OUTPUT);
  }
}

void loop() {
  playMelody();  
  delay(5000);
}

The melody to be played must be encoded into an array of such structure:

struct chord {byte note; int duration;};

The "note" is a bit-encoded byte, where the lower 6 bits represent "horn OFF" (0) or "horn ON" (1).
And "duration" is a value in milliseconds, how long the note is to be played.
For easier coding I have defined some durations for QUARTER, HALF and FULL note durations.

The example should play short notes of 250ms duration with 1,2, 3,4,5,6 horns,
a short QUARTER pause after each chord is played,
then a full note duration pause, then a full note duration using three horns as the final chord.
(Just for debugging, I'm no musician.)

The loop code just plays the melody once, creates a 5s pause, then restarts playing the same melody.

Can you understand what my code is doing and how you have to encode the timeline of your six horns in the melody array?

P.S.: Encoding/playing logic could be much simpler if you don't want a 6-polyphonic playing (one or up to six horns playing at the same time), but if monophonic play (1 horn at a time) is enough.

Hmm ,Thanks for the ideas how to build code to play horns, but I,ve old hexatone player board and for curiosity last night I,ve attached its 6 outputs to PLC to see what response I get, but what I got is that plc input lights do not switch on/off sequentially but randomly what I think is they have assign particular note to specific output so when that note come in melody array that specfic output gets on for for note value time.
For e.g if melody array is {e,c,b,a,a,b,f,d,e}
Than ouputs will switch like {4,2,1,0,0,1,5,3,4} but for specfic note time that is {1,1,2,2,2,1,2,2,1}... is that right?
But another thing is how to get notes of music or song that I want to play

For e.g if melody array is {e,c,b,a,a,b,f,d,e}
Than ouputs will switch like {4,2,1,0,0,1,5,3,4} but for specfic note time that is {1,1,2,2,2,1,2,2,1}... is that right?

No idea without looking at the code. Probably no idea with looking at the code as I have never done any PLC stuff.

But another thing is how to get notes of music or song that I want to play

You have asked this before. It is the same as knowing what keys to press on a piano to make a tune. You either do it by ear or read some sheet music.

Ok, I,ll try some stuff and update it if get successfull, right know I'm trying to understand notes and sheet music and how to implement it in arduino.

Thanks

Hello friends please example with mode and pus button select