Go Down

Topic: polyphonic piano with arduino?? (Read 10517 times) previous topic - next topic

GrooveFlotilla

Code: [Select]
          {
          if(A == [glow]0[/glow])  //which key held down
          {
           tones[[glow]0[/glow]] = 262;  //store the tone in array
               buttonState[[glow]0[/glow]] = LOW; //store the state in array
        }
        if(A ==[glow] 1[/glow])
        {
           tones[[glow]1[/glow]] = 294;
               buttonState[[glow]1[/glow]] = LOW;
        }
        if(A == [glow]2[/glow])
        {
           tones[[glow]2[/glow]] = 330;
               buttonState[[glow]2[/glow]] = LOW;
        }

Do you see a pattern emerging?
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

falohao

#31
Mar 04, 2010, 03:40 pm Last Edit: Mar 04, 2010, 04:48 pm by falohao Reason: 1
Absolutely I see it. So that I may use shorter command?(Such as the last past?

If not using this, how can I map keys to tones? :-[

plz give me hints.>< this project is my first project using arduino. :-?

falohao

I wanted to ask:
If I attached an interruption, I can't use delay function?
Code: [Select]
void setup(){
attachInterrupt(0, A, CHANGE);}

void loop()
if(tones[t] == 262){
       digitalWrite(speakerpin[0], HIGH);
     [glow]delayMicroseconds(tones[t]);[/glow]
     digitalWrite(speakerpin[0], LOW);
     [glow]delayMicroseconds(tones[t]);}[/glow]

PaulS

I asked this before, but you didn't answer. Why are you not using the tone library functions for making the sounds? Tone::play() and Tone::Stop() are so much easier to use.
The art of getting good answers lies in asking good questions.

falohao

I write some code which included tone.h, but I don't know how to read keys and play note= = I think the syntax is dedicated, am I right. I've found this link:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1251750920/25

Can you give me some guide lines?
here is my code, it's so primary>< :'(
Code: [Select]
#include <Tone.h>

#define NOTE_C4;
#define NOTE_D4;
Tone notePlayer[2];

int key[] = {2, 3};
int sp1 = 11;
int sp2 = 12;
int A = HIGH;
int B = HIGH;

void setup(void)
{
 Serial.begin(9600);
 notePlayer[0].begin(11);
 notePlayer[1].begin(12);
 pinMode(key[0], INPUT);
 pinMode(key[1], INPUT);
}

void loop(void)
{
 for(int x=0;x<2;x++)
{if(HIGH == digitalRead{key[x]}){
  if(x = 0){
  notePlayer[0].play('NOTE_C4');
  Serial.print("pin 11:");
  Serial.println('NOTE_C4');
  break;
  notePlayer[0].stop();
  break;}
 
  if(x = 1){
  notePlayer[0].play('NOTE_D4');
  Serial.print("pin 11:");
  Serial.println('NOTE_D4');
  break;
  notePlayer[0].stop();
  break;}
}

PaulS

Code: [Select]
if(x = 0){


You want == in there, not =.
The art of getting good answers lies in asking good questions.

falohao

Sorry, I wrote a new one, but it didnt be compiled. here's my code.
Code: [Select]
#include <Tone.h>

int speakerA = 12;
int speakerB = 13;
int keyA = 2;
int keyB = 3;

Tone tone1;
Tone tone2;

int buttonStateA = 0
int buttonStateB = 0

void setup()
{
 tone1.begin(12);
 tone2.begin(13);
 
 pinMode(keyA, INPUT);
 pinMode(keyB, INPUT);
}

void loop()
{
 buttonStateA = digitalRead(keyA);
 if (buttonStateA == HIGH)
 {
   tone1.play(NOTE_A4);
   delay(500);
   tone1.stop();
 }
 buttonStateA = digitalRead(keyB);
 if (buttonStateB == HIGH)
 {
   tone2.play(NOTE_B4);
   delay(500);
   tone2.stop();
 }
}


Error: expected unqualified-id before numeric const. :P

PaulS

#37
Mar 06, 2010, 05:23 pm Last Edit: Mar 06, 2010, 05:23 pm by PaulS Reason: 1
Code: [Select]
int buttonStateA = 0


I detect a missing ; here, and on the next line, too. I think the compiler did to.

Code: [Select]
 buttonState[glow]A[/glow] = digitalRead(keyB);
 if (buttonState[glow]B[/glow] == HIGH)
 {


Where did buttonStateB get a value?
The art of getting good answers lies in asking good questions.

falohao

#38
Mar 06, 2010, 05:35 pm Last Edit: Mar 06, 2010, 05:37 pm by falohao Reason: 1
Corrected it. resulting in the same= =
expected unqualified-id before numeric constant= =

according to this link #9reply

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1257390337

on the other hand, what commands can I use if code without delay function?

PaulS

Quote
Corrected it. resulting in the same= =
expected unqualified-id before numeric constant= =


What = = are you talking about? Where's the current code?

Quote
on the other hand, what commands can I use if code without delay function?


Wouldn't you be better off getting something working, first?
The art of getting good answers lies in asking good questions.

falohao

ok. i changed int buttonstateA=low and also buttonstateB.
then it can be compile.

but it keeps playing tone1 then tone2 then tone1......
with no key pressed, whatever i press switch1 and switch2, no any respond but tones keep playing. :-/

PaulS

Can you lean to one side so I can see over your shoulder? Umm, still can't see...
The art of getting good answers lies in asking good questions.

falohao

Polyphonic piano has been done few days ago....the sounds come in square waves, I want to make it to be sine waves or saw and sth. else.

But how can I accomplish waveform shaping??
Pots? PWM? any suggestion? :'(

Go Up