SHARE
TWEET

gay

a guest Jan 22nd, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * Basketball
  3. *
  4. * Score a goal!
  5. *
  6. * In this game, players will try to bounce a ping pong ball
  7. * into a cup. Make five points to win. The score is tracked
  8. * using a LightSensor.
  9. *
  10. * (c) 2013-2016 Arduino LLC.
  11. */
  12.  
  13. #include <EducationShield.h>
  14. #include "pitches.h"
  15. /*
  16. An array of pin numbers to which LEDs are attached
  17. the defaults are 2 to 6 but you can choose any of the digital pins
  18. */
  19. int ledPins[] = {2, 3, 4, 5, 6};
  20. int pinCount = 5;
  21. VUMeter vuMeter;
  22.  
  23. Melody piezo = Melody(8); // the piezo connected to digital pin 8
  24. LightSensor sensor = LightSensor(A1); //the LightSensor connected to analog pin 1
  25.  
  26. int score = 0;
  27.  
  28. void setup(){
  29.   //if your are using other pins than 2 to 6 you need to configure that here
  30.   vuMeter.config(pinCount, ledPins);
  31.   vuMeter.begin(); //does the same as pinMode, LEDs are outputs
  32.  
  33.   sensor.config(800, 600); //first run LightSensortest example to see what values you need to put here
  34. }
  35.  
  36. void loop(){
  37.   //if the LightSensor is covered the score increases with 1
  38.   //and a sounds is played
  39.     sensor.pressed();
  40.     score++;
  41.     vuMeter.fill(score); //Turn on as many LEDs as the score
  42.  
  43.     int melody[] = { NOTE_GS4, NOTE_C5};
  44.     int noteDurations[] = { 8, 8};
  45.     int numberOfNotes = 2;
  46.     piezo.play(numberOfNotes, melody, noteDurations, 1);
  47.  
  48.     delay(50);
  49.  
  50.   if(score>=pinCount) startOver(); //If the score equals the amount of LEDs you start over
  51. }
  52.  
  53.  
  54. void startOver(){
  55.   score=0; //reset the score
  56.  
  57.   int melody[] = { NOTE_C5, NOTE_G4,NOTE_G4, NOTE_A4, NOTE_G4, 0, NOTE_B4, NOTE_C5};
  58.   int noteDurations[] = { 4, 8, 8, 4,4,4,4,4 };
  59.   int numberOfNotes = 8;
  60.   piezo.play(numberOfNotes, melody, noteDurations, 1);
  61.  
  62.   vuMeter.blinkAll(50,10);
  63.  
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top