From 05bb1e666f9542d5636645cf69df5d3741f2bc2e Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Tue, 8 Feb 2011 22:38:21 -0500 Subject: Function examples/test-session.cpp on Native --- main.cpp.example | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'main.cpp.example') 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) { -- cgit v1.2.3