// file: pico.c // author: KLL /* * * */ /* * CMakeLists.txt // _____________________________ please make this file in your 'project' directory with following content: cmake_minimum_required(VERSION 3.12) #include(pico_sdk_import.cmake) include(~/pico/pico-sdk/external/pico_sdk_import.cmake) project(project) pico_sdk_init() # cross compile a c++ code for the Raspberry Pi PICO RP2040 cpu add_executable(pico pico.c) # Pull in our pico_stdlib which pulls in commonly used features target_link_libraries(pico pico_stdlib ) # enable usb output, disable uart output pico_enable_stdio_usb(pico 1) pico_enable_stdio_uart(pico 0) # create map/bin/hex/uf2 file etc. pico_add_extra_outputs(pico) */ #include #include "pico/stdlib.h" bool DIAG = true; //false; //____________________ code testing print enable //_______________________________________________ pre compiler text macro: replace all 'dp' with 'if(DIAG) printf' #define dp if(DIAG) printf // LED const uint LED_PIN = 25; bool LED_stat = false; void LED_toggle() { LED_stat = !LED_stat; //_____________________ toggle if ( LED_stat ) { gpio_put(LED_PIN, 1); dp(" LED ON \n"); } else { gpio_put(LED_PIN, 0); dp(" LED OFF\n"); } } int ser0() { //__________________________________ check for operator input / not in every loop int c_usb = getchar_timeout_us(0); //________ OPERATION switch(c_usb) { case 'd': //_____________________________ toggle print debug info DIAG = !DIAG; if (DIAG) printf("diag print enabled, press 'd'\n"); if (!DIAG) printf("diag print disabled, press 'd'\n"); break; default: ;//printf("what was that?"); } } int loop=0; //___________________________________ Mloop variables uint64_t omicros=0,nmicros=0; int reportMloop() { //___________________________ Time for 1 Million loops loop++; if ( loop >= 1000000 ) { loop = 0; nmicros = time_us_64(); dp("Mloop: %0.1f ms \n",(nmicros-omicros)/1000.0); omicros = nmicros; LED_toggle(); //_________________________ BLINK on board LED ser0(); //_______________________________ check on OPERATOR ( USB input 'd' ) } } int setup() { stdio_init_all(); gpio_init(LED_PIN); gpio_set_dir(LED_PIN, GPIO_OUT); dp("i am PICO"); //__________________________ never see this one //___________________________________________ here should be your USER SETUP } int main() { setup(); //__________________________________ SETUP while (1) { //_______________________________ LOOP reportMloop(); //________________________ prints: Mloop: 194.0 ms //_______________________________________ here should be your USER CODE } } // ______________________________________________ END