From f0fdd4b91cd4dded9e029a7a3a8b6a158d721a30 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 22 Nov 2012 00:21:11 +0100 Subject: add Nov 22nd notes and scripts --- test_20121121/entropy_hex.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 test_20121121/entropy_hex.cpp (limited to 'test_20121121/entropy_hex.cpp') 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; +} -- cgit v1.2.3