Charles Tritt / Mbed 2 deprecated NoHeaderTest

Dependencies:   mbed

Fork of HeaderTest by Charles Tritt

Committer:
CSTritt
Date:
Fri Oct 20 01:22:53 2017 +0000
Revision:
1:362abfaa2a27
Parent:
0:cc014c610423
Initial version. A blink example with all code in one file. Compare to HeaderTest.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CSTritt 0:cc014c610423 1 /*
CSTritt 1:362abfaa2a27 2 Project: NoHeaderTest
CSTritt 0:cc014c610423 3 File: main.cpp
CSTritt 0:cc014c610423 4 Last revised by: Dr. C. S. Tritt
CSTritt 0:cc014c610423 5 Last revision on: 9/19/17 (v. 1.0)
CSTritt 0:cc014c610423 6
CSTritt 1:362abfaa2a27 7 Repeatedly toggles on-board LED. Demonstrates single file project approach.
CSTritt 0:cc014c610423 8
CSTritt 0:cc014c610423 9 This example code is in the public domain.
CSTritt 0:cc014c610423 10 */
CSTritt 0:cc014c610423 11 // Use #include directives to "paste" text from other files into your code.
CSTritt 0:cc014c610423 12 // Use this #include to declare all the mbed driver classes. The mbed library
CSTritt 0:cc014c610423 13 // must also be added to the project either by importing it or by "Fixing" the
CSTritt 0:cc014c610423 14 // error that is generated when it has not been imported.
CSTritt 0:cc014c610423 15 #include "mbed.h"
CSTritt 1:362abfaa2a27 16
CSTritt 0:cc014c610423 17 // Mbed driver class objects are typically declared and defined as global.
CSTritt 0:cc014c610423 18 DigitalOut board_LED(LED1);
CSTritt 1:362abfaa2a27 19
CSTritt 0:cc014c610423 20 const float BASE_WAIT = 0.1;
CSTritt 0:cc014c610423 21 int cycles = 1;
CSTritt 1:362abfaa2a27 22
CSTritt 1:362abfaa2a27 23 void myStuff(void); // Declared here, defined after main.
CSTritt 1:362abfaa2a27 24
CSTritt 0:cc014c610423 25 /* The "main" function defines your main program -- it executes as soon as
CSTritt 0:cc014c610423 26 you program the board.
CSTritt 0:cc014c610423 27 */
CSTritt 0:cc014c610423 28 int main() { // This curly brace marks the beginning of the main function.
CSTritt 0:cc014c610423 29 board_LED = 0; // Initialize LED state (not necessary in this case).
CSTritt 0:cc014c610423 30 while(true) { // while(true) repeat forever.
CSTritt 0:cc014c610423 31 myStuff(); // Call function that is in its own file.
CSTritt 0:cc014c610423 32 if (cycles == 11) { // Reset cycles after 10 of them.
CSTritt 0:cc014c610423 33 cycles = 1;
CSTritt 0:cc014c610423 34 }
CSTritt 0:cc014c610423 35 }
CSTritt 1:362abfaa2a27 36 }
CSTritt 1:362abfaa2a27 37
CSTritt 1:362abfaa2a27 38 void myStuff(void) {
CSTritt 1:362abfaa2a27 39 board_LED = !board_LED; // Toggle LED state.
CSTritt 1:362abfaa2a27 40 wait(BASE_WAIT * (float) cycles); // Wait varying intervals.
CSTritt 1:362abfaa2a27 41 cycles++; // Slowly slow down flash rate.
CSTritt 0:cc014c610423 42 }