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.
Revision 1:1286125a89ba, committed 2013-10-17
- Comitter:
- amx_192
- Date:
- Thu Oct 17 02:07:19 2013 +0000
- Parent:
- 0:2a6f2b9e790d
- Commit message:
- This is the HW#1
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Oct 12 20:34:07 2013 +0000 +++ b/main.cpp Thu Oct 17 02:07:19 2013 +0000 @@ -1,38 +1,110 @@ +/* Program: Bootcamp-HelloWorld_LED_Count.cpp + * Author: Max Amani + * Description:This program uses the LCP1768 Microcontroller 4 LEDs to count up from 0 to 15 and reset to 0 + * When a pin connected to the LED is high, the LED lights up + */ #include "mbed.h" -DigitalOut red(LED1); -DigitalOut blue(LED2); -DigitalOut green(LED3); -DigitalOut yellow(LED4); +#define MAX_COUNT 16 + +BusOut busLeds (LED4,LED3,LED2,LED1); + +//PROTOTYPES +void delay(void); +void displayCount(const unsigned char hex); + int main() { - int count[16][4] = {{0,0,0,1},{0,0,1,0},{0,0,1,1},{0,1,0,0}, - {0,1,0,1},{0,1,1,0},{0,1,1,1},{1,0,0,0}, - {1,0,0,1},{1,0,1,0},{1,0,1,1},{1,1,0,0}, - {1,1,0,1},{1,1,1,0},{1,1,1,1},{0,0,0,0}}; + + int i; while(1) { - int i; - int j; - for ( i = 0 ; i < 16 ; i++ ) - { - for ( j = 0 ; j < 4 ; ) - { - red = count[i][j]; - printf("%c\n",count[i][j]); - blue = count[i][j+1]; - printf("%c",count[i][j+1]); - green = count[i][j+2]; - printf("%c",count[i][j+2]); - yellow = count[i][j+3]; - printf("%c",count[i][j+3]); - wait(3.0); - } - - } - //red = blue = green = yellow = 0; - //wait(1.0); - //red = 1; - //blue = green = yellow = 0; - //myled = 0; - //wait(0.2); + + for ( i = 0 ; i < MAX_COUNT ; i++ ) + { + + switch (i){ + case 0: busLeds = ~0xF; + displayCount(0x0); + delay(); + break; + case 1: busLeds = 0x1; + displayCount(0x1); + delay(); + break; + case 2: busLeds = 0x2; + displayCount(0x2); + delay(); + break; + case 3: busLeds = 0x3; + displayCount(0x3); + delay(); + break; + case 4: busLeds = 0x4; + displayCount(0x4); + delay(); + break; + case 5: busLeds = 0x5; + displayCount(0x5); + delay(); + break; + case 6: busLeds = 0x6; + displayCount(0x6); + delay(); + break; + case 7: busLeds = 0x7; + displayCount(0x7); + delay(); + break; + case 8: busLeds = 0x8; + displayCount(0x8); + delay(); + break; + case 9: busLeds = 0x9; + displayCount(0x9); + delay(); + break; + case 10: busLeds = 0xA; + displayCount(0xA); + delay(); + break; + case 11: busLeds = 0xB; + displayCount(0xB); + delay(); + break; + case 12: busLeds = 0xC; + displayCount(0xC); + delay(); + break; + case 13: busLeds = 0xD; + displayCount(0xD); + delay(); + break; + case 14: busLeds = 0xE; + displayCount(0xE); + delay(); + break; + case 15: busLeds = 0xF; + displayCount(0xF); + delay(); + break; + } + } + } +} +// delay function +void delay(){ + wait(1.0); +} +//Function that convert a hex number into a binary and append 'b' at the end +void displayCount(const unsigned char hex){ + + unsigned char i , c = hex; // hex value to convert in binary + unsigned char Mask = 1 << 3; // Mask value is set to 8 = 2^(n-1) = 1<< 3 . + // Number of bits in the binary value + for ( i = 1 ; i <= 4 ; i++ ) + { + putchar(c & Mask ? '1' : '0'); + c <<= 1; } -} + putchar('b'); + putchar('\n'); +} \ No newline at end of file