Advertisement
pleasedontcode

friday rev_01

Nov 16th, 2023
76
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: friday
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-11-16 13:35:00
  15.     - Source Code generated by: IRJM
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <SoftwareSerial.h>
  21.  
  22. /****** SYSTEM REQUIREMENT 1 *****/
  23.     /* Turn off Led when HC05 is below 20cm */
  24.  
  25. /****** FUNCTION PROTOTYPES *****/
  26. void setup(void);
  27. void loop(void);
  28.  
  29. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  30. const uint8_t LED_PIN_D2 = 2;
  31.  
  32. /***** DEFINITION OF Software Serial *****/
  33. const uint8_t HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
  34. const uint8_t HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
  35. SoftwareSerial HC05_mySerial(HC05_mySerial_PIN_SERIAL_RX_A1, HC05_mySerial_PIN_SERIAL_TX_A0);
  36.  
  37. void setup(void)
  38. {
  39.     // put your setup code here, to run once:
  40.  
  41.     pinMode(LED_PIN_D2, OUTPUT);
  42.  
  43.     HC05_mySerial.begin(9600);
  44.  
  45. }
  46.  
  47.  
  48. void loop(void)
  49. {
  50.     // put your main code here, to run repeatedly:
  51.  
  52.     // Read the distance from HC05
  53.     int distance = HC05_mySerial.read();
  54.  
  55.     // Check if the distance is below 20cm
  56.     if (distance < 20)
  57.     {
  58.         // Turn off the LED
  59.         digitalWrite(LED_PIN_D2, LOW);
  60.     }
  61.     else
  62.     {
  63.         // Turn on the LED
  64.         digitalWrite(LED_PIN_D2, HIGH);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement