Mattie

Untitled

Sep 28th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.54 KB | None | 0 0
  1. //mattie's test troep
  2. #include "pitches.h"
  3. #include <Servo.h>          // Include servo library
  4.  
  5. const int baudRate = 9600;  //Default bauldRate
  6. // notes in the melody:
  7. //int melody[] = { NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};
  8. int melody[] = { NOTE_C4, NOTE_G3};
  9. // note durations: 4 = quarter note, 8 = eighth note, etc.:
  10. //int noteDurations[] = { 4, 8, 8, 4,4,4,4,4 };
  11. int noteDurations[] = { 4, 8 };
  12. //servo troep
  13. Servo servoLeft;            // Declare left servo
  14. Servo servoRight;
  15.  
  16.  
  17. void setup()
  18. {
  19. //  Serial.begin(baudRate);
  20. //  Serial.println("ohaaaai");
  21.   pinMode(13, OUTPUT);
  22.   pinMode(12, OUTPUT);
  23.   pinMode(11, OUTPUT);
  24.   pinMode(10, OUTPUT);
  25.   ledON();
  26.   muziek();
  27.  
  28.   servoLeft.attach(2);
  29.   servoRight.attach(4);
  30.   stopServo();
  31.  
  32.   knipperLed();
  33. }
  34.  
  35. void stopServo()
  36. {
  37.   servoLeft.writeMicroseconds(1500);
  38.   servoRight.writeMicroseconds(1500);
  39. }
  40.  
  41. void forward()
  42. {
  43.     servoLeft.writeMicroseconds(1700);
  44.     servoRight.writeMicroseconds(1300);  
  45. }
  46.  
  47. void backward()
  48. {
  49.     servoLeft.writeMicroseconds(1300);
  50.     servoRight.writeMicroseconds(1700);  
  51. }
  52.  
  53.  
  54. void muziek()
  55. {
  56.       // iterate over the notes of the melody:
  57.   for (int thisNote = 0; thisNote < 2; thisNote++) {
  58.  
  59.     // to calculate the note duration, take one second
  60.     // divided by the note type.
  61.     //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
  62.     int noteDuration = 1000/noteDurations[thisNote];
  63.     tone(8, melody[thisNote],noteDuration);
  64.  
  65.     // to distinguish the notes, set a minimum time between them.
  66.     // the note's duration + 30% seems to work well:
  67.     int pauseBetweenNotes = noteDuration * 1.30;
  68.     delay(pauseBetweenNotes);
  69.     // stop the tone playing:
  70.     noTone(8);
  71.   }
  72. }
  73.  
  74. void knipperLed()
  75. {  
  76.  
  77.    // Serial.println("dit is een test");
  78.  // delay(1000);  
  79.  
  80.  digitalWrite(13, HIGH);   //LED AAN
  81.  digitalWrite(12, LOW);   //LED UIT
  82.  digitalWrite(11, HIGH);
  83.  digitalWrite(10, LOW);
  84.  
  85.  delay(250);
  86.  
  87.  digitalWrite(11, LOW);
  88.  digitalWrite(10, HIGH);
  89.  
  90.  delay(250);
  91.  
  92.  
  93.  digitalWrite(13, LOW);    //LED UIT
  94.  digitalWrite(12, HIGH);  //LED AAN
  95.  digitalWrite(11, HIGH);
  96.  digitalWrite(10, LOW);
  97.  
  98.  delay(250);
  99.  
  100.  digitalWrite(11, LOW);
  101.  digitalWrite(10, HIGH);
  102.  
  103.  delay(250);
  104.  
  105. }
  106.  
  107. void ledON()
  108. {
  109.   digitalWrite(13, HIGH);
  110.   digitalWrite(12, HIGH);
  111.   digitalWrite(11, HIGH);
  112.   digitalWrite(10, HIGH);
  113. }
  114.  
  115. void loop()
  116. {
  117.   knipperLed();
  118.   forward();
  119.   delay(5000);
  120.   stopServo();
  121.   delay(1000);
  122.   backward();
  123.   delay(5000);
  124.   stopServo();
  125.   delay(1000);
  126. }
Advertisement
Add Comment
Please, Sign In to add comment