diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/CMakeLists.txt | 22 | ||||
-rw-r--r-- | examples/keypad_example.cpp | 27 |
2 files changed, 49 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..572df7e --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.12) + +include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake) + +project(keypad_example C CXX ASM) + +pico_sdk_init() + +add_library(keypad ../src/keypad.cpp ../src/keypad.hpp) + +add_executable(keypad_example keypad_example.cpp) + +target_include_directories(keypad_example PUBLIC ../src) + +# Serial output. +pico_add_extra_outputs(keypad_example) + +target_link_libraries(keypad pico_stdlib hardware_gpio) + +target_link_libraries(keypad_example keypad hardware_timer) + +add_compile_options(-O0) diff --git a/examples/keypad_example.cpp b/examples/keypad_example.cpp new file mode 100644 index 0000000..781b808 --- /dev/null +++ b/examples/keypad_example.cpp @@ -0,0 +1,27 @@ +#include <stdio.h> +#include "pico/types.h" +#include "pico/time.h" +#include "pico/stdio.h" +#include "keypad.hpp" + +int main() { + uint col_pins[4] = {6, 7, 8, 9}; + uint row_pins[4] = {16, 17, 18, 19}; + char keypad_chars[4][4] = { + {'1', '2', '3', 'A'}, + {'4', '5', '6', 'B'}, + {'7', '8', '9', 'C'}, + {'*', '0', '#', 'D'} + }; + Keypad keypad(row_pins, col_pins, keypad_chars); + + stdio_init_all(); + + while(true) { + char key = keypad.getKey(); + if(key != '\0') + printf("%c\n", key); + + busy_wait_ms(150); + } +} |