Last active
December 20, 2015 01:09
-
-
Save rwaldron/6046654 to your computer and use it in GitHub Desktop.
blink.js & blink.ino
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
int bytesRead = 0; | |
boolean isPinSet; | |
byte stored[2]; | |
void setup() { | |
Serial.begin(57600); | |
} | |
void loop() { | |
while (Serial.available()) { | |
int data = Serial.read(); | |
stored[bytesRead] = data; | |
bytesRead++; | |
if (bytesRead == 2) { | |
if (isPinSet == false) { | |
isPinSet = true; | |
pinMode(stored[0], OUTPUT); | |
} else { | |
digitalWrite(stored[0], stored[1]); | |
} | |
bytesRead = 0; | |
} | |
// Serial.write(Serial.read()); | |
} | |
} |
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
var serial, raddress, pin; | |
serial = require("../serialport.js"); | |
raddress = /usb|acm|com/i; | |
pin = 13; | |
serial.list(function(err, result) { | |
var address, port, byte; | |
var read = new Buffer(0); | |
if (result.length) { | |
address = result.filter(function(val) { | |
// Match only addresss that Arduino cares about | |
// ttyUSB#, cu.usbmodem#, COM# | |
if ( raddress.test(val.comName) ) { | |
return val; | |
} | |
}).map(function(val) { | |
return val.comName; | |
})[0]; | |
port = new serial.SerialPort(address, { | |
baudrate: 57600, | |
buffersize: 1 | |
}); | |
port.on("open", function() { | |
var byte; | |
function loop() { | |
port.write([pin, (byte ^= 0x01)]); | |
} | |
setInterval(loop, 500); | |
}); | |
} else { | |
console.log("No valid port found"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment