Mattie

Untitled

Sep 30th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.86 KB | None | 0 0
  1. //mattie's test troep
  2. #include "pitches.h"
  3. #include <Servo.h>          // Include servo library
  4. #include <SoftwareSerial.h> //bluetooth
  5. #define RxD 6
  6. #define TxD 7
  7. #define DEBUG_ENABLED  1
  8.  
  9. SoftwareSerial blueToothSerial(RxD,TxD);
  10.  
  11. const int baudRate = 9600;  //Default bauldRate
  12. int melody[] = {
  13.   NOTE_C6 };
  14. int noteDurations[] = {
  15.   6 };
  16. Servo servoLeft;            // Declare left servo
  17. Servo servoRight;
  18. int powerLED = 13;
  19. int actLED = 12;
  20. int speakerID = 8;
  21.  
  22.  
  23. void setup()
  24. {
  25.   Serial.begin(baudRate);
  26.   Serial.println("ohaaaai");
  27.   pinMode(RxD, INPUT); //bluetooth
  28.   pinMode(TxD, OUTPUT); //bluetooth
  29.   setupBlueToothConnection();
  30.  
  31.   pinMode(powerLED, OUTPUT);
  32.   pinMode(actLED, OUTPUT);
  33.  
  34.   activateLED();
  35.   muziek();
  36.  
  37.   // servoLeft.attach(2);
  38.   // servoRight.attach(4);
  39.   // stopServo();
  40.  
  41. }
  42.  
  43. void loop()
  44. {
  45.   //blinkActivityLed();
  46.  
  47.   char recvChar;
  48.   while(1){
  49.     if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
  50.       recvChar = blueToothSerial.read();
  51.       Serial.print(recvChar);
  52.     }
  53.     if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
  54.       recvChar  = Serial.read();
  55.       //Serial.print("sending through bluetooth......");
  56.       //Serial.println(recvChar);
  57.       blueToothSerial.print(recvChar);
  58.     }
  59.   }
  60. }
  61.  
  62. void setupBlueToothConnection()
  63. {
  64.   blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  65.   blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  66.   blueToothSerial.print("\r\n+STNA=DamBot\r\n"); //set the bluetooth name as "SeeedBTSlave"
  67.   blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  68.   blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  69.   delay(2000); // This delay is required.
  70.   blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
  71.   Serial.println("The slave bluetooth is inquirable!");
  72.   delay(2000); // This delay is required.
  73.   blueToothSerial.flush();
  74. }
  75.  
  76. void blinkActivityLed()
  77. {
  78.   digitalWrite(actLED, HIGH);
  79.   delay(200);
  80.   digitalWrite(actLED, LOW);
  81.   delay(200);
  82. }
  83.  
  84.  
  85. void muziek()
  86. {
  87.   // delay(10);
  88.   // iterate over the notes of the melody:
  89.   for (int thisNote = 0; thisNote < sizeof(melody) - 1; thisNote++) {
  90.  
  91.     // to calculate the note duration, take one second
  92.     // divided by the note type.
  93.     //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
  94.     int noteDuration = 1000/noteDurations[thisNote];
  95.     tone(speakerID, melody[thisNote],noteDuration);
  96.  
  97.     // to distinguish the notes, set a minimum time between them.
  98.     // the note's duration + 30% seems to work well:
  99.     //dit was * 1.30
  100.     int pauseBetweenNotes = noteDuration * 2;
  101.     delay(pauseBetweenNotes);
  102.     // stop the tone playing:
  103.     noTone(speakerID);
  104.   }
  105.   noTone(speakerID);
  106. }
  107.  
  108. void knipperLed()
  109. {  
  110.  
  111.   // Serial.println("dit is een test");
  112.   // delay(1000);  
  113.  
  114.   digitalWrite(13, HIGH);   //LED AAN
  115.   digitalWrite(12, LOW);   //LED UIT
  116.   digitalWrite(11, HIGH);
  117.   digitalWrite(10, LOW);
  118.  
  119.   delay(250);
  120.  
  121.   digitalWrite(11, LOW);
  122.   digitalWrite(10, HIGH);
  123.  
  124.   delay(250);
  125.  
  126.  
  127.   digitalWrite(13, LOW);    //LED UIT
  128.   digitalWrite(12, HIGH);  //LED AAN
  129.   digitalWrite(11, HIGH);
  130.   digitalWrite(10, LOW);
  131.  
  132.   delay(250);
  133.  
  134.   digitalWrite(11, LOW);
  135.   digitalWrite(10, HIGH);
  136.  
  137.   delay(250);
  138.  
  139. }
  140.  
  141. void activateLED()
  142. {
  143.   digitalWrite(powerLED, HIGH);
  144.   digitalWrite(actLED, LOW);
  145. }
  146.  
  147.  
  148.  
  149. void stopServo()
  150. {
  151.   servoLeft.writeMicroseconds(1500);
  152.   servoRight.writeMicroseconds(1500);
  153. }
  154.  
  155. void forward()
  156. {
  157.   servoLeft.writeMicroseconds(1700);
  158.   servoRight.writeMicroseconds(1300);  
  159. }
  160.  
  161. void backward()
  162. {
  163.   servoLeft.writeMicroseconds(1300);
  164.   servoRight.writeMicroseconds(1700);  
  165. }
Advertisement
Add Comment
Please, Sign In to add comment