Advertisement
mem1889

sketch_3_4_ardu

Apr 11th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. //***************************************************************************************
  2. // EE40LX
  3. // Sketch 3.4 adapted to Arduino
  4. //
  5. //***************************************************************************************
  6.  
  7. int BUZZER = 8; // set BUZZER as P1.3 alias
  8. int val;
  9.  
  10. void setup()
  11. {
  12. // set BUZZER as output pin
  13. pinMode(BUZZER, OUTPUT);
  14.  
  15. // random analog voltage noise at analog pin 0 will seed
  16. // the random number generator differently every time it runs
  17. // otherwise, we will hear the same pseudo-random sequence
  18. // every time we run the program (which is at times useful)
  19. randomSeed(analogRead(0));
  20. }
  21.  
  22. void loop()
  23. {
  24. val = random(1,100); // create a random number from 1 to 100 using the Energia RNG
  25. if (val > 50) // if val is greater than 50, output an 800 Hz wave
  26. tone(BUZZER, 800, 50); // otherwise, do nothing for the same period
  27. else
  28. delay(50);
  29. }
  30. /* End of code */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement