Advertisement
pleasedontcode

"Trigger Action" rev_03

Nov 12th, 2024
55
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: "Trigger Action"
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-11-13 05:56:50
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* the robot I talked with. so all I need is to talk */
  21.     /* with the ai from the microphone and listen to the */
  22.     /* answer from the speaker so I have > breadboard and */
  23.     /* esp32 and wire and microphone and speaker and */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t speaker_PushButton_PIN_D4 = 4;
  37. const uint8_t microphone_PIN_A0 = 34; // Analog pin for microphone input
  38. const uint8_t speaker_PIN_D5 = 5;      // Digital pin for speaker output
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  41. EasyButton button(speaker_PushButton_PIN_D4); // Create an instance of EasyButton
  42.  
  43. void setup(void)
  44. {
  45.     // put your setup code here, to run once:
  46.     pinMode(speaker_PushButton_PIN_D4, INPUT_PULLUP);
  47.     pinMode(microphone_PIN_A0, INPUT); // Set microphone pin as input
  48.     pinMode(speaker_PIN_D5, OUTPUT);    // Set speaker pin as output
  49.  
  50.     button.begin(); // Initialize the EasyButton instance
  51. }
  52.  
  53. void loop(void)
  54. {
  55.     // put your main code here, to run repeatedly:
  56.     button.update(); // Update the button state
  57.  
  58.     if (button.isPressed()) {
  59.         // Code to handle button press, e.g., read from microphone and play response
  60.         int micValue = analogRead(microphone_PIN_A0); // Read microphone input
  61.         // Process micValue and generate response (not implemented here)
  62.        
  63.         // Example: Output a sound to the speaker (placeholder for actual sound generation)
  64.         digitalWrite(speaker_PIN_D5, HIGH); // Turn on speaker
  65.         delay(100);                          // Play sound for 100ms
  66.         digitalWrite(speaker_PIN_D5, LOW);  // Turn off speaker
  67.     }
  68. }
  69.  
  70. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement