HelloWorld test for Nucleo boards, prior to adding ACKme Wi-Fi shield. Verifies operation of terminal, User LED and User Button.
Dependencies: mbed
main.cpp
00001 /** 00002 * @example ACKme_HelloWorld/main.cpp 00003 * 00004 * This example program verifies the operation of key features of the Nucleo board, 00005 * without the ACKme shield installed. 00006 * It blinks the Nucleo board user LED, 00007 * It increases the blink rate when you press the User button. 00008 * It prints to a serial terminal connected to the USB port 00009 * and echoes characters entered at the terminal. 00010 * It responds, with a message, to typing 'hi <Enter>' at the terminal. 00011 * 00012 */ 00013 00014 #include "mbed.h" 00015 // include C library headers 00016 #include <stdio.h> // printf 00017 #include <ctype.h> // tolower 00018 #define ASCII_ESC 27 00019 00020 InterruptIn myButton(USER_BUTTON); 00021 static Serial consoleSerial(STDIO_UART_TX, STDIO_UART_RX); 00022 PwmOut myLed(LED1); 00023 00024 double defaultPeriod = 1.0f; // 1 second period 00025 double defaultPulseWidth = defaultPeriod/2.0; // 1/2 second pulse (on) 00026 00027 double quickPeriod = 0.1f; // 00028 double quickPulseWidth = quickPeriod/2.0; 00029 00030 void pressed() 00031 { 00032 myLed.period(quickPeriod); 00033 myLed.pulsewidth(quickPulseWidth); 00034 } 00035 void released() 00036 { 00037 myLed.period(defaultPeriod); 00038 myLed.pulsewidth(defaultPulseWidth); 00039 } 00040 00041 int main() { 00042 // specify period first, then everything else 00043 char c; 00044 char c0 = ' '; 00045 char c1 = ' '; 00046 char c2 = ' '; 00047 00048 released(); 00049 myButton.fall(&pressed); 00050 myButton.rise(&released); 00051 00052 consoleSerial.baud(115200); // console terminal to 115200 baud 00053 00054 printf( "%c[2J", ASCII_ESC ); // clear screen 00055 printf("\r\nHello World!\r\n...from ACKme Networks\r\n\r\n"); 00056 00057 printf("This app verifies some features of your Nucleo board.\r\n"); 00058 printf("Verify that the user LED (LD2 on the Nucleo F401RE) is blinking.\r\n"); 00059 printf("When you hold down the user button, the user LED blinks faster.\r\n"); 00060 printf("Characters you type on the terminal console are echoed.\r\n\r\n"); 00061 printf("Type 'hi <Enter>' for a greeting.\r\n"); 00062 00063 while(1) { 00064 if (consoleSerial.readable()){ 00065 c = consoleSerial.getc(); //Read data from serial console 00066 consoleSerial.printf("%c",c); 00067 c0 = c1; 00068 c1 = c2; 00069 c2 = tolower(c); 00070 if ((c0 == 'h') && (c1 == 'i') && ((c2 == '\n') || (c2 == '\r'))){ 00071 printf("\r\n\r\nHello!"); 00072 printf("\r\nYou have successfully programmed your Nucleo board."); 00073 printf("\r\nNow turn off power to the board, and install"); 00074 printf("\r\nthe ACKme AMW006-A02 (Mantis) Wi-Fi shield."); 00075 } 00076 } 00077 } 00078 }
Generated on Fri Jul 22 2022 10:06:05 by 1.7.2