Advertisement
Guest User

Imp Code

a guest
Jul 10th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. class Coordinate extends InputPort{
  2.     type = "integer"
  3.     name = "position"
  4.    
  5.     constructor(name){
  6.     base.constructor(name)
  7.     }
  8.    
  9.  function set(value) {
  10.         server.show("X: "+value.x+", Y:  "+value.y+", Angle: "+value.z);
  11.         server.log("X: "+value.x+", Y:  "+value.y+", Angle: "+value.z);
  12.         hardware.uart57.write(value.x+","+value.y+","+value.z);
  13. }
  14. }
  15.  
  16. function initUart()
  17. {
  18. hardware.configure(UART_57); // Using UART on pins 5 and 7
  19. hardware.uart57.configure(19200, 8, PARITY_NONE, 1, NO_CTSRTS);     //Setting up a channel between Arduino and EI
  20. }
  21.  
  22. // UART polling function.
  23. function pollUart()
  24. {
  25. imp.wakeup(0.001, pollUart.bindenv(this)); // schedule the next poll in 10us
  26. local s = "";
  27. local byte = hardware.uart57.read();
  28.  
  29. while(byte != -1) {
  30. s+=byte.tochar();
  31. byte = hardware.uart57.read();
  32. server.log("reading byte");
  33. }
  34.  
  35. if(s.len())server.show(s);
  36. server.log(s);
  37. }
  38.  
  39. // Executing the functions
  40. imp.configure("RobotWireless", [Coordinate("Coordinates")], []);
  41. initUart(); // Initialize the UART, called just once
  42. pollUart(); // start the UART polling, this function continues to call itself
  43.  
  44. //NOTES: The "reading byte" string never shows up on the log.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement