Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 108:eee3167b25b4
- Parent:
- 107:61b9c99a4e27
- Child:
- 110:b148a36c9833
diff -r 61b9c99a4e27 -r eee3167b25b4 main.cpp
--- a/main.cpp Mon Sep 20 03:01:02 2021 +0000
+++ b/main.cpp Tue Sep 21 02:00:55 2021 +0000
@@ -1,33 +1,31 @@
/*
- 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.
+ Project: BinaryCount
+ File: main.cpp
+
+ Displays 8 bit binary count on bar graph display.
+
+ Written by: Dr. C. S. Tritt
+ Created: 9/20/21 (v. 1.2)
*/
-// #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
\ No newline at end of file
+
+BusOut barGraph(D2, D3, D4, D5, D6, D7, D8, D9); // Create BusOut object.
+
+int main() {
+ // Test the wiring.
+ barGraph = 0; // All bars off (base 10).
+ ThisThread::sleep_for(400); // For 0.4 seconds.
+ barGraph = 0b01010101; // Odd bars on (binary).
+ ThisThread::sleep_for(400); // Test even bars for 0.4 seconds.
+ barGraph = 0b10101010; // Even bars on (binary).
+ ThisThread::sleep_for(400); // Test even bars for 0.4 seconds.
+ barGraph = 0xFF; // All bars on. Hex.
+ ThisThread::sleep_for(400); // For 0.4 seconds.
+ // Enter main loop.
+ while(true) {
+ for (int i = 0; i < 256; i++) { // Add one to count.
+ barGraph = i; // Copy the count to the bargraph.
+ ThisThread::sleep_for(100); // Display the value for 0.1 seconds.
+ }
+ }
+}
\ No newline at end of file