init repository
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
# Generated Cmake Pico project file
|
||||
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_C_COMPILER "/home/romain/Downloads/pico-sdk/toolchain/riscv/bin/riscv32-unknown-elf-gcc")
|
||||
|
||||
# Pull in Raspberry Pi Pico SDK (must be before project)
|
||||
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
|
||||
|
||||
project(simple_led C CXX ASM)
|
||||
|
||||
# Initialise the Raspberry Pi Pico SDK
|
||||
pico_sdk_init()
|
||||
|
||||
# Add executable. Default name is the project name, version 0.1
|
||||
|
||||
add_executable(simple_led main.c )
|
||||
|
||||
pico_set_program_name(simple_led "simple_led")
|
||||
pico_set_program_version(simple_led "0.1")
|
||||
|
||||
# Modify the below lines to enable/disable output over UART/USB
|
||||
pico_enable_stdio_uart(simple_led 0)
|
||||
pico_enable_stdio_usb(simple_led 1)
|
||||
|
||||
# Add the standard library to the build
|
||||
target_link_libraries(simple_led
|
||||
pico_stdlib)
|
||||
|
||||
# Add the standard include files to the build
|
||||
target_include_directories(simple_led PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
pico_add_extra_outputs(simple_led)
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef LED_DELAY_MS
|
||||
#define LED_DELAY_MS 250
|
||||
#endif
|
||||
|
||||
#define GPIO_15 15
|
||||
#define GPIO_13 13
|
||||
|
||||
void pico_led_init(void) {
|
||||
#ifdef PICO_DEFAULT_LED_PIN
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||
#endif
|
||||
|
||||
gpio_init(GPIO_15);
|
||||
gpio_set_dir(GPIO_15, GPIO_OUT);
|
||||
}
|
||||
|
||||
void blink_led(void) {
|
||||
pico_led_init();
|
||||
|
||||
while (true) {
|
||||
gpio_put(GPIO_15, false);
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, true);
|
||||
|
||||
sleep_ms(LED_DELAY_MS);
|
||||
|
||||
gpio_put(GPIO_15, true);
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, false);
|
||||
|
||||
sleep_ms(1000);
|
||||
}
|
||||
}
|
||||
|
||||
enum button_state {OFF, ON};
|
||||
|
||||
typedef struct state state;
|
||||
struct state {
|
||||
int counter;
|
||||
int bs;
|
||||
bool can_incr;
|
||||
};
|
||||
|
||||
static state global_state = (state) {
|
||||
.counter = 0,
|
||||
.can_incr = true
|
||||
};
|
||||
|
||||
void incr_counter(state *s) {
|
||||
if (s != NULL) {
|
||||
if (s->can_incr) {
|
||||
s->counter++;
|
||||
s->can_incr = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void set_can_incr(state *s, bool v) {
|
||||
if (s != NULL) {
|
||||
s->can_incr = v;
|
||||
}
|
||||
}
|
||||
|
||||
bool can_push(state *s) {
|
||||
if (s != NULL)
|
||||
return s->counter <= 10;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
gpio_init(GPIO_15);
|
||||
gpio_set_dir(GPIO_15, GPIO_OUT);
|
||||
|
||||
gpio_init(GPIO_13);
|
||||
gpio_set_dir(GPIO_13, GPIO_IN);
|
||||
|
||||
while (1) {
|
||||
// return low level when the button is pressed
|
||||
if (!gpio_get(GPIO_13)) {
|
||||
sleep_ms(20); // avoid "bounce" phenomenon (buffeting)
|
||||
if (!gpio_get(GPIO_13)) {
|
||||
incr_counter(&global_state);
|
||||
if (can_push(&global_state))
|
||||
gpio_put(GPIO_15, true);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
set_can_incr(&global_state, true);
|
||||
gpio_put(GPIO_15, false);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user