DIY Light Sculpture

Pages
Contributors: Feldi
Favorited Favorite 19

Software Installation

Arduino IDE

The Qduino Mini is programmable via the Arduino IDE. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE.

Installing Arduino IDE

March 26, 2013

A step-by-step guide to installing and testing the Arduino software on Windows, Mac, and Linux.

Qduino Mini Drivers and Board Add-On

If this is your first time working with the Qduino Mini, you may need to add drivers and the board add-on through the boards manager. Please visit the Qduino Mini quick start guide for detailed instructions on installing drivers and programming a Qduino Mini via the Arduino IDE.

Example Code

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

In this program, we will also be utilizing the Adafruit Neopixel Library. You can obtain this library through the Arduino Library Manager. Search for Adafruit Neopixel and you should be able to install the latest version of the library. If you prefer downloading the library manually you can grab it from the GitHub repository:

We have provided the code for this project below. Copy and paste it into your Arduino IDE and then upload it to your board. Make sure you have the correct board selected in the boards manager as well as the port under the port drop down.

language:c
    /******************************************************************************
  lightsculpture.ino
  Melissa Felderman @ SparkFun Electronics
  creation date: July 31, 2018


  Resources:
  Adafruit_NeoPixel.h - Adafruit Neopixel library and example functions

*****************************************************************************/

        #include <Adafruit_NeoPixel.h> //include afafruit library 
    #define PIN 6 //LED matrix pin
    #define brightPot A0 //potentiometer to controll brightness
    #define pwrSwitch 4 //power switch
    #define momBut 5 //button to control LED mode
    int numPix = 64; //total LED count
    int brightPotVal; //Variable to hold pot value
    int pixelBrightness; //variabe to hold brightness value
    int switchState; //variable to hold switch value
    int butState; //variable to hold button value
    int mode = 0; //starting mode for switch state
    int prevButState = LOW;
    boolean butBool = false;
    int topMode = 4; //max number of LED modes in switch state

    unsigned long lastDebounceTime = 0;
    unsigned long debounceDelay = 200;

    Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPix, PIN, NEO_GRB + NEO_KHZ800); //declare neopixel matrix


    //create an array for each row of LEDs
    int rowOne[] = {0, 1, 2, 3, 4, 5, 6, 7};
    int rowTwo[] = {8, 9, 10, 11, 12, 13, 14, 15};
    int rowThree[] = {16, 17, 18, 19, 20, 21, 22, 23};
    int rowFour[] = {24, 25, 26, 27, 28, 29, 30, 31};
    int rowFive[] = {32, 33, 34, 35, 36, 37, 38, 39};
    int rowSix[] = {40, 41, 42, 43, 44, 45, 46, 47};
    int rowSeven[] = {48, 49, 50, 51, 52, 53, 54, 55};
    int rowEight[] = {56, 57, 58, 59, 60, 61, 62, 63};

    void setup() {
      Serial.begin(9600);
      strip.begin();
      strip.show();

      pinMode(momBut, INPUT);
      pinMode(pwrSwitch, INPUT);

    }


    void loop() {
      brightPotVal = analogRead(brightPot);
      pixelBrightness = map(brightPotVal, 0, 1023, 0, 200);

      switchState = digitalRead(pwrSwitch);
      butState = digitalRead(momBut);

      strip.setBrightness(pixelBrightness);
      strip.show();

      //function to debounce button
      if ((millis() - lastDebounceTime) > debounceDelay) {
        if ((butState == HIGH) && (butBool == false)) {
          butBool = true;
          mode++;
          lastDebounceTime = millis();
        } butBool = false;
      } if (mode > topMode) {
        mode = 0;
      }

      Serial.println(mode);

      //switch state function to cycle through modes on LEDs, you can add as many or as few as you would like
      if (switchState == HIGH) {

        switch ( mode ) {
          case 0:
            for (int i = 0; i < numPix; i++) {
              strip.setPixelColor(i, 255, 255, 255);
            }
            strip.show();
            break;
          case 1:
            rainbow();
            break;
          case 2:
            buleGreenGradient();
            break;
          case 3:
            pinkGradient();
            break;
          case 4:
            yellowGradient();
            break;

        }
      } else if (switchState == LOW) {
        for (int i = 0; i < numPix; i++) {
          strip.setPixelColor(i, 0, 0, 0);
        }
        strip.show();
      }
    }



    //functions for LED colors


    void everyOther() {
      for (int i = 0; i < 8; i++) {
        strip.setPixelColor(rowOne[i], 255, 255, 255);
        strip.setPixelColor(rowThree[i], 255, 255, 255);
        strip.setPixelColor(rowFive[i], 255, 255, 255);
        strip.setPixelColor(rowSeven[i], 255, 255, 255);

        strip.setPixelColor(rowTwo[i], 0, 0, 0);
        strip.setPixelColor(rowFour[i], 0, 0, 0);
        strip.setPixelColor(rowSix[i], 0, 0, 0);
        strip.setPixelColor(rowEight[i], 0, 0, 0);
      }
      strip.show();
    }


    void pinkGradient() {
      for (int i = 0; i < 8; i++) {
        strip.setPixelColor(rowOne[i], 185, 0, 255);
        strip.setPixelColor(rowTwo[i], 195, 0, 230);
        strip.setPixelColor(rowThree[i], 205, 0, 200);
        strip.setPixelColor(rowFour[i], 215, 0, 160);
        strip.setPixelColor(rowFive[i], 225, 0, 120);
        strip.setPixelColor(rowSix[i], 235, 0, 80);
        strip.setPixelColor(rowSeven[i], 245, 0, 40);
        strip.setPixelColor(rowEight[i], 255, 0, 10);
      }
      strip.show();
    }

    void buleGreenGradient() {
      for (int i = 0; i < 8; i++) {
        strip.setPixelColor(rowOne[i], 0, 75, 255);
        strip.setPixelColor(rowTwo[i], 0, 100, 225);
        strip.setPixelColor(rowThree[i], 0, 125, 200);
        strip.setPixelColor(rowFour[i], 00, 150, 175);
        strip.setPixelColor(rowFive[i], 0, 175, 150);
        strip.setPixelColor(rowSix[i], 0, 200, 125);
        strip.setPixelColor(rowSeven[i], 0, 225, 100);
        strip.setPixelColor(rowEight[i], 0, 255, 75);
      }
      strip.show();
    }

    void yellowGradient() {
      for (int i = 0; i < 8; i++) {
        strip.setPixelColor(rowOne[i], 255, 255, 25);
        strip.setPixelColor(rowTwo[i], 255, 220, 25);
        strip.setPixelColor(rowThree[i], 255, 190, 25);
        strip.setPixelColor(rowFour[i], 255, 160, 25);
        strip.setPixelColor(rowFive[i], 255, 130, 25);
        strip.setPixelColor(rowSix[i], 255, 100, 25);
        strip.setPixelColor(rowSeven[i], 255, 70, 25);
        strip.setPixelColor(rowEight[i], 255, 40, 25);
      }
      strip.show();
    }
    void rainbow() {
      for (int i = 0; i < 8; i++) {
        strip.setPixelColor(rowOne[i], 255, 0, 0);
      } for (int i = 0; i < 8; i++) {
        strip.setPixelColor(rowTwo[i], 255, 100, 0);
      } for (int i = 0; i < 8; i++) {
        strip.setPixelColor(rowThree[i], 255, 255, 0);
      } for (int i = 0; i < 8; i++) {
        strip.setPixelColor(rowFour[i], 0, 255, 0);
      } for (int i = 0; i < 8; i++) {
        strip.setPixelColor(rowFive[i], 0, 255, 200);
      } for (int i = 0; i < 8; i++) {
        strip.setPixelColor(rowSix[i], 0, 0, 255);
      } for (int i = 0; i < 8; i++) {
        strip.setPixelColor(rowSeven[i], 255, 0, 255);
      } for (int i = 0; i < 8; i++) {
        strip.setPixelColor(rowEight[i], 255, 0, 130);
      }
      strip.show();
    }