Doing it the Hard Way

The Metro makes complex actions very simple. A perfect example of this is shifting and manipulating data. However, one of the nice things about the Metro is that you can adjust the difficulty of what you are trying to achieve. 

In the loop(), switch updateLEDs(i); to updateLEDsLong(i);

Did you notice anything different when you ran it this time?

You shouldn't have! There was no difference in the actions the code took. The code was changed to communicate with the LEDs one bit at a time by using the serial peripheral interface.

Controlling Individual LEDs

Just like CIRC02, you can individually control the LEDs on your breadboard. The current state of the eight LEDs are stored in one 8-bit value (for more info on this subject, we have a great Collin's Lab video on Binary and Hex). The code provided already takes care of the bit manipulations

To control individual LEDs, we replace the code within loop() with the following:

    int delayTime = 100; // # of ms to delay btween LED updates
for(int i=0; i<8; i++){
  changeLED(i, ON);
for(int i=0;i<8;i++){

Then, compile and upload this to your Metro. The code will cause the LEDs to light up one after another and then turn off. Read through the code and the links for a better understanding of how it works.

More Animations

If you did CIRC02, there was a part in the Make It Better section about adding additional animations. The format of changing the LEDs in this circuit will be similar. 

CIRC02 let you change the LEDs using

     digitalWrite(LED, state)

CIRC05 uses the changeLED() routine to perform the same operation:

     changeLED(LED, state)

You can repurpose the code from CIRC02's additional animations by first copying the animation code from CIRC02 into this sketch and then changing all the digitalWrite() routines to changeLED(). You'll also need to change a few other things, just follow the compiler errors and it works itself out.

This guide was first published on Aug 18, 2017. It was last updated on Jul 19, 2024.

This page (Make It Better) was last updated on Mar 08, 2024.

Text editor powered by tinymce.