Advertisement
pleasedontcode

Button Buzzer rev_01

Jan 25th, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Button Buzzer
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-25 09:19:25
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* buzzer play */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include <EasyButton.h>
  26. #include <toneAC.h> // Library for playing tones with the buzzer
  27.  
  28. /****** SYSTEM REQUIREMENTS *****/
  29. /****** SYSTEM REQUIREMENT 1 *****/
  30.     /* buzzer play */
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t buzzer_PushButton_PIN_D2 = 2;
  38. const uint8_t buzzer_PushButton_PIN_D3 = 3;
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  41. EasyButton button1(buzzer_PushButton_PIN_D2);
  42. EasyButton button2(buzzer_PushButton_PIN_D3);
  43.  
  44. void setup(void)
  45. {
  46.   // put your setup code here, to run once:
  47.   pinMode(buzzer_PushButton_PIN_D2, INPUT_PULLUP);
  48.   pinMode(buzzer_PushButton_PIN_D3, INPUT_PULLUP);
  49.  
  50.   button1.begin();
  51.   button2.begin();
  52. }
  53.  
  54. void loop(void)
  55. {
  56.   // put your main code here, to run repeatedly:
  57.   button1.read();
  58.   button2.read();
  59.  
  60.   // Add your code to react to button presses here
  61.   if (button1.isPressed()) {
  62.     toneAC(1000); // Play a 1000Hz tone with the buzzer
  63.   } else {
  64.     noToneAC(); // Stop playing the tone
  65.   }
  66.  
  67.   if (button2.isPressed()) {
  68.     toneAC(2000); // Play a 2000Hz tone with the buzzer
  69.   } else {
  70.     noToneAC(); // Stop playing the tone
  71.   }
  72. }
  73.  
  74. /****** END SYSTEM REQUIREMENTS *****/
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement