xxxxxxxxxx
57
/* 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 capture;
function setup() {
createCanvas(320, 240);
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/tty.usbmodem144201"); // open a port
capture = createCapture(VIDEO);
capture.size(width, height);
capture.hide();
}
function draw() {
background(255,0,0);
image(capture, 0, 0);
var ourPixel = get(mouseX, mouseY);
var ourBrightness = floor(brightness(ourPixel));
serial.write(ourBrightness);
}
// get the list of ports:
function printList(portList) {
for (var i = 0; i < portList.length; i++) {
// Display the list the console:
print(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);
}
}
*/