I got to admit that I liked the challenge presented here, since I am still playing around with C (I code in assembler most of the time). Here is working code that makes use of Ceri's suggestion:
#include "mbed.h"
BusOut LedDisplay (LED1, LED2, LED3, LED4);
unsigned int i;
int nDisplay[100]={ // set number in array
8,4,2,1,8,4,2,1,8,4, // 1: 0 - 09 light display
2,1,8,4,2,1,0,15,6,9, // 2: 10 - 19 light display
6,15,0,1,2,4,8,1,2,4, // 3: 20 - 29 light display
8,1,2,4,8,1,2,4,8,0, // 4: 30 - 39 light display
15,6,9,6,9,6,15,0,8,12, // 5: 40 - 49 light display
14,15,3,3,1,0,1,3,3,15, // 6: 50 - 59 light display
14,12,8,0,15,9,6,9,15,15, // 7: 60 - 69 light display
3,3,1,8,12,14,15,0,14,13, // 8: 70 - 79 light display
11,3,14,12,8,0,15,8,12,14, // 9: 80 - 89 light display
15,3,11,13,14,15,6,13,11,15}; //10: 90 - 99 light display
int main() {
while (1){
for (int i=0; i<100; i++) { // set i = array number
LedDisplay = nDisplay[i];
wait(0.2);
LedDisplay = 0; // 0.2 sec : all lights off
wait(0.2);
}
}
}
I have been trying to get a user-defined LED display to run on the mbed. I know nothing about anything. And C++ For Dummies has been over my head and not supplying the answers.
What I have today runs nicely, but some light patterns are not being interpretted correctly.
The user writes an array made up of 4-digit values: e.g. 0110 or 1111. A zero represents one of the four LEDs off. A one represents one of the four LEDs on. The digit's position in the number equates to the positon of the LED in the 4-LED display.
Reading other posts this morning, it seems that I need to look into 'parsing' and 'formatting.' Something about '%d."
Any help will be appreciated.
The program is called LED11-Lightshow and a believe it is attached here.
LED11_Lightshow