Show Posts
Pages: 1 ... 4 5 [6] 7
76  Community / Exhibition / Gallery / Prototype of Laserharp on: May 23, 2012, 03:23:12 am
Howdie guys and girls,

With the help of the arduino community, I have been able to accomplish our school project of the laserharp.
The construction is not the most beatiful, but with the lack of materials this is the result!

What you can do with it:
* Play 5 different tones
* Change between 2 channels (instruments) with buttons.
* Change the sound tone with a potentiometer



Next project is to build an other midi instrument, a midi fighter. And the third project will be to build a quadcopter, that will have an autopilot function.

Just wait 10 years and Ill be done with the midi fighter, stay tuned!

Cheers!

Edit:
I thought I could upload the code of the laserharp 2 smiley
Ive tried to shorten it down as much as possible with arrays and for loops.

Code:
#define AntalLDR 5
#define AntalInstr 2

int ValdKanal = 144;
int PitchBend = 5;

int AnalogArray[AntalLDR]  =  {0,1,2,3,4};              
int PotVal[AntalLDR]       =  {0,0,0,0,0};                
int State[AntalLDR]        =  {LOW, LOW, LOW, LOW, LOW};
int DigState[AntalLDR]     =  {LOW, LOW, LOW ,LOW, LOW};
int Noter[AntalLDR]        =  {63,62,60,59,58};

int InstrVal[AntalInstr]   =  {8,9};
int Kanal[AntalInstr]      =  {144, 145};
int InstrState[AntalInstr] =  {LOW, LOW};
int ledPin[AntalInstr]   =  {10, 11};


void setup() {
  Serial.begin(57600);
  pinMode(ledPin[0], OUTPUT);
  pinMode(ledPin[1], OUTPUT);
}

void loop() {
  //Väljer instrument/kanal
  for(int i = 0; i < AntalInstr; i++){           // En for-loop för att skanna igenom samtliga knappar (Varje knapp = Instrument val)
    
    int buttonState = digitalRead(InstrVal[i]);  // Värdet på själva knappen registreras i en variabel
    
   if(InstrState[i] != buttonState){             // Om värdet på knappen är förändrat från det förra tillstånde, då går den in i nästa IF state
     if(buttonState == HIGH){                    // Om värdet är HÖGT, går den i IF funktionen
     digitalWrite(ledPin[0], LOW);               // Släcker lampa 1
     digitalWrite(ledPin[1], LOW);               // Släcker lampa 2
     digitalWrite(ledPin[i], HIGH);              //  Den knappen som blev intryckt, tänds motsvarande lampa på
     ValdKanal = Kanal[i];                       // Eftersom att varje knapp har en bestämd kanal, så lägger vi in den kanalen i ValkdKanal
     }
     InstrState[i] = !InstrState[i];            // Eftersom att tillståndet förändrats, så måste vi lägga till det nuvarande tillståndet.
   }    
  
  }
  
  
  //Spelar upp toner
  for(int i= 0; i < AntalLDR; i++){          // Går in i en for-loop för att kolla igenom samtliga sensorer
     PotVal[i] = analogRead(AnalogArray[i]); // Lägger in värdet på LDRn i PotVal
     if(PotVal[i]  >  500){                  // Överstiger värdet på PotVal 700, då betyder det att laser strålen fortfarande är på
       DigState[i] = LOW;                    // Eftersom att strålen inte är blockerad (över 700), så lägger vi LDR tillståndet som LÅG
     }
     else {
       DigState[i] = HIGH;                  // Om värdet är lägre än 700, så lägger vi LDR tillståndet som HÖG
     }
     if(DigState[i] != State[i]){           // Nu kollar vi ifall det är någon skillnad från förra tillståndet på den specifika LDRn, om det finns skillnad gå till nästa IF
       if(DigState[i] == HIGH)              // Är värdet HÖGT, alltså att lasern blivit blockerad, går vi in i funktionen. Annars går vi till else-satsen
       {
         int value = analogRead(PitchBend)/8; // Här registrerar vi värdet på potentiometern (Pitch Bend) i en variabel
         noteOn(0xE1, value, value);          // Pitch värdet läggs in i kanal 1
         noteOn(0xE0, value, value);          // Pitch värdet läggs in i kanal 2
         Serial.println(PotVal[i]);
         noteOn(ValdKanal, Noter[i], 0x7F);   // Här skickas dessa värdena in i en funktion som skickar iväg dessa värden till datorn
                                              // ValdKanal = Den bestämda kanalen, Noter[i] = Den specifika tonen för varje LDR, 0x7F = Högsta volym
       }                              
      else{                                  
        delay(200);                          // Vi väntar en viss tid
        noteOn(ValdKanal, Noter[i], 0x00);   // Här stänger vi av ljudet
       }
       State[i] = !State[i];                 //Nu ändrar vi tillståndet till det nuvarande.
     }
    
  }
  

}
 
 void noteOn(int cmd, int pitch, int velocity) {
   Serial.write(cmd);
   Serial.write(pitch);
   Serial.write(velocity);
 }
 
