Friday, December 12, 2014

ETEC 597: Course Retrospective



Final Course Retrospective
 
What was the build that you are most proud of and why?

The build that I am most proud of is the musical circuit that plays Jingle Bells.  That build took the most research to successfully complete and I was able to involve my students and family.  I was impressed by the resemblance to the actual tune of Jingle Bells.

Go back to your first week and read each week’s submission with an eye for personal growth. Where were you when you started and where did you end up?

I gained an appreciation for hardware programmers after taking this course.  My skills as a CS teacher and developer were pushed beyond what I was accustomed to doing.  After the last project, I discovered that I had a yearning for more projects.  I am hoping to be able to pick up on Arduino development as a hobby.

What did you learn that you didn’t know before?

I was aware of some C++ syntax before the course but I didn’t know exactly how the programs were implements (especially how OOP came into play with C++.)  I learned how to write functions with C++ and my previous Java knowledge enabled me to make the connection on how to call those programs in the main loop.

How did you actually come to learn this new knowledge?

I learned this knowledge by building on my previous programming knowledge and learning through the Arduino reference site and tutorials.

What did you learn about yourself?

I learned that I enjoy experiential learning more than following prescribed instructions.  I have always felt that I did not really think outside of the box but this course made me more astute to the fact that I enjoy a challenge.  I feel better about challenging  my students more now that I have been challenged myself.

Look at your words for each week and see how they might read if one of your students turned in that submission. What were you telling yourself about yourself?

I feel that I was a little brief in some of my responses although I completed the challenges.  I am sure that this was because of my busy schedule and having so much on my plate.  I now feel the way that most of my seniors do at any point during the week; having a lot to do doesn’t excuse me from having to do the work, though.

Where did you say your challenges where?

My biggest challenge was managing my time effectively.  Having 6 preps, graduate school, and a 2-year old at home causes some serious issues when trying to find the time to test and build a circuit.

Did these challenges change over the time of the class?

The main challenge did not change but my ability to adjust did.  I started setting aside some time at the end of each school day to work on Arduino projects and the students that I had in my room for extra help or Computer Science club began to get into the testing process as well.

As you entered the world of the maker, what do you see as your next adventure in the world of making? Is it to expand your abilities to work with microprocessor and move from prototype to the production of something fun and useful? Is it to see what you can learn about the world of 3D design and printing? Is it to see what aspects of making can be used with the younger children? It is to see what you need to do to bring your vision of a maker space to life in the real world? It can be anything.

My next adventure is going to be to actually implement the maker space into my school.  Given the technology support that my district gives, it will be a process where I will have to do the majority of the leg work.  This course gave me the background knowledge to rationalize the maker space and a couple of my colleagues have agreed to help me with this process.

What are your next steps?

My next steps will be to start the Education Foundation grant process for my maker space and keep tinkering with the Arduino.  I plan on purchasing several kits for my Engineering Design and Computer Programming classes to use in the spring.

Sunday, December 7, 2014

ETEC 597: Maker Movement - Week 6

We made it!  After several weeks of tinkering and making, we are finally in the home stretch.  I, for one, have enjoyed working on these projects and coming up with solutions to each week's Maker Challenge.  This week's challenge was a culmination of outputs and inputs with our circuit having to consist of an electric motor connected to a sensor.  I chose to work with the light sensor rather than the thermal sensor because it is easier to make fast changes to light intensity when testing than making fast changes in temperature.  This decision worked out well once I was able to adjust the code and make the motor respond to changes in the photo resistor instantaneously.  The first code that I am posting is the original code for the motor control; the second set of code is the working copy of the code with the photo resistor.

Code
// Motor Controller Code

const int motorPin = 9;

void setup()
{
  // Set up the motor pin to be an output:

  pinMode(motorPin, OUTPUT);

  // Set up the serial port:

  Serial.begin(9600);
}


void loop()
{

  // motorOnThenOff();
  // motorOnThenOffWithSpeed();
  // motorAcceleration();
  // serialSpeed();
}


void motorOnThenOff()
{
  int onTime = 3000;  // milliseconds to turn the motor on
  int offTime = 3000; // milliseconds to turn the motor off
  
  digitalWrite(motorPin, HIGH); // turn the motor on (full speed)
  delay(onTime);                // delay for onTime milliseconds
  digitalWrite(motorPin, LOW);  // turn the motor off
  delay(offTime);               // delay for offTime milliseconds
}

void motorOnThenOffWithSpeed()
{
  int Speed1 = 200;  // between 0 (stopped) and 255 (full speed)
  int Time1 = 3000;  // milliseconds for speed 1
  
  int Speed2 = 50;   // between 0 (stopped) and 255 (full speed)
  int Time2 = 3000;  // milliseconds to turn the motor off
  
  analogWrite(motorPin, Speed1);  // turns the motor On
  delay(Time1);                   // delay for onTime milliseconds
  analogWrite(motorPin, Speed2);  // turns the motor Off
  delay(Time2);                   // delay for offTime milliseconds
}

void motorAcceleration()
{
  int speed;
  int delayTime = 20; // milliseconds between each speed step
  
  // accelerate the motor

  for(speed = 0; speed <= 255; speed++)
  {
    analogWrite(motorPin,speed); // set the new speed
    delay(delayTime);           // delay between speed steps
  }
  
  // decelerate the motor

  for(speed = 255; speed >= 0; speed--)
  {
    analogWrite(motorPin,speed); // set the new speed
    delay(delayTime);           // delay between speed steps
  }
}

