Last active
November 17, 2022 02:42
-
-
Save todocono/7419c1055e4e2d74d96ba93fbe0fb383 to your computer and use it in GitHub Desktop.
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
/** | |
* Based on ReceiveSingleValue - See more at https://osteele.github.io/Processing_SerialRecord/ | |
* | |
* Processing code | |
* Programmed in class - Interaction Lab 2022Fall | |
* | |
* | |
*/ | |
import processing.serial.*; | |
import osteele.processing.SerialRecord.*; | |
Serial serialPort; | |
SerialRecord serialRecord; | |
int N_V = 3; // this is the number of values that Processing sends | |
void setup() { | |
size(500, 500); | |
String serialPortName = SerialUtils.findArduinoPort(); | |
serialPort = new Serial(this, serialPortName, 9600); | |
serialRecord = new SerialRecord(this, serialPort, N_V); | |
} | |
void draw() { | |
background(0); | |
// display instructions | |
pushStyle(); | |
textAlign(CENTER, CENTER); | |
textSize(20); | |
text("Hold the mouse button to send a 1 to the Arduino", 0, 0, width, height); | |
popStyle(); | |
if (mousePressed == true) { | |
serialRecord.values[0] = 1; | |
} else { | |
serialRecord.values[0] = 0; | |
} | |
//This makes sense out of the mouse position to feed into the Arduino | |
//I can choose to convert values here or when applying them with the LED or servos | |
float bright = map(mouseX, 0, width, 0, 255); | |
serialRecord.values[1] = floor(bright); | |
float servoPos = map(mouseY, 0, width, 0, 255); | |
serialRecord.values[2] = floor(servoPos); | |
serialRecord.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment