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:
- 2:968db132481b
- Parent:
- 0:fb6bbc10ffa0
--- a/main.cpp Sun Jan 01 20:57:57 2012 +0000
+++ b/main.cpp Sat Jan 04 12:34:04 2020 +0000
@@ -1,12 +1,51 @@
-#include "mbed.h"
+ #include "mbed.h"
+// Function prototypes
+extern "C" int asm_sort(int numbers[16], int size);
+extern "C" int my_leds(int value);
-DigitalOut myled(LED1);
+void c_sort (int numbers[16], int size){
+ int temp;
+ for (int out_count = 0; out_count <= size - 2; out_count++){
+ for (int in_count = 0; in_count <= size - 2 - out_count; in_count++){
+ if (numbers[in_count] > numbers[in_count + 1]){
+ temp = numbers[in_count];
+ numbers[in_count] = numbers[in_count + 1];
+ numbers[in_count + 1] = temp;
+ }
+ }
+ }
+}
+
+// Declare LED outputs
+DigitalOut myled1(LED1);
+DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
+DigitalOut myled4(LED4);
+// Set up array to sort
+const int size = 16;
+int numbers[size] = {12, 11, 14, 10, 9, 8, 22, 7, 6, 5, 15, 4, 3, 2, 0, 1};
int main() {
- while(1) {
- myled = 1;
- wait(0.2);
- myled = 0;
- wait(0.2);
+ // Show current array contents and set lights to "before" pattern
+
+ printf("Before\n\r");
+ for(int index = 0; index <= size-1; index++){
+ printf("%d, ", numbers[index]);
+ my_leds(numbers[index]);
+ wait(0.5);
}
-}
+
+ // Call the sort function, comment out the one not being used
+ asm_sort(numbers, size); // Call to assembly sort
+ //c_sort(numbers, size); // Call to driver test stub
+
+ printf("\n\rAfter\n\r");
+
+ for(int index = 0; index <= size-1; index++){
+ printf("%d, ", numbers[index]);
+ my_leds(numbers[index]);
+ wait(0.5);
+ }
+
+ while(1) {}
+}
\ No newline at end of file