Speaker.java 757 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package boebot;
  2. import stamp.core.*;
  3. public class Speaker
  4. {
  5. private Freqout speaker;
  6. private int pinNumber;
  7. public Speaker (int pinNumberInput)
  8. {
  9. pinNumber = pinNumberInput;
  10. }
  11. public void playSound(int frequency, int duration)
  12. {
  13. speaker = new Freqout(CPU.pins[pinNumber]);
  14. for (int i = 0; i <= duration; i ++)
  15. {
  16. speaker.freqout((frequency / 10), 1);
  17. }
  18. }
  19. public static void main()
  20. {
  21. Speaker test = new Speaker(3);
  22. test.playSound(1000, 100);
  23. test.playSound(7000, 200);
  24. test.playSound(9000, 100);
  25. test.playSound(1000, 100);
  26. test.playSound(10000, 200);
  27. test.playSound(3000, 100);
  28. test.playSound(20000, 100);
  29. test.playSound(15000, 200);
  30. test.playSound(12000, 100);
  31. }
  32. }