CCCPaste

beaconReaders rev_26

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: beaconReaders
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2023-09-13 12:09:21
	- Source Code generated by: Francesco Alessandro

********* Pleasedontcode.com **********/
/****** DEFINITION OF LIBRARIES *****/
#include 

/****** SYSTEM REQUIREMENT 1 *****/
/* HC05 bluetooth device shall be connected to */
/* Arduino and will communicate with 3 specific */
/* beacon devices recognized with some unique MAC */
/* addresses. */
/****** SYSTEM REQUIREMENT 2 *****/
/* if one of three beacons is closed to Arduino with */
/* and RSSI > -50 dBm, so activate the corresponding */
/* led. Otherwise if RSSI < -70dBm, so switch off the */
/* corresponding LED. */

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void checkBeaconRSSI(int beaconNumber, int rssi);

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t Led_beacon1_LED_PIN_D2 = 2;
const uint8_t Led_beacon2_LED_PIN_D3 = 3;

void setup(void)
{
    // put your setup code here, to run once:
    pinMode(Led_beacon1_LED_PIN_D2, OUTPUT);
    pinMode(Led_beacon2_LED_PIN_D3, OUTPUT);
}

void loop(void)
{
    // put your main code here, to run repeatedly:
    checkBeaconRSSI(1, -55); // Example RSSI value for beacon 1
    checkBeaconRSSI(2, -75); // Example RSSI value for beacon 2
}

void checkBeaconRSSI(int beaconNumber, int rssi)
{
    // Check if RSSI is greater than -50 dBm
    if (rssi > -50)
    {
        // Activate the corresponding LED
        if (beaconNumber == 1)
        {
            digitalWrite(Led_beacon1_LED_PIN_D2, HIGH);
        }
        else if (beaconNumber == 2)
        {
            digitalWrite(Led_beacon2_LED_PIN_D3, HIGH);
        }
    }
    // Check if RSSI is less than -70 dBm
    else if (rssi < -70)
    {
        // Switch off the corresponding LED
        if (beaconNumber == 1)
        {
            digitalWrite(Led_beacon1_LED_PIN_D2, LOW);
        }
        else if (beaconNumber == 2)
        {
            digitalWrite(Led_beacon2_LED_PIN_D3, LOW);
        }
    }
}