summaryrefslogtreecommitdiffstats
path: root/test_20121121/entropy_hex.cpp
blob: 7fc627c8bd6c967f5acec8149c10dc8ed110b47c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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;
}