Controlling lights with the Brickstuff Arduino Shield

The Brickstuff Arduino shield has six high-current outputs that can be used to control a large number of connected lights.  Each output is connected to an N-channel MOSFET on the shield, which provides the ability to control large numbers of lights.

Here is some sample code you can use to control lights connected to the six outputs (this code is also provided as an attachment):

////////////////////////////
// Brickstuff Arduino Shield
//
// Sample code for controlling light outputs using pulse-width modulation (PWM) brightness
// (c)2020, Enthusiast Enterprises, LLC
//
// THIS CODE IS PROVIDED AS-IS WITH NO WARRANTY OR GUARANTEE OF ANY KIND
//
// HISTORY
// 11.12.2020 Version 1.0
////////////////////////////

// Define the number of outputs and pin specifics here
#define numPorts 6  // Default on the Brickstuff Arduino shield
int portPins[numPorts] = {3,5,6,9,10,11}; // PWM pins on the Arduino Uno

// Array for controlling the brightness of each output
int portBright[numPorts] = {0,0,0,0,0,0}; // Max of 255

void setup()
{
  // Set the outputs to be outputs
  for(int i = 0; i < numPorts; i++)
  {
    pinMode(portPins[i], OUTPUT);
  }
}

void loop()
{
  // Put your lighting control code here

  // Remember when setting a value for a given output that the array begins with zero, but the outputs on the board are labeled beginning with 1
  // So, to set the brightness of OUT3 (the third output on the shield), you need to set the [2] value in the array (since the array is numbered 0,1,2..)
  portBright[2] = 128;  // Sets the brightness of OUT3 to 50% (255 / 128)-- this will not get updated until you call updateOutputs()
  updateOutputs();  // Updates the OUT3 brightness (and all of the others)

  // If you want to make a pulsating light by setting the value directly (without uusing updateOutputs()), you can do this
  for(int x = 0; x < 255; x++)  // Ramp up
  {
    portBright[5] = x;  // Sets the brightness of OUT6 (remember, the array begins with 0)
    analogWrite(portPins[5], portBright[5]);  // Updates the port directly
    delay(25);
  }
  for(int x = 255; x > 0; x--)  // Ramp down
  {
    portBright[5] = x;  // Sets the brightness of OUT6 (remember, the array begins with 0)
    updateOutputs();  // Calls the updateOutputs function to do the update, instead of updating directly
    delay(25);
  }
  portBright[5] = 0;  // Make sure it's off

  // Finally, update all of the outputs you didn't set directly (also re-updates the ones you did set directly, but that's ok)
  updateOutputs();
}

// Make sure to include this subroutine at the end of any sketch you write that calls it.
void updateOutputs()
{
  for(int i = 0; i < numPorts; i++)
  {
    analogWrite(portPins[i], portBright[i]);
  }
}

This is how we control the lights in our products, using an array that stores the brightness values (0-255) of each connected output.

All of the outputs on the shield are pulse-width modulation (PWM) outputs, which means you can individually set the brightness of each output.

Reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
Like1 Follow
  • 1 Likes
  • 4 yrs agoLast active
  • 209Views
  • 2 Following