Experimental sketch, testing storing a MAC address in program memory and casting to __FlashStringHelper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Experimental sketch, testing storing a MAC address in program memory and casting to __FlashStringHelper | |
// By Nicholas Humfrey | |
// This Macro isn't available for AVR architecture in the Arduino IDE | |
#ifndef FPSTR | |
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer)) | |
#endif | |
const static byte mymac[] = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 }; | |
const static byte myprogmac[] PROGMEM = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 }; | |
// Function to print a MAC address stored in RAM | |
int printMac(const byte *mac) | |
{ | |
for (int i = 0; i < 6; i++) { | |
Serial.print(mac[i], HEX); | |
if (i < 5) | |
Serial.print(':'); | |
} | |
Serial.println(); | |
} | |
// Function to print a MAC address stored in program memory | |
int printMac(const __FlashStringHelper *mac) | |
{ | |
byte ramBytes[6]; | |
// Copy the string from flash program memory into RAM | |
memcpy_P(ramBytes, (const void *)mac, 6); | |
printMac(ramBytes); | |
} | |
void setup () | |
{ | |
Serial.begin(57600); | |
Serial.println("[FlashStringTest]"); | |
// Print MAC address stored in RAM | |
//printMac(mymac); | |
// Print MAC address from an inline string stored in programme memory | |
//printMac(F("\x74\x69\x69\x2D\x30\x31")); | |
// Print Mac address stored in programme memory using the FPSTR() macro | |
printMac(FPSTR(myprogmac)); | |
} | |
void loop () | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment