Theremin analog
in
Integration and Hardware
•
1 years ago
Hello, I am new here. So I am working with my project and I need advice.
I want to make theremin music device useing 2 x HC-SR04 ultrasonic range finders, Arduino and Processing,
With one URF I will change sound frequince, with other volume.
At this stage of project I
successfully getting data from arduino to processing and I am generating sound, but I am not able to put data from serial port to to line where sound is generating, what I need to do ?
Simply I don't know how to send data from one class to onother, maybe someone can give me a link to good tutorial about this.
Thanks for help
- import processing.serial.*;
- import ddf.minim.*;
- import ddf.minim.signals.*;
- import ddf.minim.effects.*;
- Serial myPort;
- Minim minim;
- SineWave sound;
- AudioOutput out;
- Theremin buzz;
- int data = 0;
- void serialEvent (Serial myPort) {
- String bufferString = myPort.readStringUntil('\n');
- if (bufferString != null) {
- bufferString = trim(bufferString);
- data = int(bufferString);
- println(data);
- }
- }
- void setup()
- {
- size(200, 200);
- myPort = new Serial(this, Serial.list()[1], 9600);
- myPort.bufferUntil('\n'); // change
- minim = new Minim(this);
- out = minim.getLineOut(Minim.STEREO, 512);
- buzz = new Theremin(200, 0.5); // how to put variable data from serial port instead 200 ?
- buzz.play();
- }
- void draw() {
- background(0, 0, 0);
- }
- void stop()
- {
- out.close();
- minim.stop();
- super.stop();
- }
- class Theremin {
- //global variable
- int freq = 0;
- float volume = 0;
- //constructor
- Theremin(int _freq, float _volume) {
- freq = _freq;
- volume = _volume;
- }
- //function
- void play() {
- sound = new SineWave (freq, volume, 44100);
- out.addSignal(sound);
- }
- }
1