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.
Dependencies: mbed
Fork of WaG by
display.cpp@7:161fe3793ddb, 2018-02-22 (annotated)
- Committer:
- phn10
- Date:
- Thu Feb 22 02:06:07 2018 +0000
- Revision:
- 7:161fe3793ddb
- Parent:
- 5:92cdff7fb885
- Child:
- 8:d8bc78bda829
remove function bool num_range() because it's no longer necessary.; move all function definitions to .cpp file
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phn10 | 7:161fe3793ddb | 1 | /****************************************************************************** |
phn10 | 7:161fe3793ddb | 2 | * EECS 397 |
phn10 | 7:161fe3793ddb | 3 | * |
phn10 | 7:161fe3793ddb | 4 | * Assignment Name: Lab 4: display_test2 |
phn10 | 7:161fe3793ddb | 5 | * |
phn10 | 7:161fe3793ddb | 6 | * Authors: Sam Morrison and Phong Nguyen |
phn10 | 7:161fe3793ddb | 7 | * File name: display.cpp |
phn10 | 7:161fe3793ddb | 8 | * Purpose: Contain function definitions |
phn10 | 7:161fe3793ddb | 9 | * |
phn10 | 7:161fe3793ddb | 10 | * Created: 02/21/2018 |
phn10 | 7:161fe3793ddb | 11 | * Last Modified: 02/21/2018 |
phn10 | 7:161fe3793ddb | 12 | * |
phn10 | 7:161fe3793ddb | 13 | ******************************************************************************/ |
phn10 | 7:161fe3793ddb | 14 | void mod_bcd(int num) { |
phn10 | 7:161fe3793ddb | 15 | int size = 4; |
phn10 | 7:161fe3793ddb | 16 | int dec_arr[size]; |
phn10 | 7:161fe3793ddb | 17 | int place = 0; |
phn10 | 7:161fe3793ddb | 18 | while (num != 0) { //converts decimal input to decimal array using %mod |
phn10 | 7:161fe3793ddb | 19 | int val = num % 10; |
phn10 | 7:161fe3793ddb | 20 | dec_arr[place] = val; |
phn10 | 7:161fe3793ddb | 21 | num = num/10; |
phn10 | 7:161fe3793ddb | 22 | place++; |
phn10 | 7:161fe3793ddb | 23 | } |
phn10 | 7:161fe3793ddb | 24 | for (int i = 0; i < size; i++) { //converts decimal array to binary array |
phn10 | 7:161fe3793ddb | 25 | bcd[i] = convert(dec_arr[i]); |
phn10 | 7:161fe3793ddb | 26 | } |
phn10 | 7:161fe3793ddb | 27 | } |
phn10 | 7:161fe3793ddb | 28 | |
phn10 | 7:161fe3793ddb | 29 | int convert(int dec) {//convert decimal to binary |
phn10 | 7:161fe3793ddb | 30 | if (dec == 0) //function complete |
phn10 | 7:161fe3793ddb | 31 | return 0; |
phn10 | 7:161fe3793ddb | 32 | else //recursive call until converted |
phn10 | 7:161fe3793ddb | 33 | return (dec % 2 + 10 * convert(dec / 2)); |
phn10 | 7:161fe3793ddb | 34 | } |
phn10 | 7:161fe3793ddb | 35 | |
phn10 | 7:161fe3793ddb | 36 | char to_command(char input, int place) { |
phn10 | 7:161fe3793ddb | 37 | |
phn10 | 7:161fe3793ddb | 38 | } |