![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Random Number gen
Diff: main.cpp
- Revision:
- 0:a4501e0912a4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 21 01:06:33 2015 +0000 @@ -0,0 +1,38 @@ +#include "mbed.h" +#include "SLCD.h" + +#define PROGNAME "DEstra-HW4_2 - Random Generator" + +#define DATATIME 250 // milliseconds +#define LASTDGDIV 10 + +SLCD slcd; + +AnalogIn analogRand(PTB0); + +DigitalOut Rled(LED_RED); +Serial pc(USBTX, USBRX); + + +int main(){ + float analogValue; + unsigned int analogBits; + unsigned int lastDigit; + + pc.printf(PROGNAME); + + while(true) { + analogValue = analogRand.read(); + analogBits = analogRand.read_u16(); + lastDigit = analogBits % LASTDGDIV; + Rled = !Rled; // toggle led + pc.printf("%0.5f, %d, %1d\n\r", analogValue, analogBits, lastDigit); + + // LCD // + slcd.Home(); + slcd.clear(); // wipe LCD number + slcd.printf("%1d", lastDigit); // print the lastDigit on LCD + + wait_ms(DATATIME); // 250 ms + } +} \ No newline at end of file