Skip to content

Instantly share code, notes, and snippets.

@todocono
Last active November 17, 2022 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todocono/7f5b6610bdee4148c82323043c8da406 to your computer and use it in GitHub Desktop.
Save todocono/7f5b6610bdee4148c82323043c8da406 to your computer and use it in GitHub Desktop.
/**
* Based on SendMultipleValue - See more at https://osteele.github.io/Processing_SerialRecord/
*
* Processing code
* Programmed in class - Interaction Lab 2022Fall
*
*
*/
import processing.serial.*;
import osteele.processing.SerialRecord.*;
//here I imported the code from SineWave example from Sound Library
import processing.sound.*;
SinOsc sine;
Serial serialPort;
SerialRecord serialRecord;
void setup() {
size(500, 500);
String serialPortName = SerialUtils.findArduinoPort();
serialPort = new Serial(this, serialPortName, 9600);
// If the Arduino sketch sends a different number of values, modify the number
// `2` on the next line to match the number of values that it sends.
serialRecord = new SerialRecord(this, serialPort, 2);
//here I copied the lines from SineWave example
sine = new SinOsc(this);
sine.play();
}
void draw() {
background(0);
serialRecord.read();
int value1 = serialRecord.values[0];
int value2 = serialRecord.values[1];
float x = map(value1, 300, 1024, 0, width);
float y = map(value2, 0, 1024, 0, height);
circle(x, y, 20);
// Map y from 0.0 to 1.0 for amplitude
float amplitude = map(y, 0, height, 1.0, 0.0);
sine.amp(amplitude);
// Map x from 20Hz to 1000Hz for frequency
float frequency = map(x, 0, width, 80.0, 1000.0);
sine.freq(frequency);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment