Skip to content

Instantly share code, notes, and snippets.

var serial; // variable to hold an instance of the serialport library
var portName = 'dev/cu.usbmodem97'; // fill in your serial port name here
var inData; // for incoming serial data
function setup() {
createCanvas(400, 300);
serial = new p5.SerialPort(); // make a new instance of the serialport library
serial.on('list', printList); // set a callback function for the serialport list event
serial.on('connected', serverConnected); // callback for connecting to the server
serial.on('open', portOpen); // callback for the port opening
void setup() {
Serial.begin(9600); // initialize serial communications
}
void loop() {
int flexSensor = analogRead(A0); // read the input pin
int mappedflexSensor = map(flexSensor, 0, 1023, 0, 255); // remap the flex Sensor value to fit in 1 byte
Serial.println(mappedflexSensor); // print it out the serial port
delay(1); // slight delay to stabilize the ADC
}
@fergfluff
fergfluff / Arduino code to read flex sensor and map it to 1 byte so we can use Serial.write() command
Created October 15, 2017 20:16
Arduino code to read flex sensor and map it to 1 byte so we can use Serial.write() command
void setup() {
Serial.begin(9600); // initialize serial communications
}
void loop() {
int flexSensor = analogRead(A0); // read the input pin
int mappedflexSensor = map(flexSensor, 0, 1023, 0, 255); // remap the flex sensor value to fit in 1 byte
Serial.write(mappedflexSensor); // print it out the serial port
delay(1); // slight delay to stabilize the ADC (analog to digital converter on the microcontroller
}
@fergfluff
fergfluff / Setting up my p5 sketch to list my serial ports
Created October 15, 2017 19:38
Setting up my p5 sketch to list my serial ports
let serial; //Variable to hold instance of the serialport library;
function setup() {
serial = new p5.SerialPort(); //Make a new instance of the serialport library
serial.on('list', printList); //Set a call back function for the serial port list
serial.list(); //List the serial ports
}
//Get the list of serial ports
@fergfluff
fergfluff / Pandas
Created October 4, 2017 01:27
Pandas
var x = 100;
var y = 100;
var facesize = 150;
var firstpointx = 102;
var firstpointy = 128;
var secondpointx = 100;
var secondpointy = 145;
function setup() {
createCanvas(400, 400);
@fergfluff
fergfluff / Hot Cross Buns with Arduino
Created October 1, 2017 15:42
Hot Cross Buns with Arduino
#include "pitches.h"
//Make a sketch that plays a note on each sensor when
//the sensor is above a given threshold.
//
//Start with a few constants: one for the threshold,
//one for the speaker pin number, and one for the
//duration of each tone. To make this instrument work,
//you need to know what note corresponds to each sensor.
//Include pitches.h as you did above, then make an array
#include <Servo.h>
//First, find out the range of your sensor by using analogRead()
//to read the sensor and printing out the results.
//Now, map the result of the analog reading to a range from 0 to 179,
//which is the range of the sensor in degrees. Store the mapped
//value in a local variable called servoAngle.
//Finally, add the servo library at the beginning of your code,
@fergfluff
fergfluff / Class 2 Circles and Squares
Last active September 17, 2017 13:23
Class 2 Circles and Squares
//Description: A sketch of random circles, squares that
//follow your cursor, and a background the changes when
//you press the mouse
//Notes and Questions:
//Organizing code by creating javascript objects
//?Are these overridden later in my code when I give these new
//limits?