diff options
Diffstat (limited to 'main.cpp.example')
-rw-r--r-- | main.cpp.example | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/main.cpp.example b/main.cpp.example index 1032733..8fc522a 100644 --- a/main.cpp.example +++ b/main.cpp.example @@ -1,15 +1,17 @@ -// Sample main.cpp file. Blinks an LED, sends a message out USART2 -// and turns on PWM on pin 2 +// Sample main.cpp file. Blinks the built-in LED, sends a message out +// USART2, and turns on PWM on pin 2. #include "wirish.h" -#define LED_PIN 13 #define PWM_PIN 2 -void setup() -{ +void setup() { /* Set up the LED to blink */ - pinMode(LED_PIN, OUTPUT); + 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); @@ -17,28 +19,20 @@ void setup() /* Send a message out the usb virtual serial port */ SerialUSB.println("Hello!"); - - /* Turn on PWM on pin PWM_PIN */ - pinMode(PWM_PIN, PWM); - pwmWrite(PWM_PIN, 0x8000); } -int toggle = 0; - void loop() { - toggle ^= 1; - digitalWrite(LED_PIN, toggle); + toggleLED(); delay(100); } // Force init to be called *first*, i.e. before static object allocation. // Otherwise, statically allocated object that need libmaple may fail. - __attribute__(( constructor )) void premain() { +__attribute__(( constructor )) void premain() { init(); } -int main(void) -{ +int main(void) { setup(); while (1) { |