Skip to content

Instantly share code, notes, and snippets.

@todocono
Created November 17, 2022 02:56
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/4312908a861a4a620bce452d4d5e8f89 to your computer and use it in GitHub Desktop.
Save todocono/4312908a861a4a620bce452d4d5e8f89 to your computer and use it in GitHub Desktop.
/* 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