Advertisement
pleasedontcode

Scanner rev_127

Nov 11th, 2023
66
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:32:42
  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, so read */
  26. /* sensor and provide information on serial monitor. */
  27. /****** SYSTEM REQUIREMENT 2 *****/
  28. /* if HC05 read before the character 'o' and then the */
  29. /* character 'k', so switch off the led. */
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t pulsante_PushButton_PIN_D3 = 3;
  37. const uint8_t sensor_DS18B20_DQ_PIN_D5 = 5;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t led_LED_PIN_D2 = 2;
  41.  
  42. /***** DEFINITION OF Software Serial *****/
  43. const uint8_t myBluetooth_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
  44. const uint8_t myBluetooth_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
  45. SoftwareSerial myBluetooth_HC05_mySerial(myBluetooth_HC05_mySerial_PIN_SERIAL_RX_A1, myBluetooth_HC05_mySerial_PIN_SERIAL_TX_A0);
  46.  
  47. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  48. EasyButton button(pulsante_PushButton_PIN_D3);
  49. DS18B20 sensor(sensor_DS18B20_DQ_PIN_D5);
  50.  
  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.   button.begin();
  65. }
  66.  
  67. void loop(void)
  68. {
  69.   // put your main code here, to run repeatedly:
  70.  
  71.   button.read();
  72.  
  73.   if (button.wasPressed()) {
  74.     buttonPressCount++;
  75.  
  76.     if (buttonPressCount == 3) {
  77.       // Read the sensor and provide information on serial monitor
  78.       float temperature = sensor.getTempC();
  79.       Serial.print("Temperature: ");
  80.       Serial.print(temperature);
  81.       Serial.println(" °C");
  82.  
  83.       buttonPressCount = 0; // Reset button press count
  84.     }
  85.   }
  86.  
  87.   if (myBluetooth_HC05_mySerial.available()) {
  88.     char c = myBluetooth_HC05_mySerial.read();
  89.     if (c == 'o') {
  90.       if (myBluetooth_HC05_mySerial.available()) {
  91.         char c2 = myBluetooth_HC05_mySerial.read();
  92.         if (c2 == 'k') {
  93.           digitalWrite(led_LED_PIN_D2, LOW);
  94.         }
  95.       }
  96.     }
  97.   }
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement