PianoDuino (Arduino + Processing + SoundCipher)

PianoDuino é um experimento simples que integra Arduino, Processing e uma biblioteca para manipular sons, a SoundCipher. A idéia 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. Controlando a Arduino com PHP via porta serial
  3. Classe C++ para controlar Display de 7 seguimentos
  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

  1. There are no trackbacks for this post yet.

Leave a Reply