void serialSpeed()
{
  int speed;
  
  Serial.println("Type a speed (0-255) into the box above,");
  Serial.println("then click [send] or press [return]");
  Serial.println();  // Print a blank line

  // In order to type out the above message only once,
  // we'll run the rest of this function in an infinite loop:

  while(true)  // "true" is always true, so this will loop forever.
  {
    // First we check to see if incoming data is available:
  
    while (Serial.available() > 0)
    {
      // If it is, we'll use parseInt() to pull out any numbers:
      
      speed = Serial.parseInt();
  
      // Because analogWrite() only works with numbers from
      // 0 to 255, we'll be sure the input is in that range:
  
      speed = constrain(speed, 0, 255);
      
      // We'll print out a message to let you know that the
      // number was received:
      
      Serial.print("Setting speed to ");
      Serial.println(speed);
  
      // And finally, we'll set the speed of the motor!
      
      analogWrite(motorPin, speed);
    }
  }
}

Picture of the Circuit without the Photo Resistor















Code with the Photo Resistor
// Motor Controller Code

const int sensorPin = 0;

const int motorPin = 9;

int lightLevel, high = 0, low = 1023;

void setup()
{
  // Set up the motor pin to be an output:

  pinMode(motorPin, OUTPUT);

  // Set up the serial port:

  Serial.begin(9600);
}


void loop()
{
  int lightSensor = analogRead(sensorPin/4);
  
  // motorOnThenOff();
  // motorOnThenOffWithSpeed();
  // motorAcceleration();
  // serialSpeed();
  motorSpeedwithLight();
}


void motorOnThenOff()
{
  int onTime = 3000;  // milliseconds to turn the motor on
  int offTime = 3000; // milliseconds to turn the motor off
  
  digitalWrite(motorPin, HIGH); // turn the motor on (full speed)
  delay(onTime);                // delay for onTime milliseconds
  digitalWrite(motorPin, LOW);  // turn the motor off
  delay(offTime);               // delay for offTime milliseconds
}

void motorOnThenOffWithSpeed()
{
  int Speed1 = 200;  // between 0 (stopped) and 255 (full speed)
  int Time1 = 3000;  // milliseconds for speed 1
  
  int Speed2 = 50;   // between 0 (stopped) and 255 (full speed)
  int Time2 = 3000;  // milliseconds to turn the motor off
  
  analogWrite(motorPin, Speed1);  // turns the motor On
  delay(Time1);                   // delay for onTime milliseconds
  analogWrite(motorPin, Speed2);  // turns the motor Off
  delay(Time2);                   // delay for offTime milliseconds
}

void motorAcceleration()
{
  int speed;
  int delayTime = 20; // milliseconds between each speed step
  
  // accelerate the motor

  for(speed = 0; speed <= 255; speed++)
  {
    analogWrite(motorPin,speed); // set the new speed
    delay(delayTime);           // delay between speed steps
  }
  
  // decelerate the motor

  for(speed = 255; speed >= 0; speed--)
  {
    analogWrite(motorPin,speed); // set the new speed
    delay(delayTime);           // delay between speed steps
  }
}

void motorSpeedwithLight()
{
  int speed;
  int lightSensor = analogRead(sensorPin);
  
    while(true)
    {
    speed = lightSensor/4; //Limits motor speed to 255
    analogWrite(motorPin, speed);
   }
}

Picture of the Circuit with the Photo Resistor



















Schematic Diagram



















Video of Working Circuit


Extension
Photo resistors are used in many devices around our homes and workplaces.  I recently installed a set of motion-sensitive security lights and the photo resistor made me think of those devices.  The photo resistors in the security light respond to changes in the amount of light that they detect; if this change is too drastic, then they send a signal to the controller to switch on the lights.

Although the photo resistor in a security light isn't directly related to the electric motor in this circuit, there are some similar analogues in our world.  Backup sensors on our can work by detecting distance or work by detecting light; those that detect light and stop the car are working in a similar way to the one in my circuit.  The photo resistor and motor circuit could also be used for automatic blinds in your house; if the sun is beaming too brightly, the motor can automatically lower the blinds in your window.

Monday, December 1, 2014

ETEC 597: Maker Movement - Week 5

This week's build allowed me to get my family involved in the process.  Typically, my wife walks in the office, sees me working on the electronics "thingy," turns around, and leaves.  With the addition of the piezo speaker, though, she could actually get some sensory feedback (besides flashy lights) that she could connect to electronics in her life.

It was enjoyable playing around with the code and making the piezo speaker play certain notes and tones.  I am not (nor have I ever been) a music person, so I enlisted the help of some of my band students to help me extrapolate some music to have my speaker output.  I ultimately decided on a Christmas classic, Jingle Bells, as the tune for my Arduino.  The addition of the push button was a little more challenging but definitely doable since we started working with control structures in the programming language.

Code

const int buttonPin = 2;     // pushbutton
const int ledPin =  13;      // on-board LED
const int buzzerPin = 12;    // buzzer

