#include "Arduino.h"
#include "ArduinoUniqueID.h"
/// These are found and replaced by the compiler.
#define CompileDate __DATE__
#define CompileTime __TIME__
/// These are for returning copyright information, and storing this information in the code.
const String Copyright = "Philip McGaw"; ///< Copyright company / person's name.
String Product = "ProjectName"; ///< Project name. (Updated when I make a release).
int Hardware_Rev = -1; ///< Placeholder - Takes the value of the VERSION_PINS.
String Serial_Number = "-1"; ///< Placeholder - This is the serial number of the microprocessor.
const int Software_Version = 1; ///< Firmware version. (Updated when I make a release).
String CompileYear = CompileDate;
void setup() {
version(); ///< Moves product population and version into memory.
Serial.begin(9600);
Serial.println((String) "© " + Copyright + " " + CompileYear + " - " + Product);
Serial.println((String) "Software Version: \t\t" + Software_Version + " (" + CompileDate + " " + CompileTime + ")");
Serial.println((String) "Hardware Version: \t\t" + Hardware_Rev);
Serial.println((String) "Serial Number: \t\t\t" + Serial_Number);
}
void loop() {
version();
Serial.println(Hardware_Rev);
delay(10);
}
/**
* Works out the hardware version, and the Serial number of the microcontroller.
*
* This code is run once during setup.
*/
void version() {
CompileYear = CompileYear.substring(7, 11);
/**
Version Ratio VDD (dec) Top Resistor Value Bottom Resistor Value
0 1/16 (0.0625) 4k7 DNF
1 3/16 (0.1875) 910R 3k9
2 5/16 (0.3125) 1k5 3k3
3 7/16 (0.4375) 2k4 2k4 & 430R
4 9/16 (0.5625) 2k4 & 430R 2K4
5 11/16 (0.6875) 3k3 1k5
6 13/16 (0.8125) 3k9 910R
7 15/16 (0.9357) DNF 4k7
*/
int valA = analogRead(PIN_A0); // Analog pin A1
int valB = analogRead(PIN_A1); // Analog pin A0
valA = map(valA, 0, 1023, 7, 0); // Maps the value from analouge pin to 0-7.
valB = map(valB, 0, 1023, 7, 0);
if (valB != 0)
valB = valB + 7; // adds 7 to the MSB if it is not zero
Hardware_Rev = valA; + valB; // gives us a hardware version between 0 and 21.
Serial_Number = ""; ///< empties the string removing the -1 value we filled it with,
for (size_t i = 0; i < UniqueIDsize; i++) {
Serial_Number += String(UniqueID[i], HEX);
}
Serial_Number.toUpperCase();
}