Created
March 18, 2019 03:15
-
-
Save andyarvanitis/fe8a3ede6f3f2091d5933ffab48fb629 to your computer and use it in GitHub Desktop.
purescript-native Arduino target blinky ffi (experimental)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <avr/io.h> | |
| #include <util/delay.h> | |
| #include "purescript.h" | |
| FOREIGN_BEGIN( Main ) | |
| exports["blink"] = [](const boxed& n_) -> boxed { | |
| const auto n = unbox<int>(n_); | |
| return [=]() -> boxed { | |
| DDRB |= _BV( PB5 ); // PB5 (D13) is output | |
| for (int i = 0; i < n; i++) { | |
| PINB = _BV( PB5 ); // toggle PB5; | |
| _delay_ms(500); // busy wait, blocking | |
| PINB = _BV( PB5 ); // toggle PB5; | |
| _delay_ms(500); // busy wait, blocking | |
| } | |
| return boxed(); | |
| }; | |
| }; | |
| FOREIGN_END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment