First version. Demo of PWM setup and speaker operation. Fine grain control of the PWM parameters is an advantage Mbed has over the Arduino environment.
main.cpp@108:eee3167b25b4, 2021-09-21 (annotated)
- Committer:
- CSTritt
- Date:
- Tue Sep 21 02:00:55 2021 +0000
- Revision:
- 108:eee3167b25b4
- Parent:
- 107:61b9c99a4e27
- Child:
- 109:86a37f0a397f
Initial 2021 mbed 5 version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CSTritt | 107:61b9c99a4e27 | 1 | /* |
CSTritt | 108:eee3167b25b4 | 2 | Project: BinaryCount |
CSTritt | 108:eee3167b25b4 | 3 | File: main.cpp |
CSTritt | 108:eee3167b25b4 | 4 | |
CSTritt | 108:eee3167b25b4 | 5 | Displays 8 bit binary count on bar graph display. |
CSTritt | 108:eee3167b25b4 | 6 | |
CSTritt | 108:eee3167b25b4 | 7 | Written by: Dr. C. S. Tritt |
CSTritt | 108:eee3167b25b4 | 8 | Created: 9/20/21 (v. 1.2) |
CSTritt | 107:61b9c99a4e27 | 9 | */ |
Jonathan Austin |
0:2757d7abb7d9 | 10 | #include "mbed.h" |
CSTritt | 108:eee3167b25b4 | 11 | |
CSTritt | 108:eee3167b25b4 | 12 | BusOut barGraph(D2, D3, D4, D5, D6, D7, D8, D9); // Create BusOut object. |
CSTritt | 108:eee3167b25b4 | 13 | |
CSTritt | 108:eee3167b25b4 | 14 | int main() { |
CSTritt | 108:eee3167b25b4 | 15 | // Test the wiring. |
CSTritt | 108:eee3167b25b4 | 16 | barGraph = 0; // All bars off (base 10). |
CSTritt | 108:eee3167b25b4 | 17 | ThisThread::sleep_for(400); // For 0.4 seconds. |
CSTritt | 108:eee3167b25b4 | 18 | barGraph = 0b01010101; // Odd bars on (binary). |
CSTritt | 108:eee3167b25b4 | 19 | ThisThread::sleep_for(400); // Test even bars for 0.4 seconds. |
CSTritt | 108:eee3167b25b4 | 20 | barGraph = 0b10101010; // Even bars on (binary). |
CSTritt | 108:eee3167b25b4 | 21 | ThisThread::sleep_for(400); // Test even bars for 0.4 seconds. |
CSTritt | 108:eee3167b25b4 | 22 | barGraph = 0xFF; // All bars on. Hex. |
CSTritt | 108:eee3167b25b4 | 23 | ThisThread::sleep_for(400); // For 0.4 seconds. |
CSTritt | 108:eee3167b25b4 | 24 | // Enter main loop. |
CSTritt | 108:eee3167b25b4 | 25 | while(true) { |
CSTritt | 108:eee3167b25b4 | 26 | for (int i = 0; i < 256; i++) { // Add one to count. |
CSTritt | 108:eee3167b25b4 | 27 | barGraph = i; // Copy the count to the bargraph. |
CSTritt | 108:eee3167b25b4 | 28 | ThisThread::sleep_for(100); // Display the value for 0.1 seconds. |
CSTritt | 108:eee3167b25b4 | 29 | } |
CSTritt | 108:eee3167b25b4 | 30 | } |
CSTritt | 108:eee3167b25b4 | 31 | } |