Advertisement
pleasedontcode

beaconReaders rev_26

Sep 13th, 2023
98
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: beaconReaders
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-09-13 12:09:21
  15.     - Source Code generated by: Francesco Alessandro
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20.  
  21. /****** SYSTEM REQUIREMENT 1 *****/
  22. /* HC05 bluetooth device shall be connected to */
  23. /* Arduino and will communicate with 3 specific */
  24. /* beacon devices recognized with some unique MAC */
  25. /* addresses. */
  26. /****** SYSTEM REQUIREMENT 2 *****/
  27. /* if one of three beacons is closed to Arduino with */
  28. /* and RSSI > -50 dBm, so activate the corresponding */
  29. /* led. Otherwise if RSSI < -70dBm, so switch off the */
  30. /* corresponding LED. */
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void checkBeaconRSSI(int beaconNumber, int rssi);
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t Led_beacon1_LED_PIN_D2 = 2;
  39. const uint8_t Led_beacon2_LED_PIN_D3 = 3;
  40.  
  41. void setup(void)
  42. {
  43.     // put your setup code here, to run once:
  44.     pinMode(Led_beacon1_LED_PIN_D2, OUTPUT);
  45.     pinMode(Led_beacon2_LED_PIN_D3, OUTPUT);
  46. }
  47.  
  48. void loop(void)
  49. {
  50.     // put your main code here, to run repeatedly:
  51.     checkBeaconRSSI(1, -55); // Example RSSI value for beacon 1
  52.     checkBeaconRSSI(2, -75); // Example RSSI value for beacon 2
  53. }
  54.  
  55. void checkBeaconRSSI(int beaconNumber, int rssi)
  56. {
  57.     // Check if RSSI is greater than -50 dBm
  58.     if (rssi > -50)
  59.     {
  60.         // Activate the corresponding LED
  61.         if (beaconNumber == 1)
  62.         {
  63.             digitalWrite(Led_beacon1_LED_PIN_D2, HIGH);
  64.         }
  65.         else if (beaconNumber == 2)
  66.         {
  67.             digitalWrite(Led_beacon2_LED_PIN_D3, HIGH);
  68.         }
  69.     }
  70.     // Check if RSSI is less than -70 dBm
  71.     else if (rssi < -70)
  72.     {
  73.         // Switch off the corresponding LED
  74.         if (beaconNumber == 1)
  75.         {
  76.             digitalWrite(Led_beacon1_LED_PIN_D2, LOW);
  77.         }
  78.         else if (beaconNumber == 2)
  79.         {
  80.             digitalWrite(Led_beacon2_LED_PIN_D3, LOW);
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement