George Hadley / Mbed 2 deprecated Counter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /****************************************************************************************
00002 * Date Created: 2/26/2010
00003 * Title: NBitWonder Binary Counter Code Example
00004 * Description: A binary adder implemented using the mbed embedded development platform.
00005 *       This program utilizes the mbed's 4 onboard leds to represent the value of a 4-bit
00006 *       binary variable. The variable begins at 0 and is incremented once every second.
00007 * Author: George Hadley
00008 * Website: http://nbitwonder.com
00009 ****************************************************************************************/
00010 #include "mbed.h"
00011 
00012 //LED Output initializations
00013 BusOut Bits(LED1,LED2,LED3,LED4); //LED outputs for counter
00014 
00015 char bin_val = 0x00;
00016 int main() {
00017     while(1) {
00018         //increment bin_val, resetting if 4-bit overflow condition occurs
00019         bin_val++;
00020         if(bin_val > 0x0F) 
00021         {
00022             bin_val = 0;
00023         }
00024         //Assign bin_val to led output
00025         Bits = bin_val;
00026         //wait 1 second
00027         wait(1);
00028     }
00029 }