Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Coordinate extends InputPort{
- type = "integer"
- name = "position"
- constructor(name){
- base.constructor(name)
- }
- function set(value) {
- server.show("X: "+value.x+", Y: "+value.y+", Angle: "+value.z);
- server.log("X: "+value.x+", Y: "+value.y+", Angle: "+value.z);
- hardware.uart57.write(value.x+","+value.y+","+value.z);
- }
- }
- function initUart()
- {
- hardware.configure(UART_57); // Using UART on pins 5 and 7
- hardware.uart57.configure(19200, 8, PARITY_NONE, 1, NO_CTSRTS); //Setting up a channel between Arduino and EI
- }
- // UART polling function.
- function pollUart()
- {
- imp.wakeup(0.001, pollUart.bindenv(this)); // schedule the next poll in 10us
- local s = "";
- local byte = hardware.uart57.read();
- while(byte != -1) {
- s+=byte.tochar();
- byte = hardware.uart57.read();
- server.log("reading byte");
- }
- if(s.len())server.show(s);
- server.log(s);
- }
- // Executing the functions
- imp.configure("RobotWireless", [Coordinate("Coordinates")], []);
- initUart(); // Initialize the UART, called just once
- pollUart(); // start the UART polling, this function continues to call itself
- //NOTES: The "reading byte" string never shows up on the log.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement