PianoDuino (Arduino + Processing + SoundCipher)

PianoDuino é um experimento simples que integra Arduino, Processing e uma biblioteca para manipular sons, a SoundCipher. A ideia serviu para experimentar o Multiplexador / Demultiplexador 4051.

PianoDuino (Arduino + Processing + SoundCipher) from Bruno Soares on Vimeo.

Arduino:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
 * PianoDuino
 *
 * @author   Bruno Soares
 * @link     http://www.bsoares.com.br
 * @language Arduino / C++
 */


#define PIN_SELECTOR0 2
#define PIN_SELECTOR1 3
#define PIN_SELECTOR2 4

int value;
int count;

// Selectors
byte s0;
byte s1;
byte s2;

void setup()
{
  Serial.begin(9600);
 
  pinMode(PIN_SELECTOR0, OUTPUT);
  pinMode(PIN_SELECTOR1, OUTPUT);
  pinMode(PIN_SELECTOR2, OUTPUT);
}

void loop()
{
  for (count = 0; count < 8; count++)
  {
    // Extract active bits
    s0 =  count       & 0x1;
    s1 = (count >> 1) & 0x1;
    s2 = (count >> 2) & 0x1;
   
    // Select input
    digitalWrite(2, s0);
    digitalWrite(3, s1);
    digitalWrite(4, s2);
   
    // Read input selected
    value = analogRead(0);
    if (value > 5)
    {
      Serial.print(count);
      while(analogRead(0) > 5);
    }
  }
}

Processing:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
 * PianoDuino
 *
 * @author   Bruno Soares
 * @link     http://www.bsoares.com.br
 * @language Processing
 */


import arb.soundcipher.*;
import processing.serial.*;

SoundCipher[] sc = new SoundCipher[8];
Serial port;
int portValue = 0;

void setup()
{
  for (int i = 0; i < sc.length; i++)
  {
    sc[i] = new SoundCipher(this);
  }
 
  println(Serial.list());
  port = new Serial(this, Serial.list()[1], 14400);
}

void draw()
{
  while (port.available() > 0) {
    portValue = int(port.readString().substring(0, 1));
    print(portValue);
    sc[portValue].playNote(80 - (portValue * 7), 100, 2.5);
  }
}

Baixe o código fonte completo aqui.

 


 

Conteúdo relacionado:
Fotos no Flickr
Arduino
Processing
SoundCipher
Analog multiplexer / demultiplexer 4051


Posts relacionados:

  1. Controlando Led RGB com Arduino e Processing
  2. Classe C++ para controlar Display de 7 seguimentos
  3. Controlando a Arduino com PHP via porta serial
  4. Ping Pong com Matriz de Leds 8×8
  5. Twitter Hardware

  1. leigo disse:

    Será que tem como disponibilizar o esquema de ligações?
    valeu pelo projecto,,, esta muito bom mesmo.

  2. Bruno Soares disse:

    Pô vai dar um trampinho fazer este esquema, mas faz assim, se você entender como funciona o Mux/Demux 4051 (http://www.arduino.cc/playground/Learning/4051) você mata a solução do esquema.

    Boa sote, é facinho ;)

  3. gamesh_ disse:

    gostei muito dos projetos principalmento com arduino pretendo testar.

  4. AmeliA disse:

    Hi Bruno Soares, thanks for sharing this, I hope you understand my English, I used google translate to read you blog. I’m a student trying to implement part of this to my project.

    I’ve been trying out your example, after I survive the wiring, installation of program, I had problem testing the switches. I’m using usb serial port (com3), then run the arduino program and uploaded the program, and when i run processing, only a note is played. I press the button on arduino itself, the note play again but when I press the switches (on breadboard) no sound. I was hoping you could give a hint or guide as to what the problem might be :)

  5. AmeliA disse:

    Thanks Bruno Soares, Thanks so much for sharing your code!!! Haha Finally I got it working! Its the switch, they cannot be on the same slot on the breadboard. But from your photos, they seems to be on the same, nonetheless, thanks Bruno Soares!! hahaa

  6. Lalo R. disse:

    I have a problem, when I run the code Pianuino in processing, doesn’t do nothing an display a message:

    ArrayIndexOutOfBoundsException: 1

    What can I do???

  7. Lalo R. disse:

    yes, I did but the error is found in the line 24:

    port = new Serial(this, Serial.list()[1], 14400);

    Thank you so much for your help.

  8. Lalo R. disse:

    Thanks a lot Bruno, it’s finally working. There’s just a little detail, it seems that I can only play a sequence (0, 1, 2, 3, 4, 5, 6, 7) and then I have to reset the arduino in order to be able to play again. In your video I can see that you’re able to alternate the notes you play, and the 0 button is the card’s reset, therefore I can only use 7 of the 8 available switches, I do not know what makes this happen and I’d appreciate it a lot if you could help me with this problem.

  9. captalex disse:

    i can see you used python for you second page of code for the processing, nice one, i cant just seem to find any durable material for all these!

  10. Madienne disse:

    Hi Bruno Soares, thanks for sharing. Can you use this setup and codes for any other instrument such as a steel pan/drum sounds for example?

  11. Rush1 disse:

    Hiii, I’m getting the same error as Lalo, I changed it to Serial.list() [0] and I’m getting an error : Error inside Serial. (). HELP!!

  12. Moxi disse:

    Hi – I’m would like to replicate your setup and have a newbie question: you have two files, do I need to upload both of these to the arduino board? Once I have it up and running I will post a link to to my own project on your site. I hope to hear back from you :)

    Best wishes,
    Moxi

  13. Moxi disse:

    Hi,

    I was wondering if you could enlighten me in regard to where you put the files. One has to be uploaded to the Arduino (the arduino file) but where abouts do I have to put the other one (Processing)?

    Thanks

  14. pedro disse:

    ola podes me dizer qual os valores das resistencias?

  15. avenger disse:

    Hi, thanks for sharing.
    I have a question about that. I press all buttons but I only can get one sound from the processing, the sound is 0 one, i think it is the left one button sound.

    could you please help me how can i solve this problem?

  16. brendo luiz P. fernandes disse:

    Amigo para fazer esse projeto é preciso do
    4051 ?
    abraçs!

  1. There are no trackbacks for this post yet.

Leave a Reply