// 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; }