My First but Not Humble Robot Project

2»

Comments

  • mrmamrma Posts: 28
    edited 2014-05-29 - 11:10:45
    Having fun with charlieplexing :smile:

    Do you remember Knight Rider? I was a big fan of the series, most notably the car named KITT. There was a red scanning light in front of the car where the grills are located. Why shouldn't my robot have one?

    You have probably heard of charlieplexing. Well, to put it in a nutshell, it is driving lots of LEDs with only a few pins. To be more specific, n pins can drive n2-n LEDs. Traditional multiplexing takes many more pins to drive the same number of LEDs. I have a few 10-LED bar graph displays waiting for their turn, I can use one of them. According to the formula, I can drive 10 LED with only 4 pins.[In reality 4 pins can drive (n2-n) -> (16-4=12) twelve LEDS].

    Below you will find my Arduino code for charlieplexing, also added a short video to give an idea of my "Knight Rider" light.

    [PHP]//
    // @author mrma - mrma042@gmail.com
    // @copyright Copyfree 2014
    // @brief Charlieplexing using 4 pins to light a 10LED bar graph array
    //

    #define SPEED 30 // the delay in ms between each LED
    #define digPin1 43
    #define digPin2 45
    #define digPin3 47
    #define digPin4 49

    struct led
    {
    byte left;
    byte right;
    };

    // Let's create ten pairs of pins for each single LED light
    struct led leds[10] = { { digPin2, digPin1 },
    { digPin1, digPin2 },
    { digPin2, digPin4 },
    { digPin4, digPin2 },
    { digPin1, digPin4 },
    { digPin4, digPin1 },
    { digPin1, digPin3 },
    { digPin3, digPin1 },
    { digPin4, digPin3 },
    { digPin3, digPin4 } };


    //
    // Turn a single LED on but before turn off all pins to prevent misfires
    //

    void turnLEDon(int myLED) {

    pinMode(digPin1, INPUT);
    pinMode(digPin2, INPUT);
    pinMode(digPin3, INPUT);
    pinMode(digPin4, INPUT);
    delay(1);

    pinMode(leds[myLED].left, OUTPUT);
    pinMode(leds[myLED].right, OUTPUT);
    digitalWrite(leds[myLED].left, HIGH);
    digitalWrite(leds[myLED].right, LOW);
    delay(SPEED);

    }

    //
    // The setup routine runs once at startup or when you press reset
    //

    void setup() {

    }

    //
    // The loop routine runs over and over again forever
    //

    void loop() {

    for (int i=0; i <= 9; i++) {
    turnLEDon(i);
    }

    for (int i=9; i >= 0; i--) {
    turnLEDon(i);
    }

    }

    [/PHP]


    Here are the circuit diagram, and a graph of connections:

    Charlieplex Circuit.jpg
    Charlieplexing1.jpg
    800 x 600 - 171K
    1024 x 885 - 85K
  • ercoerco Posts: 19,719
    edited 2014-05-29 - 14:19:51
    Sweet! Everybody loves blinking LEDs & Knight Rider. Alternatively, use a 74LS154 4-to-16 decoder chip to control 16 LEDs using 4 pins. Here's one I did with a 3-to-8 decoder chip (3 lines driving 8 outputs), 7 LEDs and one 5V beeper.

    https://www.youtube.com/watch?v=sm8K6dI8niA & https://www.youtube.com/watch?v=NMX5kicEoJw
Sign In or Register to comment.