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 --- Venus_Skeleton/Venus_Skeleton.ino | 100 ++++++++++- Venus_Skeleton/libs/TrueRandom/TrueRandom.cpp | 186 +++++++++++++++++++++ Venus_Skeleton/libs/TrueRandom/TrueRandom.h | 28 ++++ .../examples/AllFunctions/AllFunctions.pde | 125 ++++++++++++++ .../TrueRandom/examples/Benchmark/Benchmark.pde | 48 ++++++ .../libs/TrueRandom/examples/Die/Die.pde | 33 ++++ .../TrueRandom/examples/MacAddress/MacAddress.pde | 70 ++++++++ .../TrueRandom/examples/Magic8Ball/Magic8Ball.pde | 59 +++++++ .../examples/SetRandomSeed/SetRandomSeed.pde | 28 ++++ .../libs/TrueRandom/examples/Uuid/Uuid.pde | 58 +++++++ Venus_Skeleton/libs/TrueRandom/keywords.txt | 26 +++ Venus_Skeleton/libs/TrueRandom/release notes.txt | 6 + 12 files changed, 761 insertions(+), 6 deletions(-) create mode 100644 Venus_Skeleton/libs/TrueRandom/TrueRandom.cpp create mode 100644 Venus_Skeleton/libs/TrueRandom/TrueRandom.h create mode 100644 Venus_Skeleton/libs/TrueRandom/examples/AllFunctions/AllFunctions.pde create mode 100644 Venus_Skeleton/libs/TrueRandom/examples/Benchmark/Benchmark.pde create mode 100644 Venus_Skeleton/libs/TrueRandom/examples/Die/Die.pde create mode 100644 Venus_Skeleton/libs/TrueRandom/examples/MacAddress/MacAddress.pde create mode 100644 Venus_Skeleton/libs/TrueRandom/examples/Magic8Ball/Magic8Ball.pde create mode 100644 Venus_Skeleton/libs/TrueRandom/examples/SetRandomSeed/SetRandomSeed.pde create mode 100644 Venus_Skeleton/libs/TrueRandom/examples/Uuid/Uuid.pde create mode 100644 Venus_Skeleton/libs/TrueRandom/keywords.txt create mode 100644 Venus_Skeleton/libs/TrueRandom/release notes.txt diff --git a/Venus_Skeleton/Venus_Skeleton.ino b/Venus_Skeleton/Venus_Skeleton.ino index 213f0e6..531235c 100644 --- a/Venus_Skeleton/Venus_Skeleton.ino +++ b/Venus_Skeleton/Venus_Skeleton.ino @@ -83,6 +83,7 @@ int currValServoTurret = 0; // Actuator values int currValTurret = 0; int currValDirection = 0; +int currValDirectionDegree = 0; // Timers long timerMovementStart = 0; @@ -95,6 +96,7 @@ int counterInit = 0; int counterMovement = 0; int counterTurret = -1; int counterTurretWait = 0; +int counterSampleConfirm = 0; // ********************** @@ -463,6 +465,66 @@ bool moveTurnTo(int direction) { maneuver(100,-100); } } else { + if(direction < NUM_DIRECTIONS){ + int sign = -1; + } + if(direction >= NUM_DIRECTIONS){ + int sign = 1; + } + int deg = ((int)((millis() - timerMovementStart) * CAL_MOVE_TURN * sign)) % 360; + data.robot_curr_deg = (data.robot_curr_deg + deg + 360*3) % 360; + } + + if (timerMovementStop < millis()) { + stopMovement(); + currValDirection = 0; + for (int k = 0; k < NUM_TURRET_DIRECTIONS; k++) { + data.obstacle_turret_distances[k] = 300; + } + } +} + +void moveTurnToDeg(int degree) { + if (degree == 0 || degree == NUM_DIRECTIONS) { + return true; + } + + // Make sure turret doesn't move + timerTurret = 1; + + // if movementtimer is not started, start timer or something and initiate movement + // else continue movement and return false + // if movementtimer is expired, stop movement. + + if (!timerMovementStop) { + DEBUG_PRINT(" Start turn move: "); + DEBUG_PRINT(degree); + DEBUG_PRINT("deg - "); + counterMovement++; + // timer = now() + direction * formula + timerMovementStart = millis(); + timerMovementStop = millis() + (degree % NUM_DIRECTIONS) * CAL_MOVE_TURN; + + // DO A COMPASS CHECK + + maneuver(0,0); + if(degree < 0){ + DEBUG_PRINT(" left\n"); + // turn left + maneuver(-100,100); + } + if(degree > 0){ + DEBUG_PRINT(" right\n"); + // Turn right + maneuver(100,-100); + } + } else { + if(degree < 0){ + int sign = -1; + } + if(degree > 0){ + int sign = 1; + } int deg = ((int)((millis() - timerMovementStart) * CAL_MOVE_TURN * sign)) % 360; data.robot_curr_deg = (data.robot_curr_deg + deg + 360*3) % 360; } @@ -593,7 +655,7 @@ int checkBestRoute(int preferedDirection) { if (preferedDirection == -1) { directionArray[i] = 1; } else { - directionArray[i] = 100 + abs((int)(100 * (float)(abs(((NUM_DIRECTIONS - abs(i - NUM_DIRECTIONS)) % NUM_DIRECTIONS) - preferedDirection) - (float)NUM_DIRECTIONS / 2))); + directionArray[i] = 1 + abs((int)(pow(2, abs((int)(abs(((NUM_DIRECTIONS - abs(i - NUM_DIRECTIONS)) % NUM_DIRECTIONS) - preferedDirection) - (float)NUM_DIRECTIONS / 2))))); } // limit to first 180deg @@ -688,12 +750,26 @@ void checkSample() { stopAllServos(); sensSampleTurret(); sensSampleGripper(); + sensObstacleTurret(); } } -bool confirmSample() { - if (data.sample_turret_detected || data.sample_gripper_detected) { - if (!data.sample_gripper_detected) { +bool confirmSample(int turretVal) { + if (!counterSampleConfirm) { + + // Turret direction in degrees calculated from forward. (negative is left, positive is right) + int checkTurretDeg = (int)((counterTurret - ((NUM_TURRET_DIRECTIONS - 1) / 2)) * 10 * -1); + + + int checkTurretDegAbs = 90 - abs(checkTurretDeg); + int currValDirectionDegree = + moveTurnToDeg + } + + + if (data.sample_turret_detected[turretVal] || data.sample_gripper_detected[turretVal]) { + if (!data.sample_gripper_detected[turretVal]) { + // Turn robot to sample // If still no sample_gripper_detected return false } @@ -767,7 +843,7 @@ void setup() { void loop() { - //sensCompass(); + // x sensCompass(); sensObstacleTurret(); sensIRLine(L); sensIRLine(R); @@ -776,7 +852,6 @@ void loop() { //sensLab(); - //checkSample(); checkFreePath(); // calculateOrientation(); @@ -811,6 +886,7 @@ void loop() { break; case OPMODE_MAPPING: + checkSample(); turnTurretToNext(); checkBestRoute(0); moveTurnTo(currValDirection); @@ -818,6 +894,18 @@ void loop() { break; case OPMODE_CHECKSAMPLE: + + + + + confirmSample(); + moveTurnToDeg(); + currValTurret + + + + + break; case OPMODE_GRABSAMPLE: diff --git a/Venus_Skeleton/libs/TrueRandom/TrueRandom.cpp b/Venus_Skeleton/libs/TrueRandom/TrueRandom.cpp new file mode 100644 index 0000000..61920d0 --- /dev/null +++ b/Venus_Skeleton/libs/TrueRandom/TrueRandom.cpp @@ -0,0 +1,186 @@ +/** + * TrueRandom - A true random number generator for Arduino. + * + * Copyright (c) 2010 Peter Knight, Tinker.it! All rights reserved. + */ + +#include +#include "TrueRandom.h" + +int TrueRandomClass::randomBitRaw(void) { + uint8_t copyAdmux, copyAdcsra, copyAdcsrb, copyPortc, copyDdrc; + uint16_t i; + uint8_t bit; + volatile uint8_t dummy; + + // Store all the registers we'll be playing with + copyAdmux = ADMUX; + copyAdcsra = ADCSRA; + copyAdcsrb = ADCSRB; + copyPortc = PORTC; + copyDdrc = DDRC; + + // Perform a conversion on Analog0, using the Vcc reference + ADMUX = _BV(REFS0); + +#if F_CPU > 16000000 + // ADC is enabled, divide by 32 prescaler + ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS0); +#elif F_CPU > 8000000 + // ADC is enabled, divide by 16 prescaler + ADCSRA = _BV(ADEN) | _BV(ADPS2); +#else + // ADC is enabled, divide by 8 prescaler + ADCSRA = _BV(ADEN) | _BV(ADPS1) | _BV(ADPS0); +#endif + + // Autotriggering disabled + ADCSRB = 0; + + // Pull Analog0 to ground + PORTC &=~_BV(0); + DDRC |= _BV(0); + // Release Analog0, apply internal pullup + DDRC &= ~_BV(0); + PORTC |= _BV(1); + // Immediately start a sample conversion on Analog0 + ADCSRA |= _BV(ADSC); + // Wait for conversion to complete + while (ADCSRA & _BV(ADSC)) PORTC ^= _BV(0); + // Xor least significant bits together + bit = ADCL; + // We're ignoring the high bits, but we have to read them before the next conversion + dummy = ADCH; + + // Restore register states + ADMUX = copyAdmux; + ADCSRA = copyAdcsra; + ADCSRB = copyAdcsrb; + PORTC = copyPortc; + DDRC = copyDdrc; + + return bit & 1; +} + +int TrueRandomClass::randomBitRaw2(void) { + // Software whiten bits using Von Neumann algorithm + // + // von Neumann, John (1951). "Various techniques used in connection + // with random digits". National Bureau of Standards Applied Math Series + // 12:36. + // + for(;;) { + int a = randomBitRaw() | (randomBitRaw()<<1); + if (a==1) return 0; // 1 to 0 transition: log a zero bit + if (a==2) return 1; // 0 to 1 transition: log a one bit + // For other cases, try again. + } +} + +int TrueRandomClass::randomBit(void) { + // Software whiten bits using Von Neumann algorithm + // + // von Neumann, John (1951). "Various techniques used in connection + // with random digits". National Bureau of Standards Applied Math Series + // 12:36. + // + for(;;) { + int a = randomBitRaw2() | (randomBitRaw2()<<1); + if (a==1) return 0; // 1 to 0 transition: log a zero bit + if (a==2) return 1; // 0 to 1 transition: log a one bit + // For other cases, try again. + } +} + +char TrueRandomClass::randomByte(void) { + char result; + uint8_t i; + result = 0; + for (i=8; i--;) result += result + randomBit(); + return result; +} + +int TrueRandomClass::rand() { + int result; + uint8_t i; + result = 0; + for (i=15; i--;) result += result + randomBit(); + return result; +} + +long TrueRandomClass::random() { + long result; + uint8_t i; + result = 0; + for (i=31; i--;) result += result + randomBit(); + return result; +} + +long TrueRandomClass::random(long howBig) { + long randomValue; + long maxRandomValue; + long topBit; + long bitPosition; + + if (!howBig) return 0; + randomValue = 0; + if (howBig & (howBig-1)) { + // Range is not a power of 2 - use slow method + topBit = howBig-1; + topBit |= topBit>>1; + topBit |= topBit>>2; + topBit |= topBit>>4; + topBit |= topBit>>8; + topBit |= topBit>>16; + topBit = (topBit+1) >> 1; + + bitPosition = topBit; + do { + // Generate the next bit of the result + if (randomBit()) randomValue |= bitPosition; + + // Check if bit + if (randomValue >= howBig) { + // Number is over the top limit - start again. + randomValue = 0; + bitPosition = topBit; + } else { + // Repeat for next bit + bitPosition >>= 1; + } + } while (bitPosition); + } else { + // Special case, howBig is a power of 2 + bitPosition = howBig >> 1; + while (bitPosition) { + if (randomBit()) randomValue |= bitPosition; + bitPosition >>= 1; + } + } + return randomValue; +} + +long TrueRandomClass::random(long howSmall, long howBig) { + if (howSmall >= howBig) return howSmall; + long diff = howBig - howSmall; + return TrueRandomClass::random(diff) + howSmall; +} + +void TrueRandomClass::memfill(char* location, int size) { + for (;size--;) *location++ = randomByte(); +} + +void TrueRandomClass::mac(uint8_t* macLocation) { + memfill((char*)macLocation,6); +} + +void TrueRandomClass::uuid(uint8_t* uuidLocation) { + // Generate a Version 4 UUID according to RFC4122 + memfill((char*)uuidLocation,16); + // Although the UUID contains 128 bits, only 122 of those are random. + // The other 6 bits are fixed, to indicate a version number. + uuidLocation[6] = 0x40 | (0x0F & uuidLocation[6]); + uuidLocation[8] = 0x80 | (0x3F & uuidLocation[8]); +} + +TrueRandomClass TrueRandom; diff --git a/Venus_Skeleton/libs/TrueRandom/TrueRandom.h b/Venus_Skeleton/libs/TrueRandom/TrueRandom.h new file mode 100644 index 0000000..cfcecf8 --- /dev/null +++ b/Venus_Skeleton/libs/TrueRandom/TrueRandom.h @@ -0,0 +1,28 @@ +/** + * TrueRandom - A true random number generator for Arduino. + * + * Copyright (c) 2010 Peter Knight, Tinker.it! All rights reserved. + */ + +#ifndef TrueRandom_h +#define TrueRandom_h + +#include +class TrueRandomClass +{ + public: + int rand(); + long random(); + long random(long howBig); + long random(long howsmall, long how); + int randomBit(void); + char randomByte(void); + void memfill(char* location, int size); + void mac(uint8_t* macLocation); + void uuid(uint8_t* uuidLocation); + private: + int randomBitRaw(void); + int randomBitRaw2(void); +}; +extern TrueRandomClass TrueRandom; +#endif \ No newline at end of file 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 + +unsigned long startTime; +int i; + +void setup() { + Serial.begin(9600); + + Serial.println("TrueRandom benchmark"); + Serial.println("--------------------"); + Serial.println(); + + Serial.print("Arduino clock speed: "); + Serial.print(F_CPU/1000000); + Serial.println("MHz"); + + Serial.print("randomBit(): "); + startTime = millis(); + TrueRandom.randomBit(); + Serial.print(millis() - startTime); + Serial.println("ms"); + + Serial.print("randomByte(): "); + startTime = millis(); + TrueRandom.randomByte(); + Serial.print(millis() - startTime); + Serial.println("ms"); + + Serial.print("random(100): "); + startTime = millis(); + TrueRandom.random(100); + Serial.print(millis() - startTime); + Serial.println("ms"); + + Serial.print("random(65536): "); + startTime = millis(); + TrueRandom.random(65536); + Serial.print(millis() - startTime); + Serial.println("ms"); + + Serial.print("random(65537): "); + startTime = millis(); + TrueRandom.random(65537); + Serial.print(millis() - startTime); + Serial.println("ms"); +} +void loop() { +} \ No newline at end of file diff --git a/Venus_Skeleton/libs/TrueRandom/examples/Die/Die.pde b/Venus_Skeleton/libs/TrueRandom/examples/Die/Die.pde new file mode 100644 index 0000000..cb67888 --- /dev/null +++ b/Venus_Skeleton/libs/TrueRandom/examples/Die/Die.pde @@ -0,0 +1,33 @@ +/* + * A simple electronic die. + * + * Press the reset button to throw a set of dice. + * + */ + +#include + +void setup() { + Serial.begin(9600); + Serial.println("Throwing..."); + delay(1000); + + Serial.print("6 sided die: "); + Serial.println(TrueRandom.random(1,7)); + Serial.print("4 sided die: "); + Serial.println(TrueRandom.random(1,5)); + Serial.print("8 sided die: "); + Serial.println(TrueRandom.random(1,9)); + Serial.print("10 sided die: "); + Serial.println(TrueRandom.random(1,11)); + Serial.print("12 sided die: "); + Serial.println(TrueRandom.random(1,13)); + Serial.print("20 sided die: "); + Serial.println(TrueRandom.random(1,21)); + Serial.print("100 sided die: "); + Serial.println(TrueRandom.random(1,101)); +} + +void loop() { + ; // Do nothing +} \ No newline at end of file diff --git a/Venus_Skeleton/libs/TrueRandom/examples/MacAddress/MacAddress.pde b/Venus_Skeleton/libs/TrueRandom/examples/MacAddress/MacAddress.pde new file mode 100644 index 0000000..fc68ba7 --- /dev/null +++ b/Venus_Skeleton/libs/TrueRandom/examples/MacAddress/MacAddress.pde @@ -0,0 +1,70 @@ +// This example modifies the Ethernet Client example to use +// a randomly generated MAC address +// +// This has the advantage that no MAC addresses will clash, even if +// every device uses exactly the same code on its Arduino. +// + +// This example is identical to the Ethernet/Client example +// with three changes to utilise TrueRandom. + +#include + +// +// Change 1/3: Include TrueRandom library +#include +// +// + +// +// Change 2/3: Include TrueRandom library +// TrueRandom sets this, so no default is needed here. +byte mac[6]; +// +// + +byte ip[] = { 10, 0, 0, 177 }; +byte server[] = { 64, 233, 187, 99 }; // Google + +Client client(server, 80); + +void setup() +{ + // + // Change 3/3: Set a random MAC address using TrueRandom + TrueRandom.mac(mac); + // + // + + + Ethernet.begin(mac, ip); + Serial.begin(9600); + + delay(1000); + + Serial.println("connecting..."); + + if (client.connect()) { + Serial.println("connected"); + client.println("GET /search?q=arduino HTTP/1.0"); + client.println(); + } else { + Serial.println("connection failed"); + } +} + +void loop() +{ + if (client.available()) { + char c = client.read(); + Serial.print(c); + } + + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + for(;;) + ; + } +} \ No newline at end of file diff --git a/Venus_Skeleton/libs/TrueRandom/examples/Magic8Ball/Magic8Ball.pde b/Venus_Skeleton/libs/TrueRandom/examples/Magic8Ball/Magic8Ball.pde new file mode 100644 index 0000000..101bd38 --- /dev/null +++ b/Venus_Skeleton/libs/TrueRandom/examples/Magic8Ball/Magic8Ball.pde @@ -0,0 +1,59 @@ +/* + * 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* answers[20] = { + "As I see it, yes", + "It is certain", + "It is decidedly so", + "Mostly likely", + "Outlook good", + "Signs point to yes", + "Without a doubt", + "Yes", + "Yes - definitely", + "You may rely on it", + "Reply hazy, try again", + "Ask again later", + "Better not tell you now", + "Cannot predict now", + "Concentrate and ask again", + "Don't count on it", + "My reply is no", + "My sources say no", + "Outlook not so good", + "Very doubtful" +}; + +int answerNumber; + +void setup() { + Serial.begin(9600); + + Serial.print("The answer is "); + + // Dramatic pause + delay(1000); + Serial.print(". "); + delay(1000); + Serial.print(". "); + delay(1000); + Serial.print(". "); + delay(1000); + + answerNumber = TrueRandom.random(20); + Serial.println( answers[answerNumber] ); +} + +void loop() { + ; // Do nothing +} \ No newline at end of file diff --git a/Venus_Skeleton/libs/TrueRandom/examples/SetRandomSeed/SetRandomSeed.pde b/Venus_Skeleton/libs/TrueRandom/examples/SetRandomSeed/SetRandomSeed.pde new file mode 100644 index 0000000..e9f009c --- /dev/null +++ b/Venus_Skeleton/libs/TrueRandom/examples/SetRandomSeed/SetRandomSeed.pde @@ -0,0 +1,28 @@ +/* + * SetRandomSeed. + * + * You can use TrueRandom to set the seed for the normal Arduino + * random number generator. + * + * That way you can quickly generate random numbers that are + * different every time using the random number generator. + */ + +#include + +int i; + +void setup() { + Serial.begin(9600); + Serial.println("Here are some pseudo random digits."); + for (i=1;i<=20;i++) Serial.print(random(10)); + Serial.println(); + + randomSeed(TrueRandom.random()); + + Serial.println("Here are some random seeded pseudo random digits."); + for (i=1;i<=20;i++) Serial.print(random(10)); + Serial.println(); +} +void loop() { +} \ No newline at end of file diff --git a/Venus_Skeleton/libs/TrueRandom/examples/Uuid/Uuid.pde b/Venus_Skeleton/libs/TrueRandom/examples/Uuid/Uuid.pde new file mode 100644 index 0000000..3f80db3 --- /dev/null +++ b/Venus_Skeleton/libs/TrueRandom/examples/Uuid/Uuid.pde @@ -0,0 +1,58 @@ +/* + * Uuid + * + * UUIDs are unique numbers that are used for identifying individual units, + * functions, programmes, or whatever you want to tag. + * + * In this demo, press the Arduino Reset button to generate a new number. + * + * UUIDs can be assigned sequentially from allocated blocks of numbers, but + * they are most powerful when randomly assigned. UUIDs are such big numbers + * that, for all effective purposes, no two numbers will ever match. + * + * UUIDs are particularly useful in web-aware devices, or radio networks. + * + * For a discussion of the use of UUIDs, see + * http://en.wikipedia.org/wiki/Universally_Unique_Identifier + * + * For implementation details of UUIDs, see + * http://tools.ietf.org/html/rfc4122 + */ + +#include + +byte uuidNumber[16]; // UUIDs in binary form are 16 bytes long + +void printHex(byte number) { + int topDigit = number >> 4; + int bottomDigit = number & 0x0f; + // Print high hex digit + Serial.print( "0123456789ABCDEF"[topDigit] ); + // Low hex digit + Serial.print( "0123456789ABCDEF"[bottomDigit] ); +} + +void printUuid(byte* uuidNumber) { + 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(uuidNumber[i]); + } +} + +void setup() { + Serial.begin(9600); + + // Generate a new UUID + TrueRandom.uuid(uuidNumber); + + Serial.print("The UUID number is "); + printUuid(uuidNumber); + Serial.println(); +} + +void loop() { +} \ No newline at end of file diff --git a/Venus_Skeleton/libs/TrueRandom/keywords.txt b/Venus_Skeleton/libs/TrueRandom/keywords.txt new file mode 100644 index 0000000..07504d7 --- /dev/null +++ b/Venus_Skeleton/libs/TrueRandom/keywords.txt @@ -0,0 +1,26 @@ +####################################### +# Syntax Coloring Map For TrueRandom +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +TrueRandom KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +rand KEYWORD2 +random KEYWORD2 +randomBit KEYWORD2 +randomByte KEYWORD2 +memfill KEYWORD2 +mac KEYWORD2 +uuid KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/Venus_Skeleton/libs/TrueRandom/release notes.txt b/Venus_Skeleton/libs/TrueRandom/release notes.txt new file mode 100644 index 0000000..289981e --- /dev/null +++ b/Venus_Skeleton/libs/TrueRandom/release notes.txt @@ -0,0 +1,6 @@ +TrueRandom library +by Peter Knight, Tinker.it! 2010 +http://code.google.com/p/tinkerit + +v1: First release +v1.1: Bug fix for rand and random functions \ No newline at end of file -- cgit v1.2.1