Sunday, September 19, 2010

My first integrated circuit

It's really hard to put down a toy. The arduino is no exception, and the projects from oomlout are so easy to do. Put those two together and you've got the start of an addiction.

The CIRC05 project is the first to use an integrated circuit. It works by throwing a latch to tell the integrated circuit to receive data, then sending the data, finally releasing the latch at which point the data is displayed. The data being sent is an 8 bit number, each bit of the number corresponds to a pin. When a bit is set the pin is high (the LED is on), when a bit is clear the pin is low (the LED is off.)

I'm still learning about basic electricity and electronics, so I followed the wiring layout (pdf link) without any variation. I did want to continue playing around with the layout. To do that the source needed some modifications, allowing subsequent projects with the same layout to require minimal work.

First the original in action:


This is the modified version of the oomlout source, subsequent projects will provide unique get_pin_value() and get_delay_ms() functions. By modifying these two functions the LED behavior is easily varied.
#define PIN_DATA 2
#define PIN_CLOCK 3
#define PIN_LATCH 4

#define DELAY_MS 150

void setup() {
    pinMode(PIN_DATA, OUTPUT);
    pinMode(PIN_CLOCK, OUTPUT);
    pinMode(PIN_LATCH, OUTPUT);
}

void loop() {
    static int pin_value = 0;
    static int delay_ms;

    pin_value = get_pin_value(pin_value);
    delay_ms = get_delay_ms(pin_value);

    updateLEDs(pin_value);
    delay(delay_ms);
}

void updateLEDs(int value) {
    /* Pull the chip latch low */
    digitalWrite(PIN_LATCH, LOW);
    /* Puts the bits into the shift register */
    shiftOut(PIN_DATA, PIN_CLOCK, MSBFIRST, value);
    /* Pulls the latch high, displaying the data */
    digitalWrite(PIN_LATCH, HIGH);
}

int get_pin_value(int i) {
    if (i == 255) {
 return (0);
    }
    return (++i);
}

int get_delay_ms(int i) {
    return (DELAY_MS);
}

The first modification was to make the LEDs light up sequentially.



The get_pin_value() and get_delay_ms() functions follow
int get_pin_value(int i) {
  if (i == 0 || i > 128) {
    return 1;
  }

  return (i*2);
}

int get_delay_ms(int i) {
    return (150);
}

The second modification was to light the LEDs sequentially keeping the previously lit LEDs on.



The get_pin_value() function is only marginally more complex, get_delay_ms() is unchanged
int get_pin_value(int i) {
    if (i == 0 || i > 255) {
        return 1;
    }

    return (i * 2 + 1);
}

int get_delay_ms(int i) {
    return (DELAY_MS);
}

The third modification was to light LEDs randomly, and delay randomly between displaying the values. This is my favorite.



The get_pin_value() and get_delay_ms() functions are simplistic.

int get_pin_value(int i) {
    /* In setup randomSeed(analogRead(0)); */
    return random(0, 256);
}

int get_delay_ms(int i) {
    return random(50, 200);
}

I am having a hard time putting this toy away, luckily I'm getting tired. Maybe I'll play with inputs tomorrow...

No comments:

Post a Comment