const int songLength = 18;
char notes[] = "cdfda ag cdfdg gf "; // a space represents a rest
int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};
int tempo = 100;

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {

  pinMode(ledPin, OUTPUT); 
  pinMode(buzzerPin, OUTPUT);  

  pinMode(buttonPin, INPUT);    
}

void loop(){

  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {    
    digitalWrite(ledPin, HIGH);

    int i, duration;
  
    for (i = 0; i < songLength; i++) // step through the song arrays
    {
        duration = beats[i] * tempo;  // length of note/rest in ms
        if (notes[i] == ' ')          // is this a rest? 
        {
           delay(duration);            // then pause for a moment
        }
        else                          // otherwise, play the note
        {
           tone(buzzerPin, frequency(notes[i]), duration);
           delay(duration);            // wait for tone to finish
        }
        delay(tempo/10);              // brief pause between notes
     }
  
     // We only want to play the song once, so we'll pause forever:
     while(true){}

  }   
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
    noTone(12);
  }
}

int frequency(char note) 
{
  // This function takes a note character (a-g), and returns the
  // corresponding frequency in Hz for the tone() function.
  
  int i;
  const int numNotes = 8;  // number of notes we're storing
  
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};
  
  // Now we'll search through the letters in the array, and if
  // we find it, we'll return the frequency for that note.
  
  for (i = 0; i < numNotes; i++)  // Step through the notes
  {
    if (names[i] == note)         // Is this the one?
    {
      return(frequencies[i]);     // Yes! Return the frequency
    }
  }
  return(0);  // We looked through everything and didn't find it,
              // but we still need to return a value, so return 0.

}

Code Snippet of Song Change

The notes and beats arrays were the biggest changes when going from the original song to Jingle Bells.

const int songLength = 26;
char notes[] = "eeeeeeegcde fffffeeeeddedg";     //Jingle Bells
int beats[] = {1,1,2,1,1,2,1,1,1,1,4,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2};

int tempo = 300;

Circuit Picture



Circuit Schematics


Sorry for the orientation; I could not get this particular picture to flip.

Videos


Original Tune


Jingle Bells

Extension

I remember my fascination with computer-generated sounds from the time that I started with my first computer (a Tandy RL-1000 at a whopping 8MHz!)  I didn't know exactly how they worked but I was very curious and spent hours upon hours playing around with the MIDI editor that I had installed.  Although sounds are now much more complex (with many more channels and higher bit rates,) the principle is the same.  Sounds are composed of bits of data that control the vibrations of the speaker.  I would like to try this same experiment in the future with a full-size speaker rather than the piezo to see if the vibrations of the speaker can be seen.

Tuesday, November 25, 2014

ETEC 597: Maker Movement - Week 4

The project this time around was especially challenging since it did not directly add on to previous builds.  Google was especially helpful; I found a great resource for building the dice simulator on the Instructables website.  After carefully assembling the circuit (with tweezers because of the small connectors on the resistors), I carefully re-typed the code to load to the Arduino board.  I definitely have more appreciation for the coders that came up with this program after typing it line by line; especially with my affinity for transposing numbers.

Picture of the Arduino Circuit



Arduino Schematics
Circuit with the Switch
Circuit without the Switch

Dice Code
int pinLeds1 = 10;
int pinLeds2 = 9;
int pinLeds3 = 7;
int pinLed4 = 8;
int buttonPin = 6;
int buttonState;
long ran;
int time = 2000;

void setup ()
{
  pinMode (pinLeds1, OUTPUT);
  pinMode (pinLeds2, OUTPUT);
  pinMode (pinLeds3, OUTPUT);
  pinMode (pinLed4, OUTPUT);
  pinMode (buttonPin, INPUT);
  randomSeed(analogRead(0));
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH){
    ran = random(1, 7);
    if (ran == 1){
      digitalWrite (pinLed4, HIGH);
      delay (time);
    }
    if (ran == 2){
      digitalWrite (pinLeds1, HIGH);
      delay (time);
    }
    if (ran == 3){
      digitalWrite (pinLeds3, HIGH);
      digitalWrite (pinLed4, HIGH);
      delay (time);
    }
    if (ran == 4){
      digitalWrite (pinLeds1, HIGH);
      digitalWrite (pinLeds3, HIGH);
      delay (time);
    }
    if (ran == 5){
      digitalWrite (pinLeds1, HIGH);
      digitalWrite (pinLeds3, HIGH);
      digitalWrite (pinLed4, HIGH);
      delay (time);
   }
   if (ran == 6){
      digitalWrite (pinLeds1, HIGH);
      digitalWrite (pinLeds2, HIGH);
      digitalWrite (pinLeds3, HIGH);
      delay (time);
   }
  }
  digitalWrite (pinLeds1, LOW);
  digitalWrite (pinLeds2, LOW);
  digitalWrite (pinLeds3, LOW);
  digitalWrite (pinLed4, LOW);

}

Videos
Circuit with the Switch
Circuit without the Switch

Roll Distributions
You can see that the distribution is nearly normal; my guess is that the outcome of 4 would be on par with the 3 and the 5 if we were to do several more rolls.

Commentary
The complexities of each circuit have definitely increased from week to week.  I have even more appreciation for those EE's that have impacted our life with the electronic tools that we use and love.  Even something as simple as a Dice simulator took some considerable effort; I can only imagine the time and the manpower required to produce a smartphone!  

