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
Diff: display.cpp
- Revision:
- 10:ae0a262ba48d
- Parent:
- 9:06c0d5737e5c
- Child:
- 11:6751b9406142
--- a/display.cpp Thu Feb 22 04:20:28 2018 +0000
+++ b/display.cpp Thu Feb 22 16:22:19 2018 +0000
@@ -18,7 +18,9 @@
#include <stdio.h>
#include <string.h>
-int bcd[4];
+#define VERSION1
+//#define VERSION2
+
/*
* void initial_setup(DigitalOut SS, int data_length, int frequency);
@@ -82,8 +84,10 @@
SS = 1;
}
+
+#ifdef VERSION1
/*
- * void mod_bcd(int num);
+ * void bin2bcd_array(int num);
* Description:
*
* Inputs:
@@ -96,20 +100,21 @@
* Globals:
* Returns: void
*/
-void mod_bcd(int num) {
+void bin2bcd_array(int num, char bcd[]) {
int size = 4;
int dec_arr[size];
- int place = 0;
+ int place = 3;
while (num != 0) { //converts decimal input to decimal array using %mod
int val = num % 10;
dec_arr[place] = val;
num = num/10;
- place++;
+ place--;
}
- for (int i = 0; i < size; i++) { //converts decimal array to binary array
+ for (int i = size - 1; i >= 0; i--) { //converts decimal array to binary array
bcd[i] = convert(dec_arr[i]);
}
}
+#endif
/*
* int convert(int dec);
@@ -129,9 +134,10 @@
if (dec == 0) //function complete
return 0;
else //recursive call until converted
- return (dec % 2 + 10 * convert(dec / 2));
+ return (dec % 2 + 10 * convert(dec / 2) + ' ');
}
+#ifdef VERSION2
/*
* void bin2bcd_array(int num);
* Description: converts a number from binary format to binary coded
@@ -145,7 +151,7 @@
* Outputs:
* Returns: void
*/
-void bin2bcd_array(int num, int &bcd) {
+void bin2bcd_array(int num, char bcd[]) {
char tmp_array[4];
sprintf(tmp_array, "%d", num);
@@ -155,6 +161,7 @@
i++;
}
}
+#endif
/*
