Last active
July 6, 2020 19:06
-
-
Save RFullum/69dbe894827a5b05d02185a30235dc4e to your computer and use it in GitHub Desktop.
Touchscreen XY Controller over Serial/Bluetooth: Processing Sketch (Raspberry Pi)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Processing 3 sketch: Used on Raspberry Pi with 7" touchscreen. | |
// Touchscreen tracks XY position of finger and sends as serial data over | |
// bluetooth. That data is received by MaxMSP patch and used to control | |
// cutoff frequency and resonance of audio filters, real time. | |
import processing.serial.*; | |
Serial port; | |
int val = 0; | |
int valueScale = 128; | |
//main window | |
void setup() { | |
fullScreen(); | |
printArray(Serial.list()); | |
port = new Serial(this, Serial.list()[0], 115200); | |
} | |
//create touch crosshair vertical line | |
void verticalLine() { | |
line(mouseX, 0, mouseX, height); | |
} | |
//create touch crosshair horizontal line | |
void horizontalLine() { | |
line(0, mouseY, width, mouseY); | |
} | |
//Get XY coordinates of touch/mouse | |
void touchLocation() { | |
} | |
void printLocation() { | |
print(mouseX, "\t" , mouseY, "\n"); | |
} | |
//draw crosshairs that follow touch on screen or mouse | |
void draw() { | |
background(97, 255, 250); | |
verticalLine(); | |
horizontalLine(); | |
int xByte = (mouseX * valueScale)/ width; | |
int yByte = (mouseY * valueScale)/ height; | |
//int xByte = (int)map(mouseX, 0, width, 0, valueScale); //valueScale needs to be 127 | |
port.write(xByte); | |
port.write(yByte); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment