Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: "Button Listener" - Source Code compiled for: Arduino Uno - Source Code created on: 2024-03-20 09:19:38 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* uando una persona preme il piccolo pulsante, */ /* l'Arduino dovrebbe rilevare la pressione e */ /* iniziare a sentire l’ambiente circostante per 5 */ /* secondi (tempo nel quale tutte e tre le lampadine */ /* LED si accendono e in cui l */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include
// https://github.com/evert-arias/EasyButton #include
// https://github.com/ErickSimoes/Ultrasonic /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void startListening(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t startButton_PushButton_PIN_D2 = 2; const uint8_t sensor_HC_SR04_Echo_PIN_D4 = 4; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t sensor_HC_SR04_Trigger_PIN_D3 = 3; const uint8_t LED_LED_PIN_D5 = 5; /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ /***** used to store raw data *****/ bool sensor_HC_SR04_Trigger_PIN_D3_rawData = 0; bool LED_LED_PIN_D5_rawData = 0; /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/ /***** used to store data after characteristic curve transformation *****/ float sensor_HC_SR04_Trigger_PIN_D3_phyData = 0.0; float LED_LED_PIN_D5_phyData = 0.0; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ EasyButton startButton(startButton_PushButton_PIN_D2); Ultrasonic sensor(sensor_HC_SR04_Trigger_PIN_D3, sensor_HC_SR04_Echo_PIN_D4); bool isListening = false; unsigned long listeningStartTime = 0; const unsigned long LISTENING_DURATION = 5000; void setup(void) { // put your setup code here, to run once: pinMode(startButton_PushButton_PIN_D2, INPUT_PULLUP); pinMode(sensor_HC_SR04_Echo_PIN_D4, INPUT); pinMode(sensor_HC_SR04_Trigger_PIN_D3, OUTPUT); pinMode(LED_LED_PIN_D5, OUTPUT); // Initialize the start button startButton.begin(); // Add the callback function to be called when the start button is pressed startButton.onPressed(startListening); } void loop(void) { // put your main code here, to run repeatedly: startButton.read(); // Continuously read the status of the start button if (isListening) { unsigned long currentTime = millis(); if (currentTime - listeningStartTime >= LISTENING_DURATION) { isListening = false; // Turn off all LEDs LED_LED_PIN_D5_rawData = LOW; } else { // Code to be executed while listening // You can add your own code here LED_LED_PIN_D5_rawData = HIGH; } } updateOutputs(); // Refresh output data } void updateOutputs() { digitalWrite(sensor_HC_SR04_Trigger_PIN_D3, sensor_HC_SR04_Trigger_PIN_D3_rawData); digitalWrite(LED_LED_PIN_D5, LED_LED_PIN_D5_rawData); } void startListening() { // Code to be executed when the start button is pressed // You can add your own code here isListening = true; listeningStartTime = millis(); // Turn on all LEDs LED_LED_PIN_D5_rawData = HIGH; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)