Bluetooth.java 1006 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 char[] getRoute()
  11. {
  12. int adChar = 0;
  13. char endRoute = '?';
  14. char[] route = new char[40];
  15. while (true)
  16. {
  17. if (rxUart.byteAvailable())
  18. {
  19. char temp = (char)rxUart.receiveByte();
  20. data[adChar] = temp;
  21. if (endRoute == temp)
  22. {
  23. route = data;
  24. break;
  25. }
  26. adChar ++;
  27. }
  28. if (adChar == 40)
  29. {
  30. System.out.println("De opgegeven route is te groot. Voer maximaal 40 route-aanwijzingen in.");
  31. break;
  32. }
  33. CPU.delay(100);
  34. }
  35. return route;
  36. }
  37. }