Random Number gen

Dependencies:   SLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
destradafilm
Date:
Mon Sep 21 01:06:33 2015 +0000
Commit message:
HW4.2

Changed in this revision

SLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SLCD.lib	Mon Sep 21 01:06:33 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Sep 21 01:06:33 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa
\ No newline at end of file