Advertisement
pleasedontcode

Scanner rev_125

Nov 7th, 2023
72
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: Scanner
  13.     - Source Code compiled for: Arduino Pro Mini 3.3V
  14.     - Source Code created on: 2023-11-07 14:59:33
  15.     - Source Code generated by: AlexWind
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <EasyButton.h>
  21. #include <DS18B20.h>
  22.  
  23. /****** SYSTEM REQUIREMENT 1 *****/
  24. /* every time the button is pressed 3 times, so read */
  25. /* sensor and provide information on serial monitor. */
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t pulsante_PushButton_PIN_D3 = 3;
  33. const uint8_t sensor_DS18B20_DQ_PIN_D5 = 5;
  34.  
  35. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  36. const uint8_t led_LED_PIN_D2 = 2;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. EasyButton button(pulsante_PushButton_PIN_D3);
  40. DS18B20 sensor(sensor_DS18B20_DQ_PIN_D5);
  41.  
  42. // Counter for button presses
  43. uint8_t buttonPressCount = 0;
  44.  
  45. void setup(void)
  46. {
  47.   // put your setup code here, to run once:
  48.   pinMode(pulsante_PushButton_PIN_D3, INPUT_PULLUP);
  49.   pinMode(sensor_DS18B20_DQ_PIN_D5, INPUT);
  50.   pinMode(led_LED_PIN_D2, OUTPUT);
  51.  
  52.   // Initialize the button
  53.   button.begin();
  54.  
  55.   // Start serial communication
  56.   Serial.begin(9600);
  57. }
  58.  
  59. void loop(void)
  60. {
  61.   // put your main code here, to run repeatedly:
  62.   button.read();
  63.  
  64.   // Check if the button was pressed
  65.   if (button.wasPressed())
  66.   {
  67.     // Increment the button press count
  68.     buttonPressCount++;
  69.  
  70.     // Check if the button was pressed 3 times
  71.     if (buttonPressCount == 3)
  72.     {
  73.       // Read the temperature from the sensor
  74.       float temperature = sensor.getTempC();
  75.  
  76.       // Print the temperature on the serial monitor
  77.       Serial.print("Temperature: ");
  78.       Serial.print(temperature);
  79.       Serial.println(" °C");
  80.  
  81.       // Reset the button press count
  82.       buttonPressCount = 0;
  83.     }
  84.   }
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement