7 Segment LED display coding using ROBOTC

I am building a clawbot that can count the number of balls that it picks up and displays the count using 7 segment LED display/s. I am using a limit switch to sense the picking up of balls and an LED driver IC to interface the LED display to the Cortex microcontroller. Can someone please tell me if its easy/feasible to code the 7 segment display to increment by one , everytime the limit switch gets pressed, using ROBOTC?

Any kind of inputs would be very helpful. Thank you so much in advance!

It’s possible to do almost anything that the hardware is capable of with ROBOTC. How have you interfaced the LED driver ic with the cortex and which one are you using?

Thank you so much for replying. This is actually for a competition held at ON Semiconductor and I am supposed to use any of their products along with the VEX kit. So I came up with this LED Driver CAT4008(that ON semiconductor makes) that seemed to match my requirements. Or do you have any suggestions for the kind of LED driver IC that I can use? I was also looking at this option from MAXIM - MAX7219. Both of these support a 4 wire serial interface to connect to the Cortex.

This is like the first robot that I am building and I am very excited about it. And all your help is very much appreciated.

You could use the CAT4008, biggest problem is going to be hooking up the driver to the cortex and LEDs as I don’t see any eval boards available. This chip uses a 4 wire interface, you will need to use a technique called “bit-bang” IO to communicate with it. Use 4 digital outputs on the cortex and create the clock, data and latch signals in code, something like this (untested, example code).

#pragma config(Sensor, dgtl1,  Blank,          sensorDigitalOut)
#pragma config(Sensor, dgtl2,  Latch,          sensorDigitalOut)
#pragma config(Sensor, dgtl3,  Sclk,           sensorDigitalOut)
#pragma config(Sensor, dgtl4,  Sdata,          sensorDigitalOut)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#define   BLANK_LOW     SensorValue( Blank ) = 0
#define   BLANK_HIGH    SensorValue( Blank ) = 1
#define   CLOCK_LOW     SensorValue( Sclk )  = 0
#define   CLOCK_HIGH    SensorValue( Sclk )  = 1
#define   DATA_LOW      SensorValue( Sdata ) = 0
#define   DATA_HIGH     SensorValue( Sdata ) = 1
#define   LATCH_LOW     SensorValue( Latch ) = 0
#define   LATCH_HIGH    SensorValue( Latch ) = 1

void sendData( char data )
    int i;
    // make sure all signals low
    for(i = 0; i< 8; i++ ) {
      // is lsb low or high ?
      if( data & 1 )

      // toggle clock
      // may need small delay
      // next bit
      data = data >> 1;

    // toggle latch
    // may need small delay

task main()
    sendData( 0x55 );
    while(1) wait1Msec(100);

Thank you so much for your reply. Found it very helpful. I just have a small question. I am sorry if its a very trivial question as I am not sure if I am missing something.
for(i = 0; i< 8; i++ ) {
// is lsb low or high ?
if( data & 1 )
DATA_LOW; -----Why is this DATA_LOW? Shouldnt it be DATA_HIGH? (Is it because you are
talking with respect to a common anode 7 segment display? )

Also if I need to display a 2 digit number, I need two 7 segment displays and 2 LED drivers. I can connect the second LED driver to the next 4 digital output pins and make the chip be enabled (BLANK signal) and incremented at one tenth the frequency of the first driver right?

Thank you so much again!

You need a board to hold the chip. I’ve had good success with these boards. https://www.adafruit.com/products/1207 That will let you run wires back to the Cortex and to your chips.

From looking at the spec sheet you should be able to connect the second digit to the shift out of the first digit. So you would shift out 16 bits. Tens digit then the ones digit. You could get clever and wire the blanking pin to the second chip, so if the count is less than 10, the blanking pin keeps the display off.

@jpearman code will turn each segment on in order. You’ll still need to do the binary to seven segment translation.

The MAX7219 does that, and for about $10+ shipping you can get one mounted with the 7 segment LED units in a nice package. (http://www.newegg.com/Product/Product.aspx?Item=9SIA7BF34D7143) It will be some extra work to get it setup to do the binary to 7 Segment (it will do that internally, but you need to set a register bit)

Good luck!

Thank you so much for the detailed coherent answer! Its clear what I need to do next!

Thank you again! :slight_smile:

Perhaps, I didn’t study the datasheet that closely. To be honest, I wrote the code very quickly and didn’t pay too much attention, it was just an example, it may need to be reversed.

Nevertheless thank you so much! I was just reading through the concept of “bit banging” in the morning today and yippee, you gave it me very well explained! :slight_smile:
I am very happy to say that this Forum is extremely helpful.:slight_smile: