Skip to content

Commit 66781b0

Browse files
committed
examples/timer: Add blinky example.
Signed-off-by: zhanglinjing <[email protected]>
1 parent c90307e commit 66781b0

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

examples/timer/blinky.ino

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "Arduino.h"
2+
#include "xmc_gpio.h"
3+
// the setup function runs once when you press reset or power the board
4+
void setup() {
5+
setupGPIO();
6+
}
7+
8+
// the loop function runs over and over again forever
9+
void loop() {
10+
// Toggle the LED using delay
11+
digitalWrite(LED_BUILTIN, LOW);
12+
delay(1000); // Delay for 1000 milliseconds (1 second)
13+
digitalWrite(LED_BUILTIN, HIGH);
14+
delay(1000); // Delay for 1000 milliseconds (1 second)
15+
16+
// Toggle the LED using delayMicroseconds
17+
digitalWrite(LED_BUILTIN, LOW);
18+
delayMicroseconds(500000); // Delay for 500000 microseconds (0.5 seconds)
19+
digitalWrite(LED_BUILTIN, HIGH);
20+
delayMicroseconds(500000); // Delay for 500000 microseconds (0.5 seconds)
21+
}
22+
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
void setupGPIO() {
28+
XMC_GPIO_CONFIG_t gpio_config;
29+
30+
gpio_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
31+
gpio_config.output_level = XMC_GPIO_OUTPUT_LEVEL_LOW;
32+
gpio_config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM;
33+
XMC_GPIO_Init(mapping_port_pin[LED_BUILTIN].port, mapping_port_pin[LED_BUILTIN].pin, &gpio_config);
34+
}
35+
36+
void digitalWrite(pin_size_t pin, PinStatus value) {
37+
XMC_GPIO_SetOutputLevel(mapping_port_pin[pin].port, mapping_port_pin[pin].pin,
38+
(value == LOW) ? XMC_GPIO_OUTPUT_LEVEL_LOW
39+
: XMC_GPIO_OUTPUT_LEVEL_HIGH);
40+
}
41+
42+
#ifdef __cplusplus
43+
}
44+
#endif

0 commit comments

Comments
 (0)