A good extension to this project would be to envision the programming and circuitry involved in a gaming machine (such as a slot machine) at a casino.  Electronic slot machines or other gaming machines have more circuits than I can imagine with thousands upon thousands of lines of code.  I would like to be able to peer inside of something a little more complex than our Dice simulator one day; perhaps a combination of multiple "Dice" banks would be a better simulation of these games of chance.

Monday, November 17, 2014

ETEC 597: Maker Movement - Week 3

Time management was an issue this past week with upcoming PDAS observations and a sick wife.  It seems that time diminishes as the semester progresses.  My hope is that this next week lends to having a little more time to play around with the Arduino.

Circuit 1
The first circuit involved adding the tri-color LED into a simple circuit.  The circuit consisted of the Arduino controller connected to the LED via the breadboard with a 330-ohm resistor in the middle.  The circuit was fairly simple to build but one of the problems that I discovered was that I had one of my digital outputs in the wrong place (I had the wire running to digital output 8 instead of digital output 11.)  This shorted my program because it did not pass all of the way through the Red-Green-Blue color range.  The lack of red can be seen in the video below.

Circuit 1 Code
/*

Example sketch 03

RGB LED

  Make an RGB LED display a rainbow of colors!
 
Hardware connections:

  An RGB LED is actually three LEDs (red, green, and blue) in
  one package. When you run them at different brightnesses,
  the red, green and blue mix to form new colors.
 
  Starting at the flattened edge of the flange on the LED,
  the pins are ordered RED, COMMON, GREEN, BLUE.
 
  Connect RED to a 330 Ohm resistor. Connect the other end
  of the resistor to Arduino digital pin 9.

  Connect COMMON pin to GND.

  Connect GREEN to a 330 Ohm resistor. Connect the other end
  of the resistor to Arduino digital pin 10.

  Connect BLUE to a 330 Ohm resistor. Connect the other end
  of the resistor to Arduino digital pin 11.

This sketch was written by SparkFun Electronics,
with lots of help from the Arduino community.
Visit http://www.arduino.cc to learn about the Arduino.

Version 2.0 6/2012 MDG
*/


// First we'll define the pins by name to make the sketch
// easier to follow.

// Here's a new trick: putting the word "const" in front of a
// variable indicates that this is a "constant" value that will
// never change. (You don't have to do this, but if you do, the
// Arduino will give you a friendly warning if you accidentally
// try to change the value, so it's considered good form.)

const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;

// This variable controls how fast we loop through the colors.
// (Try changing this to make the fading faster or slower.)

int DISPLAY_TIME = 100;  // In milliseconds


void setup()
{
  // Here we'll configure the Arduino pins we're using to
  // drive the LED to be outputs:

  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}


void loop()
{
  // In this sketch, we'll start writing our own functions.
  // This makes the sketch easier to follow by dividing up
  // the sketch into sections, and not having everything in
  // setup() or loop().

  // We'll show you two ways to run the RGB LED.

  // The first way is to turn the individual LEDs (red, blue,
  // and green) on and off in various combinations. This gives you
  // a total of eight colors (if you count "black" as a color).
   
  // We've written a function called mainColors() that steps
  // through all eight of these colors. We're only "calling" the
  // function here (telling it to run). The actual function code
  // is further down in the sketch.

  mainColors();
 
  // The above function turns the individual LEDs full-on and
  // full-off. If you want to generate more than eight colors,
  // you can do so by varying the brightness of the individual
  // LEDs between full-on and full-off.
 
  // The analogWrite() function lets us do this. This function
  // lets you dim a LED from full-off to full-on over 255 steps.
 
  // We've written a function called showSpectrum() that smoothly
  // steps through all the colors. Again we're just calling it
  // here; the actual code is further down in this sketch.

  showSpectrum();
}


// Here's the mainColors() function we've written.

// This function displays the eight "main" colors that the RGB LED
// can produce. If you'd like to use one of these colors in your
// own sketch, you cancopy and paste that section into your code.

void mainColors()
{
  // Off (all LEDs off):

  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);

  delay(1000);

  // Red (turn just the red LED on):

  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);

  delay(1000);

  // Green (turn just the green LED on):

  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, LOW);

  delay(1000);

  // Blue (turn just the blue LED on):

  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);

  delay(1000);

  // Yellow (turn red and green on):

  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, LOW);

  delay(1000);

  // Cyan (turn green and blue on):

  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, HIGH);

  delay(1000);

  // Purple (turn red and blue on):

  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);

  delay(1000);

  // White (turn all the LEDs on):

  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, HIGH);

  delay(1000);
}


// Below are two more functions we've written,
// showSpectrum() and showRGB().

// showRGB() displays a single color on the RGB LED.
// You call showRGB() with the number of a color you want
// to display.

// showSpectrum() steps through all the colors of the RGB LED,
// displaying a rainbow. showSpectrum() actually calls showRGB()
// over and over to do this.

// We'll often break tasks down into individual functions like
// this, which makes your sketches easier to follow, and once
// you have a handy function, you can reuse it in your other
// programs.


// showSpectrum()

// This function steps through all the colors of the RGB LED.
// It does this by stepping a variable from 0 to 768 (the total
// number of colors), and repeatedly calling showRGB() to display
// the individual colors.

// In this function, we're using a "for() loop" to step a variable
// from one value to another, and perform a set of instructions
// for each step. For() loops are a very handy way to get numbers
// to count up or down.

// Every for() loop has three statements separated by semicolons:

//   1. Something to do before starting

//   2. A test to perform; as long as it's true,
//      it will keep looping

//   3. Something to do after each loop (usually
//      increase a variable)

// For the for() loop below, these are the three statements:

//   1. x = 0;     Before starting, make x = 0.

//   2. x < 768;   While x is less than 768, run the
//                 following code.

//   3. x++        Putting "++" after a variable means
//                 "add one to it". (You can also use "x = x + 1")

// Every time you go through the loop, the statements following
// the loop (those within the brackets) will run.

// And when the test in statement 2 is finally false, the sketch
// will continue.


void showSpectrum()
{
  int x;  // define an integer variable called "x"
 
  // Now we'll use a for() loop to make x count from 0 to 767
  // (Note that there's no semicolon after this line!
  // That's because the for() loop will repeat the next
  // "statement", which in this case is everything within
  // the following brackets {} )

  for (x = 0; x < 768; x++)

  // Each time we loop (with a new value of x), do the following:

  {
    showRGB(x);  // Call RGBspectrum() with our new x
    delay(10);   // Delay for 10 ms (1/100th of a second)
  }
}


// showRGB()

// This function translates a number between 0 and 767 into a
// specific color on the RGB LED. If you have this number count
// through the whole range (0 to 767), the LED will smoothly
// change color through the entire spectrum.

// The "base" numbers are:
// 0   = pure red
// 255 = pure green
// 511 = pure blue
// 767 = pure red (again)

// Numbers between the above colors will create blends. For
// example, 640 is midway between 512 (pure blue) and 767
// (pure red). It will give you a 50/50 mix of blue and red,
// resulting in purple.

// If you count up from 0 to 767 and pass that number to this
// function, the LED will smoothly fade between all the colors.
// (Because it starts and ends on pure red, you can start over
// at 0 without any break in the spectrum).


void showRGB(int color)
{
  int redIntensity;
  int greenIntensity;
  int blueIntensity;

  // Here we'll use an "if / else" statement to determine which
  // of the three (R,G,B) zones x falls into. Each of these zones
  // spans 255 because analogWrite() wants a number from 0 to 255.

  // In each of these zones, we'll calculate the brightness
  // for each of the red, green, and blue LEDs within the RGB LED.

  if (color <= 255)          // zone 1
  {
    redIntensity = 255 - color;    // red goes from on to off
    greenIntensity = color;        // green goes from off to on
    blueIntensity = 0;             // blue is always off
  }
  else if (color <= 511)     // zone 2
  {
    redIntensity = 0;                     // red is always off
    greenIntensity = 255 - (color - 256); // green on to off
    blueIntensity = (color - 256);        // blue off to on
  }
  else // color >= 512       // zone 3
  {
    redIntensity = (color - 512);         // red off to on
    greenIntensity = 0;                   // green is always off
    blueIntensity = 255 - (color - 512);  // blue on to off
  }

  // Now that the brightness values have been set, command the LED
  // to those values

  analogWrite(RED_PIN, redIntensity);
  analogWrite(BLUE_PIN, blueIntensity);
  analogWrite(GREEN_PIN, greenIntensity);
}


Circuit 1 Video


Circuit 2
In circuit 2, I tried to connect the potentiometer to the circuit to change the flash rate of the tri-color LED.  I was not able to have success with this circuit; the potentiometer seemed loose in the breadboard and may not have made complete contact.  I was not able to spend a lot of time troubleshooting the circuit; this project is one that is on the backburner to come back to at some point.

Circuit 2 Code
/*

Example sketch 03

RGB LED

  Make an RGB LED display a rainbow of colors!
 
Hardware connections:

  An RGB LED is actually three LEDs (red, green, and blue) in
  one package. When you run them at different brightnesses,
  the red, green and blue mix to form new colors.
 
  Starting at the flattened edge of the flange on the LED,
  the pins are ordered RED, COMMON, GREEN, BLUE.
 
  Connect RED to a 330 Ohm resistor. Connect the other end
  of the resistor to Arduino digital pin 9.

  Connect COMMON pin to GND.

  Connect GREEN to a 330 Ohm resistor. Connect the other end
  of the resistor to Arduino digital pin 10.

  Connect BLUE to a 330 Ohm resistor. Connect the other end
  of the resistor to Arduino digital pin 11.

This sketch was written by SparkFun Electronics,
with lots of help from the Arduino community.
Visit http://www.arduino.cc to learn about the Arduino.

Version 2.0 6/2012 MDG
*/


// First we'll define the pins by name to make the sketch
// easier to follow.

// Here's a new trick: putting the word "const" in front of a
// variable indicates that this is a "constant" value that will
// never change. (You don't have to do this, but if you do, the
// Arduino will give you a friendly warning if you accidentally
// try to change the value, so it's considered good form.)

const int sensorPin = 0;
const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;

// This variable controls how fast we loop through the colors.
// (Try changing this to make the fading faster or slower.)

int DISPLAY_TIME = 100;  // In milliseconds


void setup()
{
  // Here we'll configure the Arduino pins we're using to
  // drive the LED to be outputs:

  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}


void loop()
{
  // In this sketch, we'll start writing our own functions.
  // This makes the sketch easier to follow by dividing up
  // the sketch into sections, and not having everything in
  // setup() or loop().

  // We'll show you two ways to run the RGB LED.

  // The first way is to turn the individual LEDs (red, blue,
  // and green) on and off in various combinations. This gives you
  // a total of eight colors (if you count "black" as a color).
   
  // We've written a function called mainColors() that steps
  // through all eight of these colors. We're only "calling" the
  // function here (telling it to run). The actual function code
  // is further down in the sketch.
 
  mainColors();
 
  // The above function turns the individual LEDs full-on and
  // full-off. If you want to generate more than eight colors,
  // you can do so by varying the brightness of the individual
  // LEDs between full-on and full-off.
 
  // The analogWrite() function lets us do this. This function
  // lets you dim a LED from full-off to full-on over 255 steps.
 
  // We've written a function called showSpectrum() that smoothly
  // steps through all the colors. Again we're just calling it
  // here; the actual code is further down in this sketch.

  showSpectrum();
}


// Here's the mainColors() function we've written.

// This function displays the eight "main" colors that the RGB LED
// can produce. If you'd like to use one of these colors in your
// own sketch, you cancopy and paste that section into your code.

void mainColors()
{
  // Off (all LEDs off):

  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);

  delay(1000);

  // Red (turn just the red LED on):

  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);

  delay(1000);

  // Green (turn just the green LED on):

  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, LOW);

  delay(1000);

  // Blue (turn just the blue LED on):

  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);

  delay(1000);

  // Yellow (turn red and green on):

  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, LOW);

  delay(1000);

  // Cyan (turn green and blue on):

  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, HIGH);

  delay(1000);

  // Purple (turn red and blue on):

  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);

  delay(1000);

  // White (turn all the LEDs on):

  digitalWrite(RED_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(BLUE_PIN, HIGH);

  delay(1000);
}


// Below are two more functions we've written,
// showSpectrum() and showRGB().

// showRGB() displays a single color on the RGB LED.
// You call showRGB() with the number of a color you want
// to display.

// showSpectrum() steps through all the colors of the RGB LED,
// displaying a rainbow. showSpectrum() actually calls showRGB()
// over and over to do this.

// We'll often break tasks down into individual functions like
// this, which makes your sketches easier to follow, and once
// you have a handy function, you can reuse it in your other
// programs.


// showSpectrum()

// This function steps through all the colors of the RGB LED.
// It does this by stepping a variable from 0 to 768 (the total
// number of colors), and repeatedly calling showRGB() to display
// the individual colors.

// In this function, we're using a "for() loop" to step a variable
// from one value to another, and perform a set of instructions
// for each step. For() loops are a very handy way to get numbers
// to count up or down.

// Every for() loop has three statements separated by semicolons:

//   1. Something to do before starting

//   2. A test to perform; as long as it's true,
//      it will keep looping

//   3. Something to do after each loop (usually
//      increase a variable)

// For the for() loop below, these are the three statements:

//   1. x = 0;     Before starting, make x = 0.

//   2. x < 768;   While x is less than 768, run the
//                 following code.

//   3. x++        Putting "++" after a variable means
//                 "add one to it". (You can also use "x = x + 1")

// Every time you go through the loop, the statements following
// the loop (those within the brackets) will run.

// And when the test in statement 2 is finally false, the sketch
// will continue.


void showSpectrum()
{
  int x;  // define an integer variable called "x"
 
  // Now we'll use a for() loop to make x count from 0 to 767
  // (Note that there's no semicolon after this line!
  // That's because the for() loop will repeat the next
  // "statement", which in this case is everything within
  // the following brackets {} )

  for (x = 0; x < 768; x++)

  // Each time we loop (with a new value of x), do the following:

  {
    showRGB(x);  // Call RGBspectrum() with our new x
    delay(10);   // Delay for 10 ms (1/100th of a second)
  }
}


// showRGB()

// This function translates a number between 0 and 767 into a
// specific color on the RGB LED. If you have this number count
// through the whole range (0 to 767), the LED will smoothly
// change color through the entire spectrum.

// The "base" numbers are:
// 0   = pure red
// 255 = pure green
// 511 = pure blue
// 767 = pure red (again)

// Numbers between the above colors will create blends. For
// example, 640 is midway between 512 (pure blue) and 767
// (pure red). It will give you a 50/50 mix of blue and red,
// resulting in purple.

// If you count up from 0 to 767 and pass that number to this
// function, the LED will smoothly fade between all the colors.
// (Because it starts and ends on pure red, you can start over
// at 0 without any break in the spectrum).


void showRGB(int color)
{
  int sensorValue;
  sensorValue = analogRead(sensorPin);
  int redIntensity;
  int greenIntensity;
  int blueIntensity;

  // Here we'll use an "if / else" statement to determine which
  // of the three (R,G,B) zones x falls into. Each of these zones
  // spans 255 because analogWrite() wants a number from 0 to 255.

  // In each of these zones, we'll calculate the brightness
  // for each of the red, green, and blue LEDs within the RGB LED.

  if (color <= 255)          // zone 1
  {
    redIntensity = 255 - sensorValue;    // red goes from on to off
    greenIntensity = sensorValue;        // green goes from off to on
    blueIntensity = 0;             // blue is always off
  }
  else if (color <= 511)     // zone 2
  {
    redIntensity = 0;                     // red is always off
    greenIntensity = 255 - (sensorValue - 256); // green on to off
    blueIntensity = (sensorValue - 256);        // blue off to on
  }
  else // color >= 512       // zone 3
  {
    redIntensity = (sensorValue - 512);         // red off to on
    greenIntensity = 0;                   // green is always off
    blueIntensity = 255 - (sensorValue - 512);  // blue on to off
  }

  // Now that the brightness values have been set, command the LED
  // to those values

  analogWrite(RED_PIN, redIntensity);
  analogWrite(BLUE_PIN, blueIntensity);
  analogWrite(GREEN_PIN, greenIntensity);
}


Circuit 2 Video


Circuit 3
In circuit 3, I programmed the tri-color LED to remain flashing blue and added a red LED to the circuit.  The two LEDs flashed in an alternate pattern that looked like the type of lights that one would see in a police car.  I also changed up the timing to the LEDs flashed at a more rapid pace.

Circuit 3 Code
/*

Example sketch 03

RGB LED

  Make an RGB LED display a rainbow of colors!
 
Hardware connections:

  An RGB LED is actually three LEDs (red, green, and blue) in
  one package. When you run them at different brightnesses,
  the red, green and blue mix to form new colors.
 
  Starting at the flattened edge of the flange on the LED,
  the pins are ordered RED, COMMON, GREEN, BLUE.
 
  Connect RED to a 330 Ohm resistor. Connect the other end
  of the resistor to Arduino digital pin 9.

  Connect COMMON pin to GND.

  Connect GREEN to a 330 Ohm resistor. Connect the other end
  of the resistor to Arduino digital pin 10.

  Connect BLUE to a 330 Ohm resistor. Connect the other end
  of the resistor to Arduino digital pin 11.

This sketch was written by SparkFun Electronics,
with lots of help from the Arduino community.
Visit http://www.arduino.cc to learn about the Arduino.

Version 2.0 6/2012 MDG
*/


// First we'll define the pins by name to make the sketch
// easier to follow.

// Here's a new trick: putting the word "const" in front of a
// variable indicates that this is a "constant" value that will
// never change. (You don't have to do this, but if you do, the
// Arduino will give you a friendly warning if you accidentally
// try to change the value, so it's considered good form.)

const int RED_LED = 8;
const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;

// This variable controls how fast we loop through the colors.
// (Try changing this to make the fading faster or slower.)

int DISPLAY_TIME = 100;  // In milliseconds


void setup()
{
  // Here we'll configure the Arduino pins we're using to
  // drive the LED to be outputs:

  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
  pinMode(RED_LED, OUTPUT);
}

void loop()
{
  // In this sketch, we'll start writing our own functions.
  // This makes the sketch easier to follow by dividing up
  // the sketch into sections, and not having everything in
  // setup() or loop().

  // We'll show you two ways to run the RGB LED.

  // The first way is to turn the individual LEDs (red, blue,
  // and green) on and off in various combinations. This gives you
  // a total of eight colors (if you count "black" as a color).
   
  // We've written a function called mainColors() that steps
  // through all eight of these colors. We're only "calling" the
  // function here (telling it to run). The actual function code
  // is further down in the sketch.

  mainColors();
 
  digitalWrite(RED_LED, HIGH);   // Turn on the LED

  delay(100);              // Wait for one second
 
  digitalWrite(RED_LED, LOW);    // Turn off the LED
 
  delay(100);              // Wait for one second
 
  // The above function turns the individual LEDs full-on and
  // full-off. If you want to generate more than eight colors,
  // you can do so by varying the brightness of the individual
  // LEDs between full-on and full-off.
 
  // The analogWrite() function lets us do this. This function
  // lets you dim a LED from full-off to full-on over 255 steps.
 
  // We've written a function called showSpectrum() that smoothly
  // steps through all the colors. Again we're just calling it
  // here; the actual code is further down in this sketch.

  //showSpectrum();
}


// Here's the mainColors() function we've written.

// This function displays the eight "main" colors that the RGB LED
// can produce. If you'd like to use one of these colors in your
// own sketch, you cancopy and paste that section into your code.

void mainColors()
{
  // Off (all LEDs off):

  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, LOW);

  delay(100);

  // Red (turn just the red LED on):

  //digitalWrite(RED_PIN, HIGH);
  //digitalWrite(GREEN_PIN, LOW);
  //digitalWrite(BLUE_PIN, LOW);

  //delay(100);

  // Green (turn just the green LED on):

  //digitalWrite(RED_PIN, LOW);
  //digitalWrite(GREEN_PIN, HIGH);
  //digitalWrite(BLUE_PIN, LOW);

  //delay(100);

  // Blue (turn just the blue LED on):

  digitalWrite(RED_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);

  delay(100);

  // Yellow (turn red and green on):

  //digitalWrite(RED_PIN, HIGH);
  //digitalWrite(GREEN_PIN, HIGH);
  //digitalWrite(BLUE_PIN, LOW);

  //delay(100);

  // Cyan (turn green and blue on):

  //digitalWrite(RED_PIN, LOW);
  //digitalWrite(GREEN_PIN, HIGH);
  //digitalWrite(BLUE_PIN, HIGH);

  //delay(100);

  // Purple (turn red and blue on):

  //digitalWrite(RED_PIN, HIGH);
  //digitalWrite(GREEN_PIN, LOW);
  //digitalWrite(BLUE_PIN, HIGH);

  //delay(100);

  // White (turn all the LEDs on):

  //digitalWrite(RED_PIN, HIGH);
  //digitalWrite(GREEN_PIN, HIGH);
  //digitalWrite(BLUE_PIN, HIGH);

  //delay(100);
}


