RoboCup Base Station

Dependencies:   mbed mbed-rtos Wireless Drivers

main.cpp

Committer:
jjones646
Date:
2014-12-31
Revision:
0:a606cf2249ad
Child:
1:e5373c63f642

File content as of revision 0:a606cf2249ad:

// Cycle through a 7-segment LCD display

#include "mbed.h"

// Outputs used as input values to the 7-segment binary decoder
DigitalOut signal[4] = {p17, p18, p19, p20};

// For latching the 7 segment led's output
DigitalOut latch(p16);

// To show that the mbed is running
DigitalOut status_led(LED1);

// Function for writing a number to the 7-segment display
void writeSegment(uint8_t val)
{
    // write out the new value
    for (int i=0; i<4; i++)
        signal[i] = ((1<<i) & (val)) & 0x0F;

    // latch the value
    for (int i=0; i<2; i++)
        latch = !latch;
}

int main()
{
    latch = 0;  // initialize the latch pin for the CD4511B decoder
    status_led = 0; // initialize & turn off led for startup operations

    uint8_t channel;    // limit to 4 bits (0x00 to 0x0F)
    channel = 8;    // light up all of the 7-segment's segments at startup - allows for the user to detect if there's a problem
    writeSegment(channel);
    wait(1.0);  // wait 2 seconds to ensure user sees the startup operation

    channel = 0;    // start back over at 0

    while(1) {
        // send numerical value to 7-segment & hold for a while
        writeSegment(channel++);
        wait(0.3);
        status_led = !status_led;
        
        // wait again just so that the status led and segment are out of sync
        wait(0.2);
        
        // reset value if too high
        channel = channel > 9 ? 0 : channel;
    }
}