diff options
Diffstat (limited to 'main.cpp.example')
| -rw-r--r-- | main.cpp.example | 43 | 
1 files changed, 43 insertions, 0 deletions
diff --git a/main.cpp.example b/main.cpp.example new file mode 100644 index 0000000..4e44489 --- /dev/null +++ b/main.cpp.example @@ -0,0 +1,43 @@ +// Sample main.cpp file. Blinks the built-in LED, sends a message out +// USART2, and turns on PWM on pin 2. + +#include <wirish/wirish.h> + +#define PWM_PIN  2 + +void setup() { +    /* Set up the LED to blink  */ +    pinMode(BOARD_LED_PIN, OUTPUT); + +    /* Turn on PWM on pin PWM_PIN */ +    pinMode(PWM_PIN, PWM); +    pwmWrite(PWM_PIN, 0x8000); + +    /* Send a message out USART2  */ +    Serial2.begin(9600); +    Serial2.println("Hello world!"); + +    /* Send a message out the usb virtual serial port  */ +    SerialUSB.println("Hello!"); +} + +void loop() { +    toggleLED(); +    delay(100); +} + +// 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; +}  | 
