Created
November 17, 2022 02:56
-
-
Save todocono/4312908a861a4a620bce452d4d5e8f89 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
/* PROCESSING CODE | |
/** | |
* Example sketch for the SerialRecord library for Processing. | |
* | |
* Receives an integer from the serial port, and uses it to control the | |
* horizontal positon of a line on the canvas. | |
* | |
* This sketch has the same effect as calling `serialPort.read(0)`. | |
* | |
* If your sketch needs to receive only a single value, consider using that | |
* function instead of this library. | |
* | |
* The only advantage of the approach in this sketch is that it is simple to | |
* modify it to receive a second value, as ReceiveMultipleValues demonstrates. | |
*/ | |
import processing.serial.*; | |
import osteele.processing.SerialRecord.*; | |
Serial serialPort; | |
SerialRecord serialRecord; | |
void setup() { | |
size(500, 500); | |
String serialPortName = SerialUtils.findArduinoPort(); | |
serialPort = new Serial(this, serialPortName, 9600); | |
serialRecord = new SerialRecord(this, serialPort, 1); | |
} | |
void draw() { | |
background(255); | |
serialRecord.read(); | |
int value = serialRecord.get(); | |
float x = map(value, 0, 1024, 0, height); | |
line(x, 0, x, height); | |
} | |
*/ | |
/* | |
/* | |
ARDUINO CODE | |
SendSingleValue | |
This sketch repeatedly sends a record that contains a single value. The value | |
is the value of `millis()`, modulo 32768. | |
This sketch pairs well with the ReceiveSingleValue example from the | |
Processing SerialRecord library | |
<https://osteele.github.io/Processing_SerialRecord/>. | |
You can also use the Serial Monitor to inspect the values that the sketch | |
sends to the serial port. | |
Things to try: | |
- Connect a potentiometer to the Arduino, and send its value instead. | |
by Oliver Steele, 2020-2022 | |
This example code is in the public domain. | |
*/ | |
#include "SerialRecord.h" | |
SerialRecord writer(1); | |
void setup() { | |
Serial.begin(9600); | |
} | |
void loop() { | |
int value = analogRead(A0); | |
writer[0] = value; | |
writer.send(); | |
// This delay slows down the loop, so that it runs less frequently. This can | |
// make it easier to debug the sketch, because new values are printed at a | |
// slower rate. | |
delay(20); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment