summaryrefslogtreecommitdiffstats
path: root/test_20121121/entropy_hex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test_20121121/entropy_hex.cpp')
-rw-r--r--test_20121121/entropy_hex.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/test_20121121/entropy_hex.cpp b/test_20121121/entropy_hex.cpp
new file mode 100644
index 0000000..7fc627c
--- /dev/null
+++ b/test_20121121/entropy_hex.cpp
@@ -0,0 +1,63 @@
+// Sample main.cpp file. Blinks the built-in LED, sends a message out
+// USART2, and turns on PWM on pin 2.
+
+#include "wirish.h"
+
+int inByte; // Byte read from Serial1
+
+void printHex(char val);
+
+void setup() {
+ // Initialize Serial1
+ //Serial1.begin(9600);
+ //pinMode(37, INPUT_FLOATING);
+ pinMode(37, INPUT_PULLDOWN);
+ //pinMode(37, INPUT_PULLUP);
+ pinMode(BOARD_LED_PIN, OUTPUT);
+}
+
+void loop() {
+
+ togglePin(BOARD_LED_PIN);
+
+ for (int i=0; i < 78/2; i++) {
+ inByte = 0;
+ for (int j=0; j < 8; j++) {
+ delay(1);
+ inByte |= digitalRead(37) << j;
+ }
+ printHex(inByte);
+ }
+ SerialUSB.println();
+}
+
+void printHex(char val) {
+ char u = (val & 0xF0) >> 4;
+ char l = (val & 0x0F);
+ if(u <= 9) {
+ SerialUSB.write('0'+u);
+ } else {
+ SerialUSB.write('A'+u-10);
+ }
+ if(l <= 9) {
+ SerialUSB.write('0'+l);
+ } else {
+ SerialUSB.write('A'+l-10);
+ }
+}
+
+// Force init to be called *first*, i.e. before static object allocation.
+// Otherwise, statically allocated objects that need libmaple may fail.
+__attribute__((constructor)) void premain() {
+ init();
+}
+
+int main(void) {
+ setup();
+
+ while (true) {
+ loop();
+ }
+
+ return 0;
+}