Advertisement
Guest User

Untitled

a guest
Mar 4th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <SPP.h>
  2. USB Usb;
  3. BTD btd(&Usb);
  4. SPP SerialBT(&btd,"PDM Arduino","0001");
  5.  
  6. boolean firstMessage = true;
  7.  
  8. void setup() {
  9.   Serial.begin(115200);
  10.   if (Usb.Init() == -1){
  11.     Serial.print(F("\r\nOSC did not start"));
  12.     while(1);
  13.   }
  14.   Serial.print(F("\r\nSPP Bluetooth started"));
  15. }
  16. void loop() {
  17.   Usb.Task();
  18.   if(SerialBT.connected){
  19.     if(firstMessage){
  20.       firstMessage = false;
  21.       SerialBT.println(F("Hello from Arduino"));
  22.       Serial.println("HELLO!");
  23.       /*
  24.       for( int i = 0; i < 256; i++){
  25.         Serial.print("0x");
  26.         Serial.print(i,HEX);
  27.         Serial.print(" - ");
  28.         Serial.write(i);
  29.         Serial.println();
  30.       }
  31.       */
  32.     }
  33.     if(Serial.available()){
  34.       SerialBT.print((char)Serial.read());
  35.     }
  36.     if(SerialBT.available()){
  37.       Serial.print("Tilgaengelig:");
  38.       Serial.println(SerialBT.available());
  39.       int times = 0;
  40.     while(SerialBT.available()){
  41.       char k = SerialBT.read();
  42.       times++;
  43.       char c = (char)k;
  44.       if(c == '0' || c == '1' ||c == '2' ||c == '3' ||c == '4' ||c == '5' ||c == '6' ||c == '7' ||c == '8' ||c == '9'){
  45.        
  46.       }
  47.       else{
  48.        
  49.         Serial.println();
  50.         Serial.print("Fejl:");
  51.         Serial.print(times);
  52.         Serial.print(" - 0x");
  53.         Serial.print(c,HEX);
  54.       }
  55.      
  56.     }
  57.     }
  58.   }
  59.   else{
  60.     firstMessage = true;
  61.   }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement