Advertisement
Pouknouki

Untitled

Mar 29th, 2015
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.46 KB | None | 0 0
  1. /*
  2.  * FM.h
  3.  * A library for SeeedStudio Grove FM
  4.  *
  5.  * Copyright (c) 2012 seeed technology inc.
  6.  * Website    : www.seeed.cc
  7.  * Author     : Steve Chang
  8.  * Create Time: JULY 2014
  9.  * Change Log : Modified by loovee 2013-10-29  ,   Modified by jacob yan 2014-7-29
  10.  
  11.  * The MIT License (MIT)
  12.  *
  13.  * Permission is hereby granted, free of charge, to any person obtaining a copy
  14.  * of this software and associated documentation files (the "Software"), to deal
  15.  * in the Software without restriction, including without limitation the rights
  16.  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17.  * copies of the Software, and to permit persons to whom the Software is
  18.  * furnished to do so, subject to the following conditions:
  19.  *
  20.  * The above copyright notice and this permission notice shall be included in
  21.  * all copies or substantial portions of the Software.
  22.  *
  23.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26.  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  29.  * THE SOFTWARE.
  30.  */
  31.  
  32.  
  33.  
  34. #include <SoftwareSerial.h>   //Software Serial Port
  35.  
  36. #define RxD         7
  37. #define TxD         6
  38.  
  39. #define PINLED      9
  40.  
  41. #define LEDON()     digitalWrite(PINLED, HIGH)
  42. #define LEDOFF()    digitalWrite(PINLED, LOW)
  43.  
  44. #define DEBUG_ENABLED  1
  45.  
  46. SoftwareSerial blueToothSerial(RxD,TxD);
  47.  
  48. void setup()
  49. {
  50.     Serial.begin(9600);
  51.     pinMode(RxD, INPUT);
  52.     pinMode(TxD, OUTPUT);
  53.     pinMode(PINLED, OUTPUT);
  54.     LEDOFF();
  55.    
  56.     setupBlueToothConnection();
  57.     delay(1000);
  58.     Serial.flush();
  59.     blueToothSerial.flush();
  60. }
  61.  
  62. void loop()
  63. {
  64.     char recvChar;
  65.    
  66.     while(1)
  67.     {
  68.         if(blueToothSerial.available())
  69.         {//check if there's any data sent from the remote bluetooth shield
  70.             recvChar = blueToothSerial.read();
  71.             Serial.print(recvChar);
  72.            
  73.             if(recvChar == '1')
  74.             {
  75.                 LEDON();
  76.             }
  77.             else if(recvChar == '0')
  78.             {
  79.                 LEDOFF();
  80.             }
  81.         }
  82.     }
  83. }
  84.  
  85.  
  86.  
  87.  
  88. /***************************************************************************
  89.  * Function Name: setupBlueToothConnection
  90.  * Description:  initilizing bluetooth connction
  91.  * Parameters:
  92.  * Return:
  93. ***************************************************************************/
  94. void setupBlueToothConnection()
  95. {  
  96.         blueToothSerial.begin(9600);  
  97.        
  98.         blueToothSerial.print("AT");
  99.         delay(400);
  100.      
  101.         blueToothSerial.print("AT+DEFAULT");             // Restore all setup value to factory setup
  102.         delay(2000);
  103.        
  104.         blueToothSerial.print("AT+NAMEEasyCourses");    // set the bluetooth name as "SeeedBTSlave" ,the length of bluetooth name must less than 12 characters.
  105.         delay(400);
  106.        
  107.       blueToothSerial.print("AT+PIN0000");             // set the pair code to connect
  108.         delay(400);
  109.      
  110.       blueToothSerial.print("AT+ROLE0");
  111.       delay(400);
  112.        
  113.         blueToothSerial.print("AT+AUTH1");             //
  114.        delay(400);    
  115.      
  116.       blueToothSerial.flush();
  117.       Serial.println("coucou");
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement