Navigation Menu

A portfolio for an exhibit designer, planner, interactive designer, developer, artist, coder, optimist, and normally too humble of a guy.

Design

More work »

MCN 2017 Workshop

MCN 2017 Workshop

Posted on Nov 6, 2017 in Arduino | 0 comments

Welcome to the workshop. We’ll have lots of fun working with Arduino today.

 

Parts

A quick list of the parts in our kit:

Learn more about the Circuit Playground Classic here. We chose the classic for our class, because the Express does not yet have full support.

 

Installation

Before we use our kits, we need to install some pieces. Sometimes this part can be a bit tricky, depending on your computer. Follow the steps below.

  1. If you have Windows, install the drivers.
  2. Download the Arduino IDE.
  3. Install the Circuit Playground library via the Library Manager. Stop when you get to the section titled “Run the Demo.” We’ll go through those steps together.

 

Load our First Programs

Together, let’s load our first programs. Follow the steps you saw before to run the demo. Then, load the blink program viaFile >> Examples >> Adafruit Circuit Playground >> Hello_Circuit Playground >> Hello_Blink.

 

Try Other Programs

Next, try the other Circuit Playground programs that came with the library. File >> Examples >> Adafruit Circuit Playground >> Hello_Circuit Playground >>. See what they do. When you’re finished with those, jump up to some of the others like Birthday_Candles or FidgetSpinner.

See other lessons here.

 

Wire a Circuit

Now, we’ll break out of the box and build our own circuit using the LED sequins and alligator clips. First, let’s test the LEDs using just power, no code. Follow the diagram below:

Next, let’s use code to control the external LED. Change the circuit, and upload the new code.

#include <Adafruit_CircuitPlayground.h>

int d = 250; // how long to delay in the blink
int ledPin = 6; // which pin is connected to the led?

void setup() {
  CircuitPlayground.begin();
  pinMode(ledPin, OUTPUT);
}

void loop() {
  digitalWrite(ledPin, HIGH);
  delay(d);
  digitalWrite(ledPin, LOW);
  delay(d*2);
}

 

For an advanced code option, combine the blink with a button press.

#include <Adafruit_CircuitPlayground.h>

// learn more about state changes here: https://www.arduino.cc/en/Tutorial/StateChangeDetection?from=Tutorial.ButtonStateChange

// this constant won't change:
const int  buttonPin = 2;    // the pin that the pushbutton is attached to
const int ledPin = 6;       // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
  CircuitPlayground.begin();
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);
}


void loop() {
  // read the pushbutton input pin:
  buttonState = CircuitPlayground.leftButton();

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter);
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastButtonState = buttonState;


  // turns on the LED every four button pushes by checking the modulo of the
  // button push counter. the modulo function gives you the remainder of the
  // division of two numbers:
  if (buttonPushCounter % 2 == 0) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }

}

 

Remix Programs

Try remixing programs. Maybe try using the capacitive touch sensors.

Here is one where I combined the light sensor and the speaker to make a theremin.

/*
Original idea from Adafruit Arduino - Lesson 10. Pseudo Thermin
https://learn.adafruit.com/adafruit-arduino-lesson-10-making-sounds/arduino-code
*/

#include <Adafruit_CircuitPlayground.h>

int reading; // store light sensor reading
const int minPitch = 200;
const int maxPitch = 6000;

void setup()
{
  Serial.begin(9600);
  CircuitPlayground.begin();
}

void loop()
{
  // read the light sensor
  reading = CircuitPlayground.lightSensor();

  // calculate a pitch based on the light sensor
  int pitch = map(reading, 0, 1023, minPitch, maxPitch);

  // play a tone
  CircuitPlayground.playTone(pitch, 100, false);
  Serial.println(pitch);
}

 

Reference

While you’re working on the code, see the following for reference.

 

Cover photo from Adafruit on Flickr.

Read More

MCN 2016 Workshop

MCN 2016 Workshop

Posted on Oct 23, 2016 in Arduino | 0 comments

At today’s workshop, we’ll follow a series of small projects using parts from our kit. We’ll copy and paste code to see what it does. Then later, we’ll dive into the inner working of the code. Finally, we’ll make something on our own with the combined parts.

Read More

MCN 2015 Workshop

MCN 2015 Workshop

Posted on Nov 4, 2015 in Arduino | 0 comments

At today’s workshop, we’ll follow a series of small projects using parts from our kit. We’ll copy and paste code to see what it does. Then later, we’ll dive into the inner working of the code. Finally, we’ll make something on our own with the combined parts.

Read More

Arduino Pumpkin

Arduino Pumpkin

Posted on Oct 29, 2015 in Arduino | 0 comments

Make your pumpkin more interactive. Get the code on Github.

  1. Default program softly changes color hue automatically
  2. Hit the state button, then use the potentiometer to change the color hue yourself

 

Wiring Diagram

Wiring Diagram for Arduino Pumpkin
IMG_1462

 

Arduino Powered Pumpkin with color changing hue

Read More

MCN Workshop Part 6

MCN Workshop Part 6

Posted on Oct 30, 2014 in Arduino | 0 comments

Soon, we will break for the free form section of the workshop where you can customize your project in your own way. But before we do, let’s review some tricks to think about while you work on your project.

Pace your time

Plan something that you can accomplish given the timeframe we have left. Start small, get that working, then iterate something other idea building on the last, get that working, and so on, and so on. Time will fly.

Help your Neighbors

Work on your project, but help answer questions from those around you. Through out questions and ideas. We always make better ideas bouncing them around between a group. There will be others in the room who have done this before. Ask them for help too.

No More Aligator Clips

The alligator clips are wonderful to iterate ideas quickly, but they do not hold up to abuse. There are two easy ways to make your circuits more permanent.

Soldering

Soldering in action. Photo by zazenergy.

Soldering in action. Photo by zazenergy.

Soldering is commonplace in electronics. If you have not done this before, today is a great day to start. We will have a few soldering stations setup in the room, and we can show you the basics.

  • Here is a great tutorial on how to solder, if you want to get started without one of us.
  • Remember, soldering can be dangerous. Please respect the tools, don’t hurt yourself, and don’t burn down the building. 😉

Conductive Thread

Conductive thread in use. Photo by Shannon Henry.

Conductive thread in use. Photo by Shannon Henry.

Another approach is using conductive thread. Each table has some needles and conductive thread. Be careful not to cross the streams—er, um wires—or you will short your circuit. Here is a great tutorial on using conductive thread.

 What is the Form?

What do you want your creation to look like? Is it a button for your name tag? Does it sit on your hat or your bag? Is it more abstract or does it have a more real form? Take fabric, or paper, glue, or whatever you want to make your project your own. Think about defusing the light from the NeoPixels somehow. A tennis ball works well.

Tweak the Code

Inside the code. Photo by David Asch.

Inside the code. Photo by David Asch.

Have an idea to change the interaction behavior? This workshop did not handle much on how to code, but during this free form section of the workshop, you can dive in. Find others who have coded before and tell them your vision. If it’s simple enough, you could get it working. Get ready for bug fixing, function building, and magic making. There are some great forums to ask questions too.

Here is another piece of example code with some new function that you might want to play with.

/* 
  Created by chris@drumminhands.com
  Modified by combining these tutorials
    Blink without Delay  http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
    State change detection (edge detection) http://arduino.cc/en/Tutorial/ButtonStateChange
    Adafruit Strandtest https://github.com/adafruit/Adafruit_NeoPixel
    Debounce http://www.arduino.cc/en/Tutorial/Debounce
    Cyclon eyes https://github.com/EternalCore/NeoPixel_Cylon_Scrolling_Eye
 */
#include <Adafruit_NeoPixel.h>

// constants won't change. 
#define buttonPin 2 // the number of the pushbutton pin
#define neoPixelPin 0 //the number of the neopixel pin
#define numPixelsInStrip 16 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPixelsInStrip, neoPixelPin, NEO_GRB + NEO_KHZ800);

///////////////////////////////////////////////////////////////////////////
// Change the following variables to play with different outcomes        //
                                                                         //
int defaultBrightness = 64; // the max brightness, between 0 and 256     //
                                                                         //
// Do not change anything outside of this comment box,                   //
// unless you know what it does.                                         //  
///////////////////////////////////////////////////////////////////////////

// Variables used in programs

int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
int programState = 0; // current program seleted -- buttonpresses rotate between programs
int numOfPrograms = 5; // how many programs are there total, not including the off state
int ledState = HIGH; // the current state of the output pin
long previousMillis = 0;  // will store last time LED was updated
int neoPixelToChange = 0; //track which neoPixel to change
int neoPixel_j = 0; //stores values for program cycles
//cylon variables
int fadeDirection = -1;//change sign to fade up or down
boolean cylonDirection = true; //keeps track of the direction the pixels should swipe
boolean cylonPause = false; //keeps track of the pause inbetween swipes
long delayMillis = 0; // will store the last time the cylon swipe was paused

// Setup is a program run once at the beginning to get things in place
void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  strip.begin(); // prep the NeoPixels
  strip.show(); // Initialize all pixels to 'off'
  strip.setBrightness(defaultBrightness); // initialize brightness
}

// Loop is the program that runs repeatedly after Setup. Look for the programs below to change.
void loop() {
  
  // read the state of the switch into a local variable:
  int reading = digitalRead(buttonPin);

  // check to see if you just pressed the button  

  // If the switch changed, due to noise or pressing:
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  } 
  
  if ((millis() - lastDebounceTime) > debounceDelay) {

    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;
      
      // only toggle the LED if the new button state is HIGH
      if (buttonState == HIGH) {        
        //change the program
        programState = (programState + 1) % (numOfPrograms + 1); //include numOfPrograms + 1, since there is an off state
      }
    }
  }

  // save the reading.  Next time through the loop
  lastButtonState = reading;

//////////////////////////////////////////////////////////////////////////////
// Change the program states to cycle when the button is pressed.           //
// Try changing the colors and duration.                                    //
// NOTE if you change the number of programs in the switch statement above, //
// be sure to change the variable numOfPrograms at the top.                 //
//////////////////////////////////////////////////////////////////////////////
  //run the chosen program
  switch (programState) {
    case 0:
      allColor(strip.Color(0,0,0)); // turn all lights off
      break; 
    case 1:
      //blinkColor(strip.Color(255,0,0),100); // blink red every 100
      blinkColor((unsigned long)random(0x01000000),250);
      break;        
    case 2:
      softBlink(strip.Color(0,255,255),defaultBrightness, 50); // soft blink blue every 50
      break;
    case 3:
      strip.setBrightness(defaultBrightness); // initialize brightness
      rainbow(20); //all rainbow with a 20 wait setting
      break;
    case 4:
      rainbowCycle(10); //all rainbow, but slightly different--try it to see
      break;
    case 5:
      cylonEye(40, 500); //cylon eye, but not sure if the pause is working
      break;
    default: 
      // if nothing else matches, do the default 
      allColor(strip.Color(0,0,0)); //turn all off
  } 
}
//////////////////////////////////////////////////////////////////////
// Stop changing program states. Below are the programs themselves. //
//////////////////////////////////////////////////////////////////////

// Fill all the dots with one color
void allColor(uint32_t c) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
  }
} // note for a random color, use:
  // allColor((unsigned long)random(0x01000000)); // random color
  
void blinkColor(uint32_t c, uint8_t wait) {
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > wait) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW){
      ledState = HIGH;
      allColor(c); 
    } else {
      ledState = LOW;
      allColor(strip.Color(0,0,0)); // off
    }
  } 
}  
  

void rainbow(uint8_t wait) {
    
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > wait) {
    
    // save the last time you changed a NeoPixel 
    previousMillis = currentMillis; 

    //change the colors of the pixels
    uint16_t i;

    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+neoPixel_j) & 255));
    }
    strip.show();
    neoPixel_j = (neoPixel_j + 1) % 255; //increment j until all colors are used, then start over
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > wait) {
    
    // save the last time you changed a NeoPixel 
    previousMillis = currentMillis; 

    //change the colors of the pixels
    uint16_t i;

    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + neoPixel_j) & 255));
    }
    strip.show();
    neoPixel_j = (neoPixel_j + 1) % 1279; // 5 cycles of all colors on wheel, then start over
  }
}

void softBlink(uint32_t c, uint8_t brightness, uint8_t wait) {
  
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > wait) {
  
    //set the color of all pixels
    allColor(c); // is there a way to set this only once per program ????????????????????
    
    // save the last time you changed a NeoPixel 
    previousMillis = currentMillis; 
    
    uint16_t i;
    int b = (neoPixel_j * brightness) / brightness;
    strip.setBrightness(b);
    strip.show(); 
    // sometime figure out how to get this to fade down too instead of just restarting //////////////////////
    neoPixel_j = (neoPixel_j + 1) % brightness;
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

void cylonEye(uint8_t swipeSpeed, uint8_t pauseTime) {

  if (cylonPause) { //we are on a pause break from swipes

    unsigned long currentPauseMillis = millis();

    //check to see if we've waited long enough
    if ((currentPauseMillis - delayMillis) > pauseTime) { /////////////////////////////// this is not getting called. Why????????????????
      // save the last time you checked the pause
      delayMillis = currentPauseMillis;
      cylonPause = false; //end the pause
    }

  } else {

    //if needed, change directions
    if (neoPixelToChange > numPixelsInStrip) {
      cylonDirection = false;
    }
    if (neoPixelToChange < 0) {
      cylonDirection = true;
      cylonPause = true; //take a break from the swipe
      //turn all pixels off
      for (uint16_t i = 0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, strip.Color(0, 0, 0));
      }
      strip.show();
      delayMillis = millis();
    }

    //run the swipe
    if (cylonDirection) {
      cylonUp(strip.Color(255, 0, 0), strip.Color(72, 0, 0), swipeSpeed); // red
    } else {
      cylonDown(strip.Color(255, 0, 0), strip.Color(72, 0, 0), swipeSpeed); // red
    }
  }
}

void cylonUp(uint32_t c0, uint32_t c1, uint8_t wait) {

  unsigned long currentMillis = millis();

  //neoPixelToChange * wait
  if (currentMillis - previousMillis > wait) {

    //turn all pixels off
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(0, 0, 0));
    }

    // save the last time you changed a NeoPixel
    previousMillis = currentMillis;

    //change a pixel
    strip.setPixelColor(neoPixelToChange, c0); //primary color
    strip.setPixelColor(neoPixelToChange - 1, c1); //secondary color
    strip.setPixelColor(neoPixelToChange + 1, c1); //secondary color
    strip.show();
    neoPixelToChange++;
  }
}

void cylonDown(uint32_t c0, uint32_t c1, uint8_t wait) {

  unsigned long currentMillis = millis();

  //neoPixelToChange * wait
  if (currentMillis - previousMillis > wait) {

    //turn all pixels off
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(0, 0, 0));
    }

    // save the last time you changed a NeoPixel
    previousMillis = currentMillis;

    //change a pixel
    strip.setPixelColor(neoPixelToChange, c0); //primary color
    strip.setPixelColor(neoPixelToChange - 1, c1); //secondary color
    strip.setPixelColor(neoPixelToChange + 1, c1); //secondary color
    strip.show();
    neoPixelToChange--; //is there any way to combine this with cylonUp, since this is the only line that is different?
  }
}

Try the Other Sensors

You have many sensors in your kit. They each do slightly different things. Take a look at the product pages, click “Learn” to see the code in action. Here is the list:

Share Your Code

Did you make something unique and fun? Share it with the rest of the group. They might improve on it and send it back to you. Welcome to the maker world.

 

part5-left

 

 

Cover photo by josef.stuefer

Read More

MCN Workshop Part 5

MCN Workshop Part 5

Posted on Oct 30, 2014 in Arduino | 0 comments

On the previous parts, we wired a simple input button and next wired NeoPixels for flashy output. Now we’ll combine both input and output.

Interactions

  1. We will need a fresh blank sketch. Go into the File menu and choose New.
  2. Copy and paste the following 257 lines of code.
    /* 
      Created by chris@drumminhands.com
      Modified by combining these tutorials
        Blink without Delay  http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
        State change detection (edge detection) http://arduino.cc/en/Tutorial/ButtonStateChange
        Adafruit Strandtest https://github.com/adafruit/Adafruit_NeoPixel
        Debounce http://www.arduino.cc/en/Tutorial/Debounce
        Cyclon eyes https://github.com/EternalCore/NeoPixel_Cylon_Scrolling_Eye
     */
     
    //Choose a default program to run all the time, until the button is pressed. 
    //Then run the second program for a time. Then go back to the original program.
    
    #include <Adafruit_NeoPixel.h>
    
    // constants won't change. 
    #define neoPixelPin 0       // the number of the neopixel pic
    #define buttonPin  2        // the number of the input pin
    #define numPixelsInStrip 12 // the number of pixels in the strip/circle
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPixelsInStrip, neoPixelPin, NEO_GRB + NEO_KHZ800);
    
    //////////////////////////////////////////////////////////////////////////////////////
    // Change the following variables to play with different outcomes                   //
                                                                                        //
    int defaultBrightness = 128; // the max brightness, between 0 and 256               //
    int reactionDuration = 2000; // how long to run the second program, in miliseconds  //
                                                                                        //
    // Do not change anything outside of this comment box, unless you know what it does.// 
    //////////////////////////////////////////////////////////////////////////////////////
    
    // Variables used in programs
    int buttonState; // the current reading from the input pin
    int lastButtonState = LOW; // the previous reading from the input pin
    long lastDebounceTime = 0; // the last time the output pin was toggled
    long debounceDelay = 50; // the debounce time; increase if the output flickers
    int programState = 0; // current program seleted
    int ledState = HIGH; // the current state of the output pin
    long previousMillis = 0;  // will store last time LED was updated
    int neoPixelToChange = 0; //track which neoPixel to change
    int neoPixel_j = 0; //stores values for program cycles
    long color = 0x01000000; //store the color value when reacting
    
    // Setup is a program run once at the beginning to get things in place
    void setup() {
      pinMode(buttonPin, INPUT_PULLUP);
      strip.begin(); // prep the NeoPixels
      strip.show(); // Initialize all pixels to 'off'
      strip.setBrightness(defaultBrightness); // initialize brightness
    }
    
    // Loop is the program that runs repeatedly after Setup. Look for the programs below to change.
    void loop() {
      
      // read the state of the switch into a local variable:
      int reading = digitalRead(buttonPin);
    
      // check to see if you just pressed the button  
    
      // If the switch changed, due to noise or pressing:
      if (reading != lastButtonState) {
        // reset the debouncing timer
        lastDebounceTime = millis();
      } 
      
      if ((millis() - lastDebounceTime) > debounceDelay) {
    
        // if the button state has changed:
        if (reading != buttonState) {
          buttonState = reading;
          
          // only toggle the LED if the new button state is HIGH
          if (buttonState == HIGH) {        
            //change the program
            programState = 1; //change to the second program
            color = random(0x01000000); // choose a color at random for the reaction
          }
        }
      }
    
      // save the reading.  Next time through the loop
      lastButtonState = reading;
      
      // if it's been longer than the reaction duration
      if ((millis() - lastDebounceTime) > reactionDuration) {
        programState = 0; //go back to the default program
      }
      
      //run the chosen program
      switch (programState) {
        case 0:
    ///////////////////////////////////////////////////////////////////////////////////////////
          rainbowCycle(7); //The default program. Change as needed                           //        
    ///////////////////////////////////////////////////////////////////////////////////////////
          break; 
        case 1:
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          blinkColor(color,100); // use this line to blink a random color                                              //
          //blinkColor((unsigned long)random(0x01000000),100); // use this line to blink a new random color each blink //
          //blinkColor(strip.Color(128,0,204),100); // use this line to blink a specific color                         //
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          break;        
        default: 
          allColor(strip.Color(0,0,0)); //if nothing else matches, turn all off
      } 
    }
    
    // Fill all the dots with one color
    void allColor(uint32_t c) {
      for(uint16_t i=0; i<strip.numPixels(); i++) {
          strip.setPixelColor(i, c);
          strip.show();
      }
    } // note for a random color, use:
      // allColor((unsigned long)random(0x01000000)); // random color
      
    void blinkColor(uint32_t c, uint8_t wait) {
      unsigned long currentMillis = millis();
     
      if(currentMillis - previousMillis > wait) {
        // save the last time you blinked the LED 
        previousMillis = currentMillis;   
    
        // if the LED is off turn it on and vice-versa:
        if (ledState == LOW){
          ledState = HIGH;
          allColor(c); 
        } else {
          ledState = LOW;
          allColor(strip.Color(0,0,0)); // off
        }
      } 
    }  
      
    // Fill the dots one after the other with a color
    void colorWipe(uint32_t c, uint8_t wait) {
      
      unsigned long currentMillis = millis();
      
      //only do this if some of the pixels still need to be lit
      if (neoPixelToChange <= strip.numPixels()){
        
        if(currentMillis - previousMillis > wait) {
          
          // save the last time you changed a NeoPixel 
          previousMillis = currentMillis;  
        
          //change a pixel
          strip.setPixelColor(neoPixelToChange, c);
          strip.show();
          neoPixelToChange++;
        }
      }
    }
    
    // Fill the dots one after the other with a color
    void colorWipeCycle(uint32_t c, uint8_t wait) {
      
      unsigned long currentMillis = millis();
      
      //only do this if some of the pixels still need to be lit
      if (neoPixelToChange <= strip.numPixels()){
        
        if(currentMillis - previousMillis > wait) { 
          
          // save the last time you changed a NeoPixel 
          previousMillis = currentMillis;  
        
          //change a pixel
          strip.setPixelColor(neoPixelToChange, c);
          strip.show();
          neoPixelToChange++;
          
        } 
        
      } else {
        // reset the cycle
        previousMillis = 0;  
        neoPixelToChange = 0;
        allColor(strip.Color(0,0,0));
      }
    }
    
    void rainbow(uint8_t wait) {
        
      unsigned long currentMillis = millis();
    
      if(currentMillis - previousMillis > wait) {
        
        // save the last time you changed a NeoPixel 
        previousMillis = currentMillis; 
    
        //change the colors of the pixels
        uint16_t i;
    
        for(i=0; i<strip.numPixels(); i++) {
          strip.setPixelColor(i, Wheel((i+neoPixel_j) & 255));
        }
        strip.show();
        neoPixel_j = (neoPixel_j + 1) % 255; //increment j until all colors are used, then start over
      }
    }
    
    // Slightly different, this makes the rainbow equally distributed throughout
    void rainbowCycle(uint8_t wait) {
      
      unsigned long currentMillis = millis();
    
      if(currentMillis - previousMillis > wait) {
        
        // save the last time you changed a NeoPixel 
        previousMillis = currentMillis; 
    
        //change the colors of the pixels
        uint16_t i;
    
        for(i=0; i<strip.numPixels(); i++) {
          strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + neoPixel_j) & 255));
        }
        strip.show();
        neoPixel_j = (neoPixel_j + 1) % 1279; // 5 cycles of all colors on wheel, then start over
      }
    }
    
    void softBlink(uint32_t c, uint8_t brightness, uint8_t wait) {
      
      unsigned long currentMillis = millis();
    
      if(currentMillis - previousMillis > wait) {
      
        //set the color of all pixels
        allColor(c); // is there a way to set this only once per program ????????????????????
        
        // save the last time you changed a NeoPixel 
        previousMillis = currentMillis; 
        
        uint16_t i;
        int b = (neoPixel_j * brightness) / brightness;
        strip.setBrightness(b);
        strip.show(); 
        // sometime figure out how to get this to fade down too instead of just restarting //////////////////////
        neoPixel_j = (neoPixel_j + 1) % brightness;
      }
    }
    
    // Input a value 0 to 255 to get a color value.
    // The colours are a transition r - g - b - back to r.
    uint32_t Wheel(byte WheelPos) {
      if(WheelPos < 85) {
       return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
      } else if(WheelPos < 170) {
       WheelPos -= 85;
       return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
      } else {
       WheelPos -= 170;
       return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
      }
    }
  3. Save the code on your computer with a filename that makes sense.
  4. The circuit should already be setup, as long as you did not unplug the button when you plugged in the NeoPixels. If you need to tweak, be sure unplug the GEMMA from your computer before changing the circuit. Double-check the following:
    • Yellow from GEMMA DO to NeoPixels IN
    • Red from GEMMA Vout to NeoPixels PWR
    • Black from GEMMA GND to NeoPixels GND
    • White from GEMMA D2 to button
    • Green from GEMMA GND to other side of the buttonneopixel wiring 2
  5. Plug the GEMMA into your computer’s USB port, if it’s not already.
  6. Upload the code. Remember to press the button on the GEMMA before uploading.
  7. After uploading, the GEMMA should be running the code. A soft rainbow pattern will circle.
  8. Try pushing the button. The NeoPixels should do something very different for a few seconds and then go back to the original soft rainbow pattern.
  9. What’s happening here is the output changes depending on the input. It reacts to you.

Tweak the code

Now let’s tweak the code, just a bit. Don’t be scared. Let’s make some changes to customize this for you.

  1. Scroll down in the code until you find a section that looks like this:
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          blinkColor(color,100); // use this line to blink a random color                                              //
          //blinkColor((unsigned long)random(0x01000000),100); // use this line to blink a new random color each blink //
          //blinkColor(strip.Color(128,0,204),100); // use this line to blink a specific color                         //
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
  2. Notice only one line has different color in the text. The others are “commented out,” meaning that there are two slashes (//) at the start of the line. This means that you can type anything you want after those slashes and those characters won’t influence the behavior at all. It’s a way for you to write comments for yourself or others who read the code. It is also a way to hide particular lines of code for later use.
  3. Add two comment slashes to line 97 and un-comment line 99, similar to below:
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
          //blinkColor(color,100); // use this line to blink a random color                                              //
          //blinkColor((unsigned long)random(0x01000000),100); // use this line to blink a new random color each blink //
          blinkColor(strip.Color(128,0,204),100); // use this line to blink a specific color                         //
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
  4. With this change, the NeoPixels will do something different when the button is pushed. Save the file and upload it. Give the button a try. What color does it change to?
  5. Now tweak the code to your liking. Change the color value to anything you want. This is the specific part that sets the color, with three values, one each for Red, Green, and Blue.
    strip.Color(128,0,204)
  6. Each of the three values can a whole number from 0 to 255. Change the values and try uploading it again. Maybe use a color picker to get the RGB values you want.
  7. Be sure to save your file as you iterate.
  8. Now we are ready to move onto the final section.

part4-leftpart6-right

 

Cover photo by me. 😉

Read More