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.
main.cpp
- Committer:
- amx_192
- Date:
- 2013-10-17
- Revision:
- 1:1286125a89ba
- Parent:
- 0:2a6f2b9e790d
File content as of revision 1:1286125a89ba:
/* 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" #define MAX_COUNT 16 BusOut busLeds (LED4,LED3,LED2,LED1); //PROTOTYPES void delay(void); void displayCount(const unsigned char hex); int main() { int i; while(1) { 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'); }