diff options
Diffstat (limited to 'examples/test-systick.cpp')
| -rw-r--r-- | examples/test-systick.cpp | 50 | 
1 files changed, 22 insertions, 28 deletions
diff --git a/examples/test-systick.cpp b/examples/test-systick.cpp index 247892d..c7b5529 100644 --- a/examples/test-systick.cpp +++ b/examples/test-systick.cpp @@ -3,54 +3,48 @@  #include "wirish.h"  #include "systick.h" -#define LED_PIN 13 -#define PWM_PIN  2 -#define BUT     38 +#define LED_PIN BOARD_LED_PIN +#define PWM_PIN 2 +#define BUT     BOARD_BUTTON_PIN -void setup() -{ +void setup() {      /* Set up the LED to blink  */      pinMode(LED_PIN, OUTPUT); - -    /* Turn on PWM on pin PWM_PIN */ -    pinMode(PWM_PIN, PWM); -    pwmWrite(PWM_PIN, 0x8000); - -    pinMode(BUT, INPUT_PULLDOWN); +    pinMode(BUT, INPUT);  } -int toggle = 0; +bool disable = true;  long time = 0;  void loop() { -    toggle ^= 1; -    digitalWrite(LED_PIN, toggle); +    volatile int i = 0; +    toggleLED();      // An artificial delay -    int16 i = 1; -    float j = 1; -    for(i=0; i<6553; i++) { -        j = sqrt(j) + 1;  -    } -         -    if(digitalRead(BUT)) { -        systick_disable(); -    } else { -        systick_resume(); +    for(i = 0; i < 150000; i++) +        ; + +    if(isButtonPressed()) { +        if (disable) { +            systick_disable(); +            SerialUSB.println("Disabling SysTick"); +        } else { +            SerialUSB.println("Re-enabling SysTick"); +            systick_resume(); +        } +        disable = !disable;      } -    //SerialUSB.println(micros());      // there is a bug with this      SerialUSB.println(millis());  }  // 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) {  | 
