Bluetooth.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package bluetooth;
  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[] data = new char[40];
  10. public void getRoute()
  11. {
  12. int adChar = 0;
  13. char endRoute = '?';
  14. while (true)
  15. {
  16. if (rxUart.byteAvailable())
  17. {
  18. char temp = (char)rxUart.receiveByte();
  19. data[adChar] = temp;
  20. if (endRoute == temp)
  21. {
  22. returnRoute();
  23. break;
  24. }
  25. adChar ++;
  26. if (adChar == 40)
  27. {
  28. System.out.println("De opgegeven route is te groot. Voer maximaal 40 route-aanwijzingen in.");
  29. break;
  30. }
  31. }
  32. if (!rxUart.byteAvailable())
  33. {
  34. break;
  35. }
  36. CPU.delay(100);
  37. }
  38. }
  39. private char[] returnRoute()
  40. {
  41. System.out.println("Array:");
  42. System.out.println(data[0]);
  43. System.out.println(data[1]);
  44. System.out.println(data[2]);
  45. return data;
  46. }
  47. }