From 144ef44e4a3ce3b27a9135a1366ecf4155b13886 Mon Sep 17 00:00:00 2001 From: Peter de Kok Date: Wed, 10 Jun 2015 16:51:17 +0200 Subject: Added TrueRandom Lib --- .../examples/AllFunctions/AllFunctions.pde | 125 +++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 Venus_Skeleton/libs/TrueRandom/examples/AllFunctions/AllFunctions.pde (limited to 'Venus_Skeleton/libs/TrueRandom/examples/AllFunctions/AllFunctions.pde') diff --git a/Venus_Skeleton/libs/TrueRandom/examples/AllFunctions/AllFunctions.pde b/Venus_Skeleton/libs/TrueRandom/examples/AllFunctions/AllFunctions.pde new file mode 100644 index 0000000..8c63f21 --- /dev/null +++ b/Venus_Skeleton/libs/TrueRandom/examples/AllFunctions/AllFunctions.pde @@ -0,0 +1,125 @@ +/* + * A magic 8 ball. + * + * Press the reset button to see into the future. + * + * View the answer to your question in the Serial Monitor, at 19200 baud. + * + * Press the Arduino reset button to ask another question. + * + */ + +#include + +char array[10]; +int arrayLength = 10; + +char macAddress[6]; // MAC addresses are always 6 bytes long +char uuidNumber[16]; // UUIDs are always 16 bytes long + +void printHex(char number) { + // Print high hex digit + Serial.print( "0123456789ABCDEF"[number / 16] ); + // Low hex digit + Serial.print( "0123456789ABCDEF"[number & 15] ); +} + +void printMac(char* macAddress) { + // Print a MAC address in the form + // 12:23:34:45:56:67 + int i; + for (i=0; i<6; i++) { + printHex(macAddress[i]); + if (i<5) Serial.print(":"); + } +} +void printUuid(char* uuidNumber) { + // Print a UUID in the form + // 12345678-1234-1234-1234-123456789ABC + int i; + for (i=0; i<16; i++) { + if (i==4) Serial.print("-"); + if (i==6) Serial.print("-"); + if (i==8) Serial.print("-"); + if (i==10) Serial.print("-"); + printHex(uuid[i]); + } +} + +void setup() { + Serial.begin(9600); + + // TrueRandom.rand() returns a positive integer + // in the range 0..32767 + + Serial.print("A random int: "); + Serial.println(TrueRandom.rand()); + + // TrueRandom.random() returns a positive long integer + // in the range 0..2,147,483,647 + + Serial.print("A random long int: "); + Serial.println(TrueRandom.random()); + + // TrueRandom.random(n) returns a positive long integer + // in the range 0 .. (n-1) + + Serial.print("A random number between 0 and 999: "); + Serial.println(TrueRandom.random(1000)); + + // TrueRandom.random(a,b) returns a positive long integer + // in the range a .. (b-1). + // b must be larger than a. + + Serial.print("A random number between 1000 and 9999: "); + Serial.println(TrueRandom.random(1000,10000)); + + // TrueRandom.randomBit() returns a single random bit + // It returns either 1 or 0. + Serial.print("A random bit: "); + Serial.println(TrueRandom.randomBit()); + + // TrueRandom.randomByte() returns a single random byte + // It returns an 8 bit char (byte) in the range -128 to 127. + Serial.print("A random byte: "); + Serial.println(TrueRandom.randomByte(),DEC); + + // Zero an array + for(i=0; i