Bluetooth.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package boebot;
  2. import stamp.core.*;
  3. public class Bluetooth
  4. {
  5. final static int SERIAL_RX_PIN = CPU.pin14;
  6. final static int SERIAL_TX_PIN = CPU.pin15;
  7. static Uart rxUart = new Uart(Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert, Uart.speed9600, Uart.stop1);
  8. static Uart txUart = new Uart(Uart.dirTransmit, SERIAL_TX_PIN, Uart.dontInvert, Uart.speed9600, Uart.stop1);
  9. private char[] route = new char[40];
  10. private int counter = 0;
  11. public void getRoute()
  12. {
  13. while (true)
  14. {
  15. if (rxUart.byteAvailable())
  16. {
  17. route[counter] = (char)rxUart.receiveByte();
  18. counter ++;
  19. }
  20. if (route[counter] == '¿')
  21. {
  22. counter = 0;
  23. givenRoute();
  24. break;
  25. }
  26. if (route[counter] == '¡')
  27. {
  28. counter = 0;
  29. calculateRoute();
  30. break;
  31. }
  32. CPU.delay(100);
  33. }
  34. }
  35. public char[] givenRoute()
  36. {
  37. char[] sendRoute = route;
  38. return sendRoute;
  39. }
  40. public char[] calculateRoute()
  41. {
  42. char[] sendRoute = new char[40];
  43. int charTest = 0;
  44. int addValue = 0;
  45. while (true)
  46. {
  47. if (route[charTest] != ',' && route[charTest] != '!' && route[charTest] != '¡')
  48. {
  49. sendRoute[addValue] = route[charTest];
  50. addValue ++;
  51. }
  52. if (route[charTest] == '¡')
  53. {
  54. break;
  55. }
  56. charTest ++;
  57. }
  58. return sendRoute;
  59. }
  60. }