// Below are two more functions we've written,
// showSpectrum() and showRGB().

// showRGB() displays a single color on the RGB LED.
// You call showRGB() with the number of a color you want
// to display.

// showSpectrum() steps through all the colors of the RGB LED,
// displaying a rainbow. showSpectrum() actually calls showRGB()
// over and over to do this.

// We'll often break tasks down into individual functions like
// this, which makes your sketches easier to follow, and once
// you have a handy function, you can reuse it in your other
// programs.


// showSpectrum()

// This function steps through all the colors of the RGB LED.
// It does this by stepping a variable from 0 to 768 (the total
// number of colors), and repeatedly calling showRGB() to display
// the individual colors.

// In this function, we're using a "for() loop" to step a variable
// from one value to another, and perform a set of instructions
// for each step. For() loops are a very handy way to get numbers
// to count up or down.

// Every for() loop has three statements separated by semicolons:

//   1. Something to do before starting

//   2. A test to perform; as long as it's true,
//      it will keep looping

//   3. Something to do after each loop (usually
//      increase a variable)

// For the for() loop below, these are the three statements:

//   1. x = 0;     Before starting, make x = 0.

//   2. x < 768;   While x is less than 768, run the
//                 following code.

//   3. x++        Putting "++" after a variable means
//                 "add one to it". (You can also use "x = x + 1")

// Every time you go through the loop, the statements following
// the loop (those within the brackets) will run.

// And when the test in statement 2 is finally false, the sketch
// will continue.


void showSpectrum()
{
  int x;  // define an integer variable called "x"
 
  // Now we'll use a for() loop to make x count from 0 to 767
  // (Note that there's no semicolon after this line!
  // That's because the for() loop will repeat the next
  // "statement", which in this case is everything within
  // the following brackets {} )

  for (x = 0; x < 768; x++)

  // Each time we loop (with a new value of x), do the following:

  {
    showRGB(x);  // Call RGBspectrum() with our new x
    delay(10);   // Delay for 10 ms (1/100th of a second)
  }
}


// showRGB()

// This function translates a number between 0 and 767 into a
// specific color on the RGB LED. If you have this number count
// through the whole range (0 to 767), the LED will smoothly
// change color through the entire spectrum.

// The "base" numbers are:
// 0   = pure red
// 255 = pure green
// 511 = pure blue
// 767 = pure red (again)

// Numbers between the above colors will create blends. For
// example, 640 is midway between 512 (pure blue) and 767
// (pure red). It will give you a 50/50 mix of blue and red,
// resulting in purple.

// If you count up from 0 to 767 and pass that number to this
// function, the LED will smoothly fade between all the colors.
// (Because it starts and ends on pure red, you can start over
// at 0 without any break in the spectrum).


void showRGB(int color)
{
  int redIntensity;
  int greenIntensity;
  int blueIntensity;

  // Here we'll use an "if / else" statement to determine which
  // of the three (R,G,B) zones x falls into. Each of these zones
  // spans 255 because analogWrite() wants a number from 0 to 255.

  // In each of these zones, we'll calculate the brightness
  // for each of the red, green, and blue LEDs within the RGB LED.

  if (color <= 255)          // zone 1
  {
    redIntensity = 255 - color;    // red goes from on to off
    greenIntensity = color;        // green goes from off to on
    blueIntensity = 0;             // blue is always off
  }
  else if (color <= 511)     // zone 2
  {
    redIntensity = 0;                     // red is always off
    greenIntensity = 255 - (color - 256); // green on to off
    blueIntensity = (color - 256);        // blue off to on
  }
  else // color >= 512       // zone 3
  {
    redIntensity = (color - 512);         // red off to on
    greenIntensity = 0;                   // green is always off
    blueIntensity = 255 - (color - 512);  // blue on to off
  }

  // Now that the brightness values have been set, command the LED
  // to those values

  analogWrite(RED_PIN, redIntensity);
  analogWrite(BLUE_PIN, blueIntensity);
  analogWrite(GREEN_PIN, greenIntensity);
}


Circuit 3 Video


Circuit 4
In circuit 4, added a series of yellow LEDs to the "police car" circuit.  The most difficult part of building this circuit was making sure the LED's were wired in series and making a complete path to the power source and the Arduino board.

Circuit 4 Code
Circuit 4 Code did not differ from that of Circuit 4; the yellow LEDs were wired to the output of the Red LED.

Circuit 4 Video


The circuits that were constructed this week were a step above the previous circuits.  I enjoyed being able to piece together the previous circuits that we built to come up with a unique circuit that encompasses previous knowledge.  This is the essence of making - building on prior knowledge to create a design or project to impact others.