Un échange d'information autour de la carte KeyDuino
 
HomeHome  FAQFAQ  RegisterRegister  Log inLog in  

Share | 
 

 NFC infinity table

View previous topic View next topic Go down 
AuthorMessage
MrStein
KeyDuino TEAM
avatar

Messages : 59
Reputation : 3
Date d'inscription : 2015-10-10
Age : 23
Localisation : Lille, FRANCE

PostSubject: NFC infinity table   Sun 25 Oct - 22:19


Code:

/*
This sketch is made to be used with any NDEF active device sending a color value (format #RRGGBB).
This then sets the connected LEDs to the specified color.
Please note that it won't work with a passive NFC tag.
You will need NDEF library and FastLED ( https://github.com/FastLED/FastLED )
More information in the video of the project: https://www.youtube.com/watch?v=mML4pEM4C_A
Author: Mr Stein
Revised by Raymond Borenstein - CITC-EuraRFID
Compatible with KeyDuino 5.1
Join http://keyduino.forumsactifs.com/ to ask your questions, suggest your ideas, and show your projects!
*/

#include <FastLED.h>
#include <KeyDuino.h>
#include "snep.h"
#include "NdefMessage.h"

#define NUM_LEDS 152
#define DATA_PIN 13
CRGB leds[NUM_LEDS];
#define BRIGHTNESS  255

#define FRAMES_PER_SECOND 60
#define COOLING  55
#define SPARKING 120

KeyDuino keyDuino;
SNEP nfc(keyDuino);
uint8_t ndefBuf[128];

void setup() {
  Serial.begin(115200);
  FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness( BRIGHTNESS );
  Color_ALL(255,0,0);
}

void Color_ALL(int RED, int GREEN, int BLUE)
{
  for( int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB(RED, GREEN, BLUE);
  }
  FastLED.show();
}


unsigned int hexToDec(String hexString) {
  unsigned int decValue = 0;
  int nextInt;
  for (int i = 0; i < hexString.length(); i++) {
    nextInt = int(hexString.charAt(i));
    if (nextInt >= 48 && nextInt <= 57) nextInt = map(nextInt, 48, 57, 0, 9);
    if (nextInt >= 65 && nextInt <= 70) nextInt = map(nextInt, 65, 70, 10, 15);
    if (nextInt >= 97 && nextInt <= 102) nextInt = map(nextInt, 97, 102, 10, 15);
    nextInt = constrain(nextInt, 0, 15);
    decValue = (decValue * 16) + nextInt;
  }

  return decValue;
}


String GET_NDEF(){
  int msgSize = nfc.read(ndefBuf, sizeof(ndefBuf));
  if (msgSize > 0) {
    NdefMessage msg  = NdefMessage(ndefBuf, msgSize);      
    NdefRecord record = msg.getRecord(0);
    int payloadLength = record.getPayloadLength();
    byte payload[payloadLength];
    record.getPayload(payload);        
    int startChar = 0;        
    if (record.getTnf() == TNF_WELL_KNOWN && record.getType() == "T") {
      startChar = payload[0] + 1;
    }
    else if (record.getTnf() == TNF_WELL_KNOWN && record.getType() == "U") {
      startChar = 1;
    }

    String payloadAsString = "";
    for (int c = startChar; c < payloadLength; c++) {
      payloadAsString += (char)payload[c];
    }
    return(payloadAsString);
  }
  else return("NULL");
}

void loop() {
  String Color = "NULL";

  while(Color=="NULL") Color = GET_NDEF();
  Serial.println(Color);


  //The received NDEF message must be formatted "#RRGGBB", where RR is red level, GG green level, BB blue level
  String r_string = Color.substring(1,3);
  String g_string = Color.substring(3,5);
  String b_string = Color.substring(5,7);
  int r = hexToDec(r_string);
  int g = hexToDec(g_string);
  int b = hexToDec(b_string);

  Color_ALL(r,g,b);
}


Last edited by MrStein on Tue 8 Mar - 13:31; edited 1 time in total
Back to top Go down
http://keyduino.forumsactifs.com
Hopo28
Newbie
Newbie


Messages : 1
Reputation : 0
Date d'inscription : 2016-03-02

PostSubject: Re: NFC infinity table   Wed 2 Mar - 11:50

Aaand where does one get the phone app?
Back to top Go down
MrStein
KeyDuino TEAM
avatar

Messages : 59
Reputation : 3
Date d'inscription : 2015-10-10
Age : 23
Localisation : Lille, FRANCE

PostSubject: Re: NFC infinity table   Thu 3 Mar - 8:58

Hi ! the keyduino APK is on the github of the keyduino project (https://github.com/CITCEuraRFID/KeyDuino)
But for this version, I use the NXP chameleon APK, and the code onlywork with the PN532 HSU lib (We will work on it for make it compatible with the keyduino lib).
Back to top Go down
http://keyduino.forumsactifs.com
Sponsored content




PostSubject: Re: NFC infinity table   

Back to top Go down
 
NFC infinity table
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» check out this for a wedding table display
» Mordheim Table Size
» coffee table - one of my bargain buys today. ID?
» Topsy Turvey Triangles (wall hanging or table topper)
» Gaming Table Creation Tips

Permissions in this forum:You cannot reply to topics in this forum
KeyDuino forum :: KeyDuino projects & tutorial :: Tutorials :: Official tutorial-
Jump to: