main.cpp.example 880B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Sample main.cpp file. Blinks the built-in LED, sends a message out
  2. // USART2, and turns on PWM on pin 2.
  3. #include <wirish/wirish.h>
  4. #define PWM_PIN 2
  5. void setup() {
  6. /* Set up the LED to blink */
  7. pinMode(BOARD_LED_PIN, OUTPUT);
  8. /* Turn on PWM on pin PWM_PIN */
  9. pinMode(PWM_PIN, PWM);
  10. pwmWrite(PWM_PIN, 0x8000);
  11. /* Send a message out USART2 */
  12. Serial2.begin(9600);
  13. Serial2.println("Hello world!");
  14. /* Send a message out the usb virtual serial port */
  15. SerialUSB.println("Hello!");
  16. }
  17. void loop() {
  18. toggleLED();
  19. delay(100);
  20. }
  21. // Force init to be called *first*, i.e. before static object allocation.
  22. // Otherwise, statically allocated objects that need libmaple may fail.
  23. __attribute__((constructor)) void premain() {
  24. init();
  25. }
  26. int main(void) {
  27. setup();
  28. while (true) {
  29. loop();
  30. }
  31. return 0;
  32. }