Week 13 - Output Devices

This week our goal is to add an output device to a microcontroller board and program it to do something.

I decided after a bit of exploring to create the 20 LED array output board and to modify the hello.array.44.c program.

I milled the board and set about adding the many small parts to the board. When I finally finished and plugged it into the programmer, it successfully programmed. However, only 2 of the 20 LEDs lit. Boo! I took the heat gun and aimed it at my solder connections. After a bit of reflowing of the solder, I now had 18 of the 20 LEDs working. Closer examination of the remaining LEDs and their connections allowed me to fix the soldering on them and it gave me a working board.

I began by modifying the variables in the led_cycle() Changing the first value modifies the number of blinks and changing the second value modifies the duration of each blink. If the second value is small enough (and the first sufficiently large) this will create the illusion of a persistent image in our vision. Instead of seeing the pattern trace through the LEDs, instead it appears to be continuously lit.

void led_cycle(uint8_t number, uint8_t delay) {
   //
   // cycle through LEDs
   //
   uint8_t i;
   for (i = 0; i < number; ++i) {
      flash(B,A,delay);
      flash(C,A,delay);
      flash(D,A,delay);
      flash(E,A,delay);
      flash(A,B,delay);
      flash(C,B,delay);
      flash(D,B,delay);
      flash(E,B,delay);
      flash(A,C,delay);
      flash(B,C,delay);
      flash(D,C,delay);
      flash(E,C,delay);
      flash(A,D,delay);
      flash(B,D,delay);
      flash(C,D,delay);
      flash(E,D,delay);
      flash(A,E,delay);
      flash(B,E,delay);
      flash(C,E,delay);
      flash(D,E,delay);
      }
   }

By commenting out parts of the led_cycle() we can skip the step that lights the particular LED that the charlieplex would select. With a bit of trial and error, we can spell out characters or pictures. I created the first 6 letters of the alphabet and set them on repeat.

void led_cycle_a(uint8_t number, uint8_t delay) {
   //
   // cycle through Letter A
   //
   uint8_t i;
   for (i = 0; i < number; ++i) {
      //flash(B,A,delay);
      flash(C,A,delay);
      flash(D,A,delay);
      //flash(E,A,delay);
      flash(A,B,delay);
      //flash(C,B,delay);
      //flash(D,B,delay);
      flash(E,B,delay);
      flash(A,C,delay);
      flash(B,C,delay);
      flash(D,C,delay);
      flash(E,C,delay);
      flash(A,D,delay);
      //flash(B,D,delay);
      //flash(C,D,delay);
      flash(E,D,delay);
      flash(A,E,delay);
      //flash(B,E,delay);
      //flash(C,E,delay);
      flash(D,E,delay);
      }
   }

I then decided to make a program that gives a random letter grade (A,B,C,D,F). I used

    
      while (1) {
      led_cycle(10,10);
      int x = rand(0)%5;
      switch (x) {
            case 0:
                 led_cycle_a(50,1);
                 break;
            case 1:
                 led_cycle_b(50,1);
                 break;
            case 2:
                 led_cycle_c(50,1);
                 break;
            case 3:
                 led_cycle_d(50,1);
                 break;
            case 4:
                 led_cycle_f(50,1);
                 break;
            default:
                 led_cycle_e(50,1);
                 break; 
to create a random value between 0 and 4 and then used this value to select the appropriate letter grade. It returns a value of the letter e if it does not work correctly. This happened a bit at first until I got the code correct. Now it works fine and is relatively random, but I did not seed the random generator, so it will repeat the same pattern every time the program starts over. If I really wanted a random grader, I would need to include that in the program. (But really, who wants a random grader?)

Download the (modified) program: hello.array.44.c

back to index