77  Using Arduino / Programming Questions / Re: Want to use two push buttons to bank up/bank down through states. Difficult? on: May 04, 2012, 11:39:29 am
Have you tried to make ur own script, or do you want us to make one for you?

However, do you want it to loop through the 4 states over and over again?
And from
-P1 high, P2 high
to
-P2 high
Does the P1 go low?
78  Using Arduino / Programming Questions / Re: Help me correct this please on: May 03, 2012, 03:27:34 pm
bump
79  Using Arduino / Project Guidance / Re: Light triggered audio project on: May 02, 2012, 03:16:03 pm
Ive found out that the most efficient way of producing sounds from the computer itself is to setup a MIDI interaction beneath the computer and the arduino.

Here is a link, that will tell you how you can easily use your USB cable to send USB messages (dunno what to call it) and convert it to MIDI messages.
http://spikenzielabs.com/SpikenzieLabs/Serial_MIDI.html
80  Using Arduino / Programming Questions / Re: Help me correct this please on: May 02, 2012, 01:18:00 pm
Oh Im sry, I had 2 in the code but changed em manually in the thread hehe just forgot that one.
However, it does compile and it worked once or twice, but dunno what happened after smiley-razz

The switch buttons works good.

81  Using Arduino / Programming Questions / Help me correct this please on: May 02, 2012, 01:08:21 pm
Hello dear members,

Could some1 see whats wrong with my code?
It worked but at a suddenly it stopped working.

This works with only 2 choices, when I make it 3 it is stuck at the third choice (146).

Global:
Code:
#define AntalInstr 3

int InstrVal[AntalInstr] =  {8,9,10};
int Kanal[AntalInstr]    =  {144, 145,146};
int InstrState[AntalInstr] =  {LOW, LOW, LOW};

Void loop:
Code:

  for(int i = 0; i < AntalInstr; i++){  
    int buttonState = digitalRead(InstrVal[i]);
  
   if(InstrState[i] != buttonState){
     if(buttonState == HIGH){
     ValdKanal = Kanal[i];
     }
     InstrState[i] = !InstrState[i];
   }      
  }
82  Using Arduino / Project Guidance / Re: Several instruments [MIDI] on: April 29, 2012, 05:06:46 pm
Thank you.

Now Ive been able to read some more about this on the net.

So what Im supposed to do is to send a MMC message, and the message looks like this:
F0 7F deviceID 06 command F7

The question is, what deviceID? Is it from the software I use on the computer?
And, how do I send these? Should I make a new function which sends all these hex values one by one?

Cheers
83  Using Arduino / Project Guidance / Re: Several instruments [MIDI] on: April 29, 2012, 01:18:03 pm
Thank you Grumpy Mike, I am now able to play several instruments, and also make some pitch bending and some other functions. With other words, you have made it much more clear for me how stuffs really work!

Right now, Im up with my last shot and after this Ive successfully collected everything I need.
What command do you send to make a record, and to play the recorded notes?

Do you have any link where it clearly says how to do this?

Cheers!
84  Using Arduino / Project Guidance / Re: Several instruments [MIDI] on: April 28, 2012, 01:31:51 pm
Quote
However, immediatly it returns to channel 1
Not sure what you mean by that. The last code you posted does everything on channel 1.

Hmm, if I say . It does not change the instrument, it says it does, but its still the same sound. Im using Midi OX to see all the information thats coming out
85  Using Arduino / Project Guidance / Re: Several instruments [MIDI] on: April 28, 2012, 01:01:45 pm
Okey now Im able to see that I am changing channel, and also instrumment (steel str guitar). However, immediatly it returns to channel 1, how come?

