Advertisement
j0h

arduino Tones Analog write to buzzer pin

j0h
Aug 12th, 2019
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. /*
  2. messing with tone, and conflicting pins.
  3. */
  4. int buzz = 8;
  5. int p3 = 3;
  6. int p11 =11;
  7.  
  8. int analogPin = A0;
  9. int val =0;
  10. // the setup routine runs once when you press reset:
  11. void setup() {
  12.   // initialize the digital pin as an output.
  13.   pinMode(buzz, OUTPUT);
  14.   pinMode(p3,OUTPUT);
  15.   pinMode(p11, OUTPUT);
  16.  
  17. }
  18.  
  19. // the loop routine runs over and over again forever:
  20. void loop() {
  21. tone(buzz, 0, 500);              // wait for a second
  22.   val = analogRead(analogPin);
  23. analogWrite(buzz, val );
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement