Project 2: Copcar Lights

During this week's lessons we experimented with the potentiometer. I started with the example code provided and then I rewrote the entire code with different names for the variables, just to check if I could follow what information was being used and where it was needed in the code.

Reflection: One of the more humbling points was after I successfully rewrote the code I showed my wife. She thought it was pretty cool as she is always very supportive. I then attempted to complete one of the circuit play activities to get both devices to run through the digital ports. During this portion I wanted to dive in a little deeper and I discovered the print.read command, I documented this process in my previous post. It took me about two hours to fix and debug this activity, after which point I showed my wife again. It then dawned on me that from her perspective I had done pretty much nothing, the LED still flashed the same as before, but I knew that I had made great strides in my personal understanding of the arduino. This goes to show, not all learning is directly obvious in the finished product.

The final challenge of the week tasked me with making two lights flash opposite of each other. This was very similar to the robotics I teach my students where I make them turn motors on and off independently of each other. From that experience I knew that I needed to added another line of code for the second LED. (Code copied at the bottom). Here is the video of the project working.



As with my last project, I always like extending these arduino activities into a real-world situation. Just before I finished the last part of the project my Wife and I were watching LivePD and I got thinking that I could replicated the flashing lights of the cop cars. It was surprisingly easy to make this adjustment because my kit included an RGB LED, with two legs representing Red and Blue. I moved the wires from the two independently LEDs to the appropriate legs of the RGB LED. The resulting code was exactly the same, producing this video:





/*

Week 2
POTENTIOMETER
Travis Ray

Connections:
Potentiometer A5(+), A6 (analog 0), A7 (-)
LED G21 -> G22 
Resistor J22 -> -
H
*/

//Declare Global Variables:

int potentio_port = 0;    // The potentiometer is connected to analog pin 0                   
int ledPin = 13;      // The LED is connected to digital pin 13
int ledPin2 = 12;     //  second LED connected to pin 12
int potentio; //Declare variable for potentiometer


void setup() // this function runs once when the sketch starts up
{
  
  pinMode(ledPin, OUTPUT); //Setup LED (dig 13) as an output
  pinMode(ledPin2, OUTPUT); //setup LED2 (dig 12) as output
  

  //Serial.begin(9600);//Starts Serial Library (To Debug Variable)

}


void loop() // this function runs repeatedly after setup() finishes
{

  potentio = analogRead(potentio_port);//Stores current value of potentiometer
//Serial.print(potentio); //prints current value of potentiometer to computer screen
//Serial.print("\t"); //tabs

  digitalWrite(ledPin, HIGH);     // Turn the LED on
  digitalWrite(ledPin2, LOW);     //Turn off LED2

  delay(potentio);             // Pause for sensorValue
  
  digitalWrite(ledPin, LOW);      // Turn the LED off
  digitalWrite(ledPin2, HIGH);    // Turn on LED2

  delay(potentio);             // Pause for sensorValue
                                  // milliseconds
  

}

Comments

Popular posts from this blog

Week 3: Times Square and Multiple Inputs