Initial version. Illuminates the LED when the user button is held down. Otherwise, the LED is off. Variation on 21_Button_v5.

main.cpp

Committer:
CSTritt
Date:
2021-09-20
Revision:
107:61b9c99a4e27
Parent:
105:ed03c03b353e
Child:
108:eee3167b25b4

File content as of revision 107:61b9c99a4e27:

/*
  21_myBlink_v5 - Turns on an LED on and off for, repeatedly.
  Last Revised: 9/19/21 (v. 1.0)
  Based on mbed example. Modified by Dr. C. S. Tritt. This example code is in 
  the public domain. 
*/
//  #include is a directive that "pastes" a file into your code.
//  Use this specific #include at the beginning of each mbed program.
//  mbed.h contains/points to the full definitions of our simple statements.
#include "mbed.h"
//  Define the object board_LED to be a digital output connected to LED1,
//  which is the little green LED built into the Nucleo board.
DigitalOut board_LED(LED1);
const int WAIT_ON = 1400; // On time in seconds.
const int WAIT_OFF = 600; // Off time in seconds. 
/*  
    The "main" function defines your main program -- it executes as soon as
    you program the board. Functions can return (compute and give back) a 
    value.  The main function could return an integer error code, so it begins 
    with int. Functions can also accept inputs.  The main function cannot 
    however, so its round parentheses are empty.
*/  
int main() { // This curly brace marks the beginning of the main function.
    // while() will repeat a set of actions as long as the statement inside
    // its round parentheses is true. 1 is the definition of true, so
    // while(1) and while(true) repeat forever. 
    while(true) {   // This curly brace marks the start of the repeated actions.
        board_LED = 1;  // Turn on LED by storing a 1 in board_LED.
        ThisThread::sleep_for(WAIT_ON); // Int value in mS.
        board_LED = 0;  // Turn off LED by storing a 0 in board_LED.
        ThisThread::sleep_for(WAIT_OFF); // Int value in mS.
    }  // end of repeated actions  
}  // end of main function