 }
 
 // Serial program/verify operation
-int sendOp(int cmd, int payload) {
+int sendOp(int cmd, int payload)
+{
   bool valid = true;
   bool isread = false;
 
   // Check if command is valid and if it contains a read
-  switch (cmd) {
-    case B0000:
-      break;
-    case B0010:
-      isread = true;
-      break;
-    case B1000:
-      isread = true;
-      break;
-    case B1001:
-      isread = true;
-      break;
-    case B1010:
-      isread = true;
-      break;
-    case B1011:
-      isread = true;
-      break;
-    case B1100:
-      break;
-    case B1101:
-      break;
-    case B1110:
-      break;
-    case B1111:
-      break;
-    default:
-      valid = false;
+  switch (cmd)
+  {
+  case B0000:
+    break;
+  case B0010:
+    isread = true;
+    break;
+  case B1000:
+    isread = true;
+    break;
+  case B1001:
+    isread = true;
+    break;
+  case B1010:
+    isread = true;
+    break;
+  case B1011:
+    isread = true;
+    break;
+  case B1100:
+    break;
+  case B1101:
+    break;
+  case B1110:
+    break;
+  case B1111:
+    break;
+  default:
+    valid = false;
   }
 
   // Check if data payload is the right size
-  if ((isread && (payload > 255)) || (!isread && (payload > 65535))) {
+  if ((isread && (payload > 255)) || (!isread && (payload > 65535)))
+  {
     SerialUSB.write("Invalid number of payload bits\r\n");
     return false;
-  } 
-  
-  if (valid) {
+  }
+
+  if (valid)
+  {
     // Send command bits to the RN2483
-    for (int n = 0; n < 4; n++) {
+    for (int n = 0; n < 4; n++)
+    {
       //Lower PGC and write bit to PGD
       digitalWrite(PGC, LOW);
       digitalWrite(PGD, bitRead(cmd, n));
       delayMicroseconds(1);
-      
+
       //Raise PGC to send bit
       digitalWrite(PGC, HIGH);
       delayMicroseconds(1);

      // Wait atleast 40ns (P5A)
      delayMicroseconds(1);
      SerialUSB.write("Sent 4 command bits and 8 data payload bits\r\nResponse: ");
      SerialUSB.print(String(response, HEX)+"\r\n");
      
      return response;
    } else {
      // Write all 16 bits from the data payload      
      for (int n = 0; n < 16; n++) {
        //Lower PGC and write bit to PGD
        digitalWrite(PGC, LOW);
        digitalWrite(PGD, bitRead(payload, n));
        delayMicroseconds(1);
        
        //Raise PGC to send bit
        digitalWrite(PGC, HIGH);
        delayMicroseconds(1);
      }
      digitalWrite(PGC, LOW);
      
      // Wait atleast 40ns (P5A)
      delayMicroseconds(1);
      SerialUSB.write("Sent 4 command bits and 16 data payload bits\r\n");

      return true;
    }
  } else {
    SerialUSB.write("Command not valid\r\n");
    return false;
  }
}

void loop() {
  if(SerialUSB.available()){
    char ch = SerialUSB.read();
    switch(ch){
      case '1':
        SerialUSB.write("Read address 3FFFFE\r\n");
        sendOp(B0000, 0x0E3F);
        sendOp(B0000, 0x6EF8);
        sendOp(B0000, 0x0EFF);
        sendOp(B0000, 0x6EF7);
        sendOp(B0000, 0x0EFE);
        sendOp(B0000, 0x6EF6);
        sendOp(B1001, 0x0000);
        break;
      case '2':
        SerialUSB.write("Read address 3FFFFF\r\n");
        sendOp(B0000, 0x0E3F);
        sendOp(B0000, 0x6EF8);
        sendOp(B0000, 0x0EFF);
        sendOp(B0000, 0x6EF7);
        sendOp(B0000, 0x0EFF);
        sendOp(B0000, 0x6EF6);
        sendOp(B1001, 0x0000);
        break;
      case '3':
        exitLVP();
        enterLVP();
        break;
      case '4':
        exitLVP();
        break;
      case '5':
        break;
      case '\r':
        break;
      case '\n':
        break;
      default:
        SerialUSB.write("Invalid input\r\n");
    }
  }
}


    // Wait atleast 40ns (P5)
    delayMicroseconds(1);

    if (isread)
    {
      // Write 8 payload bits to RN2483
      for (int n = 0; n < 8; n++)
      {
        //Lower PGC and write bit to PGD
        digitalWrite(PGC, LOW);
        digitalWrite(PGD, bitRead(payload, n));
        delayMicroseconds(1);

        //Raise PGC to send bit
        digitalWrite(PGC, HIGH);
        delayMicroseconds(1);
