#include // Electrical erasable programable ROM /////////////////////////////// MOUSE #include // Wireles module use SPI for communication with ATMEGA32U4 #include #include // Libraries for Wireless module RF24 radio(9, 10); // CE, CSN // Object for radio // @Param 9, 10 -> two pins CE and CSN, found a tutorial online // Used for pipe between dongle and tracking device const byte address[6] = "00001"; // stuct for holding data sent frm tracking device to dongle device // @Param id if two near dongles in the same gym // @Param d == buff (data) struct dataStruct { int id; char d[30]; } M_d; // PIN 3 (Button) #define button 3 unsigned long mill1 = 0; void setup() { SerialUSB.begin(115200); SerialUSB.println("salut"); ////////////////////////////////////SERIAL radio.begin(); radio.openReadingPipe(0, address); radio.setPALevel(RF24_PA_MIN); radio.startListening(); /////////////////////////////////////NRF pinMode(button, INPUT_PULLUP); } // Reads the ID // 1 byte id uint8_t id = readIntFromEEPROM(10); void loop() { if (radio.available()) { radio.read( & M_d, sizeof(M_d)); if (id == M_d.id) { SerialUSB.print(M_d.d); SerialUSB.print("\n"); } } if (!digitalRead(button)) { // If was pressed more than 5 sec, then pair if (millis() - mill1 > 5000) { pair(); } } else { mill1 = millis(); } } void pair() { bool p = true; Serial.print("Pairing\n"); while (p) { if (radio.available()) { radio.read( & M_d, sizeof(M_d)); if (strcmp(M_d.d, "pairing") == 0) { writeIntIntoEEPROM(10, M_d.id); SerialUSB.println(readIntFromEEPROM(10)); Serial.print("Paired\n"); delay(1000); p = false; id = readIntFromEEPROM(10); } } } } void writeIntIntoEEPROM(int address, int number) { EEPROM.write(address, number); } int readIntFromEEPROM(int address) { return EEPROM.read(address); }