xxxxxxxxxx
60
/* Danny Rozin
Introduction to Physical Computing
ITP
This sketch will send one binary byte from P5 to arduino
See arduino code in bottom, have LED connected to pin 3
move mouseX to dim LED*/
var serial; // variable to hold an instance of the serialport library
var fromSerial = 0; //variable to hold the data
var capture;
function setup() {
createCanvas(320, 240);
capture = createCapture(VIDEO);
capture.size(320, 240);
capture.hide();
serial = new p5.SerialPort(); // make a new instance of serialport librar
serial.on('list', printList); // callback function for serialport list event
serial.on('data', serialEvent); // callback for new data coming in
serial.list(); // list the serial ports
serial.open("/dev/cu.usbmodem14131"); // open a port
}
function draw() {
image(capture, 0, 0, 320, 240);
var ourColor=get (mouseX,mouseY);
var ourBrightness = brightness(ourColor);
serial.write(ourBrightness); // sends as byte unles iyts a string
}
// get the list of ports:
function printList(portList) {
for (var i = 0; i < portList.length; i++) {
// Display the list the console:
println(i + " " + portList[i]);
}
}
function serialEvent() {
// this is called when data is recieved
}
/*
// Arduino Code
void setup() {
Serial.begin(9600);
}
void loop() {
if(Serial.available()){
byte byteFromSerial = Serial.read();
analogWrite(3,byteFromSerial);
}
}
*/