Advertisement
pleasedontcode

Button Monitor rev_04

Jan 24th, 2024
104
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 Monitor
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-24 22:31:20
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if button is pressed so print hello on serial */
  21.     /* monitor */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  26. #include <DS18B20.h>    //https://github.com/matmunk/DS18B20
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t button_PushButton_PIN_D2 = 2;
  34. const uint8_t temp_DS18B20_DQ_PIN_D3 = 3;
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37.  
  38. EasyButton button(button_PushButton_PIN_D2);
  39. DS18B20 sensor(temp_DS18B20_DQ_PIN_D3);
  40.  
  41. void setup(void)
  42. {
  43.   // put your setup code here, to run once:
  44.   pinMode(button_PushButton_PIN_D2, INPUT_PULLUP);
  45.   pinMode(temp_DS18B20_DQ_PIN_D3, INPUT);
  46.  
  47.   // Initialize the button
  48.   button.begin();
  49.  
  50.   // Initialize the DS18B20 sensor
  51.   uint8_t address[8];
  52.   sensor.getAddress(address);
  53.   sensor.select(address);
  54.  
  55.   // Start the serial communication
  56.   Serial.begin(9600);
  57. }
  58.  
  59. void loop(void)
  60. {
  61.   // put your main code here, to run repeatedly:
  62.  
  63.   // Read the button state
  64.   button.read();
  65.  
  66.   // Check if the button is pressed
  67.   if (button.isPressed())
  68.   {
  69.     // Print "Hello" to the serial monitor
  70.     Serial.println("Hello");
  71.   }
  72.  
  73.   // Read the temperature from the DS18B20 sensor
  74.   float temperature = sensor.getTempC();
  75.  
  76.   // Print the temperature to the serial monitor
  77.   Serial.print("Temperature: ");
  78.   Serial.print(temperature);
  79.   Serial.println(" °C");
  80.  
  81.   delay(1000);
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement