diff options
author | Marti Bolivar <mbolivar@leaflabs.com> | 2011-03-04 20:25:26 -0500 |
---|---|---|
committer | Marti Bolivar <mbolivar@leaflabs.com> | 2011-03-08 13:43:41 -0500 |
commit | 8863418f0595c8dfd7d01081be941541539827bb (patch) | |
tree | 94b86a04e6808df1390e88d809dd54c9aa8edccb /examples/test-systick.cpp | |
parent | 8241a4c640d036faa148350219ad3deea72a23c2 (diff) | |
download | librambutan-8863418f0595c8dfd7d01081be941541539827bb.tar.gz librambutan-8863418f0595c8dfd7d01081be941541539827bb.zip |
Brought examples/ up to date; PIN_MAP bugfix for D24.
(Cherry-pick from refactor with some modifications).
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) { |