86  Using Arduino / Project Guidance / Re: Several instruments [MIDI] on: April 28, 2012, 11:53:37 am
I think Im starting to get this.
Ill upload my code sketch, no serious code atm just testing around so dont laugh smiley-razz
This isnt finished cause it should only change to the other channel, if this is correct Ill make it reversible
Code:
#define midiChannel  0xc1;

const int knapp1 = 8;
const int knapp2 = 9;

int state1 = HIGH;

void setup() {
  pinMode(knapp1, INPUT);
  pinMode(knapp2, INPUT);
  Serial.begin(57600);
}
 
 void loop() {
     int buttonstate2 = digitalRead(knapp2);
    
     if(buttonstate2 == HIGH){
       programChange(0xc0, 25);
     }
  
     int  buttonstate1 = digitalRead(knapp1);
    
      //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
     if(buttonstate1 != state1){
     if(buttonstate1 == HIGH)
     {
       noteOn(0x90, 0x1B, 0x45);
     }
     //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
      else{
        noteOn(0x90, 0x1A, 0x00);  
       }
       state1 = !state1;
     }
    
    
 }
 
 void noteOn(int cmd, int pitch, int velocity) {
   Serial.write(cmd);
   Serial.write(pitch);
   Serial.write(velocity);
 }
 
 //  change the voice
void programChange(char cmd, char data1) {
  cmd = cmd | char(midiChannel);  // merge channel number
  Serial.write(cmd);
  Serial.write(data1);
}

Im although getting an error here.
Quote
sketch_apr28b.cpp: In function 'void programChange(char, char)':
sketch_apr28b:47: error: expected primary-expression before 'char'
sketch_apr28b:47: error: expected `;' before 'char'
sketch_apr28b:47: error: expected primary-expression before ')' token
sketch_apr28b:47: error: expected `;' before ')' token
Marking this line:   cmd = cmd | char(midiChannel);  // merge channel number
87  Using Arduino / Project Guidance / Re: Several instruments [MIDI] on: April 28, 2012, 10:15:45 am
Thanks for the quick reply.

How do I know which channel number it is?
Could you explain a bit what u actually did?

There are three variables
(x, y, z)
x = Action + Channel
y = note
z = velocity and such.

I do understand your code, but not exactly why we are doing that.

Cheers

Edit:
So 0x90 is channel 1, and 0x91 should be channel 2 I guess?
And isnt something missing in programChange, there are only 2 variables, shouldn there be 3?
88  Using Arduino / Project Guidance / Several instruments [MIDI] on: April 28, 2012, 09:40:49 am
Hello dear fellow members,

Ive succeeded to setup my arduino MIDI interface, with a software called Ableton live 8.

Now I want to take it a step further, by playing different types of instrument by just using a simple potentiometer.
The use of a potentiometer is ofcourse very simple, but I dont really get the part where you can change instrument.

Ive read some threads by using the search function, and also read about the midi and how things work from pages that Arduino.cc offers.

I have no clue actually what to do. In Ableton I can configure more than one MIDI instrument, but I do only kno how to activate em manually through the computer. Ive read about channels, but I do no even know what channel it is Im configuring.

Could some1 guide me through a bit?

Cheers!
89  Using Arduino / Audio / Re: setting up midi [HELP][NEWBIE] on: April 26, 2012, 08:34:56 am
Additional information to make it easier for you to help me.

To make sure there is nothing wrong with the connection between the DIN chassi and the USB midi cable, I wired up the DIN with the piano DIN, as I said to make sure my DIN connection is working.

And my piano were able to play tones on the midi synth.

So there must be a problem with my circuit. I can notify on my arduino UNO that the TX led is going on and off.

Why am I not recieving any data from the arduino?
90  Using Arduino / Audio / Re: setting up midi [HELP][NEWBIE] on: April 26, 2012, 06:26:05 am
Ive tried that code, without success.
And Ive tried to connect a 220ohm resistor to TX and +5v, still no success.

Maybe I have missunderstood how things really work here.
Just to make sure, ALL u need is some resistors and the DIN chassi? Right?
Pages: 1 ... 4 5 [6] 7