HelloWorld test for Nucleo boards, prior to adding ACKme Wi-Fi shield. Verifies operation of terminal, User LED and User Button.

Dependencies:   mbed

Committer:
neale
Date:
Mon Oct 20 03:59:27 2014 +0000
Revision:
0:a4e185cb0718
Add files from original ACKme_HelloWorld program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
neale 0:a4e185cb0718 1 /**
neale 0:a4e185cb0718 2 * @example ACKme_HelloWorld/main.cpp
neale 0:a4e185cb0718 3 *
neale 0:a4e185cb0718 4 * This example program verifies the operation of key features of the Nucleo board,
neale 0:a4e185cb0718 5 * without the ACKme shield installed.
neale 0:a4e185cb0718 6 * It blinks the Nucleo board user LED,
neale 0:a4e185cb0718 7 * It increases the blink rate when you press the User button.
neale 0:a4e185cb0718 8 * It prints to a serial terminal connected to the USB port
neale 0:a4e185cb0718 9 * and echoes characters entered at the terminal.
neale 0:a4e185cb0718 10 * It responds, with a message, to typing 'hi <Enter>' at the terminal.
neale 0:a4e185cb0718 11 *
neale 0:a4e185cb0718 12 */
neale 0:a4e185cb0718 13
neale 0:a4e185cb0718 14 #include "mbed.h"
neale 0:a4e185cb0718 15 // include C library headers
neale 0:a4e185cb0718 16 #include <stdio.h> // printf
neale 0:a4e185cb0718 17 #include <ctype.h> // tolower
neale 0:a4e185cb0718 18 #define ASCII_ESC 27
neale 0:a4e185cb0718 19
neale 0:a4e185cb0718 20 InterruptIn myButton(USER_BUTTON);
neale 0:a4e185cb0718 21 static Serial consoleSerial(STDIO_UART_TX, STDIO_UART_RX);
neale 0:a4e185cb0718 22 PwmOut myLed(LED1);
neale 0:a4e185cb0718 23
neale 0:a4e185cb0718 24 double defaultPeriod = 1.0f; // 1 second period
neale 0:a4e185cb0718 25 double defaultPulseWidth = defaultPeriod/2.0; // 1/2 second pulse (on)
neale 0:a4e185cb0718 26
neale 0:a4e185cb0718 27 double quickPeriod = 0.1f; //
neale 0:a4e185cb0718 28 double quickPulseWidth = quickPeriod/2.0;
neale 0:a4e185cb0718 29
neale 0:a4e185cb0718 30 void pressed()
neale 0:a4e185cb0718 31 {
neale 0:a4e185cb0718 32 myLed.period(quickPeriod);
neale 0:a4e185cb0718 33 myLed.pulsewidth(quickPulseWidth);
neale 0:a4e185cb0718 34 }
neale 0:a4e185cb0718 35 void released()
neale 0:a4e185cb0718 36 {
neale 0:a4e185cb0718 37 myLed.period(defaultPeriod);
neale 0:a4e185cb0718 38 myLed.pulsewidth(defaultPulseWidth);
neale 0:a4e185cb0718 39 }
neale 0:a4e185cb0718 40
neale 0:a4e185cb0718 41 int main() {
neale 0:a4e185cb0718 42 // specify period first, then everything else
neale 0:a4e185cb0718 43 char c;
neale 0:a4e185cb0718 44 char c0 = ' ';
neale 0:a4e185cb0718 45 char c1 = ' ';
neale 0:a4e185cb0718 46 char c2 = ' ';
neale 0:a4e185cb0718 47
neale 0:a4e185cb0718 48 released();
neale 0:a4e185cb0718 49 myButton.fall(&pressed);
neale 0:a4e185cb0718 50 myButton.rise(&released);
neale 0:a4e185cb0718 51
neale 0:a4e185cb0718 52 consoleSerial.baud(115200); // console terminal to 115200 baud
neale 0:a4e185cb0718 53
neale 0:a4e185cb0718 54 printf( "%c[2J", ASCII_ESC ); // clear screen
neale 0:a4e185cb0718 55 printf("\r\nHello World!\r\n...from ACKme Networks\r\n\r\n");
neale 0:a4e185cb0718 56
neale 0:a4e185cb0718 57 printf("This app verifies some features of your Nucleo board.\r\n");
neale 0:a4e185cb0718 58 printf("Verify that the user LED (LD2 on the Nucleo F401RE) is blinking.\r\n");
neale 0:a4e185cb0718 59 printf("When you hold down the user button, the user LED blinks faster.\r\n");
neale 0:a4e185cb0718 60 printf("Characters you type on the terminal console are echoed.\r\n\r\n");
neale 0:a4e185cb0718 61 printf("Type 'hi <Enter>' for a greeting.\r\n");
neale 0:a4e185cb0718 62
neale 0:a4e185cb0718 63 while(1) {
neale 0:a4e185cb0718 64 if (consoleSerial.readable()){
neale 0:a4e185cb0718 65 c = consoleSerial.getc(); //Read data from serial console
neale 0:a4e185cb0718 66 consoleSerial.printf("%c",c);
neale 0:a4e185cb0718 67 c0 = c1;
neale 0:a4e185cb0718 68 c1 = c2;
neale 0:a4e185cb0718 69 c2 = tolower(c);
neale 0:a4e185cb0718 70 if ((c0 == 'h') && (c1 == 'i') && ((c2 == '\n') || (c2 == '\r'))){
neale 0:a4e185cb0718 71 printf("\r\n\r\nHello!");
neale 0:a4e185cb0718 72 printf("\r\nYou have successfully programmed your Nucleo board.");
neale 0:a4e185cb0718 73 printf("\r\nNow turn off power to the board, and install");
neale 0:a4e185cb0718 74 printf("\r\nthe ACKme AMW006-A02 (Mantis) Wi-Fi shield.");
neale 0:a4e185cb0718 75 }
neale 0:a4e185cb0718 76 }
neale 0:a4e185cb0718 77 }
neale 0:a4e185cb0718 78 }