Messages : 85 Reputation : 4 Date d'inscription : 2015-10-10 Age : 30 Localisation : Lille, FRANCE
Subject: 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! */
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
Hopo28 Newbie
Messages : 1 Reputation : 0 Date d'inscription : 2016-03-02
Subject: Re: NFC infinity table Wed 2 Mar - 11:50
Aaand where does one get the phone app?
MrStein KeyDuino TEAM
Messages : 85 Reputation : 4 Date d'inscription : 2015-10-10 Age : 30 Localisation : Lille, FRANCE
Subject: 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).