Advertisement
pleasedontcode

Scanner rev_126

Nov 11th, 2023
64
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-11 15:23:01
  15.     - Source Code generated by: AlexWind
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <SoftwareSerial.h>
  21. #include <EasyButton.h>
  22. #include <DS18B20.h>
  23.  
  24. /****** SYSTEM REQUIREMENT 1 *****/
  25. /* Every time the button is pressed 3 times, read the sensor and provide information on the serial monitor. */
  26.  
  27. /****** SYSTEM REQUIREMENT 2 *****/
  28. /* If 'H' is received before the character 'o' and then the character 'k', switch off the LED. */
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t pulsante_PushButton_PIN_D3 = 3;
  36. const uint8_t sensor_DS18B20_DQ_PIN_D5 = 5;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t led_LED_PIN_D2 = 2;
  40.  
  41. /***** DEFINITION OF Software Serial *****/
  42. const uint8_t myBluetooth_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
  43. const uint8_t myBluetooth_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
  44. SoftwareSerial myBluetooth_HC05_mySerial(myBluetooth_HC05_mySerial_PIN_SERIAL_RX_A1, myBluetooth_HC05_mySerial_PIN_SERIAL_TX_A0);
  45.  
  46. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  47. EasyButton pulsante_PushButton(pulsante_PushButton_PIN_D3);
  48. DS18B20 sensor_DS18B20(sensor_DS18B20_DQ_PIN_D5);
  49.  
  50. // Variables to count button presses
  51. int buttonPressCount = 0;
  52.  
  53. void setup(void)
  54. {
  55.   // put your setup code here, to run once:
  56.  
  57.   pinMode(pulsante_PushButton_PIN_D3, INPUT_PULLUP);
  58.   pinMode(sensor_DS18B20_DQ_PIN_D5, INPUT);
  59.  
  60.   pinMode(led_LED_PIN_D2, OUTPUT);
  61.  
  62.   myBluetooth_HC05_mySerial.begin(9600);
  63.  
  64.   pulsante_PushButton.begin();
  65. }
  66.  
  67. void loop(void)
  68. {
  69.   // put your main code here, to run repeatedly:
  70.  
  71.   pulsante_PushButton.read();
  72.  
  73.   /****** SUBSYSTEM REQUIREMENT 1 *****/
  74.   if (pulsante_PushButton.wasPressed())
  75.   {
  76.     // Increment the button press count
  77.     buttonPressCount++;
  78.  
  79.     // Check if the button has been pressed 3 times
  80.     if (buttonPressCount == 3)
  81.     {
  82.       // Read sensor and provide information on serial monitor
  83.       float temperature = sensor_DS18B20.getTempC();
  84.       Serial.print("Temperature: ");
  85.       Serial.println(temperature);
  86.  
  87.       // Reset the button press count
  88.       buttonPressCount = 0;
  89.     }
  90.   }
  91.  
  92.   /****** SUBSYSTEM REQUIREMENT 2 *****/
  93.   if (myBluetooth_HC05_mySerial.available())
  94.   {
  95.     char c = myBluetooth_HC05_mySerial.read();
  96.  
  97.     if (c == 'H')
  98.     {
  99.       // Check if 'o' and 'k' are received after 'H'
  100.       if (myBluetooth_HC05_mySerial.available() && myBluetooth_HC05_mySerial.read() == 'o')
  101.       {
  102.         if (myBluetooth_HC05_mySerial.available() && myBluetooth_HC05_mySerial.read() == 'k')
  103.         {
  104.           // Switch off the LED
  105.           digitalWrite(led_LED_PIN_D2, LOW);
  106.         }
  107.       }
  108.     }
  109.   }
  110. }
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement