• A story in three pieces ( Intro, Getting there..., Finally )

    - Finally

    The final code (TL;DR) looks like this ('Fritzing' attached as pic):

    // /RFID/PICO_SPI1_B1_SAVED.js
    
    // GND GND        // B3  SCK
    // BAT VCC        // B4  MISO
    // B1  CS/SS/SDA  // B5  MOSI
    
    SPI1.setup({sck:B3, miso:B4, mosi:B5 });
    var MFRC522_MODULE = require("MFRC522"), nfc;
    var cards = 
        { "[30,60,213,229]"  : function(){ // flash red LED
          LED1.set(); setTimeout("LED1.reset()", 100); }
         , "[244,171,74,26]" : function(){ // flash green LED
          LED2.set(); setTimeout("LED2.reset()", 100); }
        },f;
    
    function onInit(){
      LED1.set(); LED2.set();
      nfc = MFRC522_MODULE.connect(SPI1, B1 /*CS PICO*/);
      setInterval(function() {
          nfc.findCards(function(card) {
              if ((f = cards[JSON.stringify(card)])) { f(); }
          });
      }, 300);
      LED1.reset(); LED2.reset();
    }
    

    Note 1: Line 21's logical expression of if has double parenthesis ((...)) because Espruino's Javascript validator throws a 'tantrum': logical expression and not assignment expected... Standard Javascript can handle the concise form of assignment and result left on 'stack top' for 'anonymous' and easy reuse...

    Note 2: The print(card); in line 20 is needed to find out the RFID tag/card/token's serial - an array of 4 integers ranging from 0..255 - if not otherwise known.

    Attachement: 'Fritizing my way...' (one end of the blue needed a bit 'photoshopping' push for visualization)


    1 Attachment

    • FritzingMyWay.png
About

Avatar for allObjects @allObjects started