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