Nick's Lab 2 Report


a. What line(s) of code do you need to change to make the LED blink (like, at all)?

 

None of the lines of code need to be changed in order for the LED to blink.

b. What line(s) of code do you need to change to change the rate of blinking?

 

In order to change the rate of blinking, you must change the lines of code with "delay(1000);" because the delay function dictates how long the LED stays either on or off before switching back to the other mode.

c. What circuit element would you want to add to protect the board and LED?

 

A resistor should be added to protect the board and LED.

a. Which lines do you need to modify to correspond with your button and LED pins? 

 

I need to modify the line "const int led = 13" to say "const int led = 9" because my LED is connected to pin 9. My button is connected to pin 2 so no other lines need to be modified.

 

b. Modify the code or the circuit so that the LED lights only while the button is depressed. Include your code in your lab write-up.

 

const int buttonPin = 2;     // the number of the pushbutton pin

const int ledPin =  9;      // the number of the LED pin

 

// variables will change:

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

 

void setup() {

  // initialize the LED pin as an output:

  pinMode(ledPin, OUTPUT);      

  // initialize the pushbutton pin as an input:

  pinMode(buttonPin, INPUT);     

}

 

void loop(){

  // read the state of the pushbutton value:

  buttonState = digitalRead(buttonPin);

 

  // check if the pushbutton is pressed.

  // if it is, the buttonState is HIGH:

  if (buttonState == LOW) {     

    // turn LED on:    

    digitalWrite(ledPin, HIGH);  

  } 

  else {

    // turn LED off:

    digitalWrite(ledPin, LOW); 

  }

}

a) Which line(s) of code do you need to modify to correspond with your LED pin?

 

None of the lines of code have to be modified to correspond with the LED pin.

b) How would you change the rate of fading?

 

In order to change the rate of fading, I could either change the rate at which fadeValue increases/decreases in the for loop, or I could change the value in the delay() function to make it wait longer or shorter before changing the brightness of the LED.

a. What is the minimum resistor size that should be used with these LEDs? (Hint: think about your voltage supply and what the diode voltage drop means.) 

 

The Arduino gives a supply of 5V, and the superbright LED has a voltage drop of 3.2V, so there will be 1.8V going across the resistor. The maximum current across the LED is 30 mA, so the minimum resistor size to be used is 60 Ohms ( (5V - 3.2V) / .03 A = 60 Ohms).

a. Is there computation in your device? Where is it? What do you think is happening inside the "computer?"

 

There is no computation inside my device.

b. Are there sensors on your device? How do they work? How is the sensed information conveyed to other portions of the device?

 

There is a sensor on my device. When the protruding button is pushed, it closes the circuit inside, and when it is pushed a second time, it opens the circuit.

c. How is the device powered? Is there any transformation or regulation of the power? How is that done? What voltages are used throughout the system?

 

The device is powered using a 5V power supply. The power is regulated using a resistor. There is a 1.85V drop across the red LED, so 3.15V are going across the circuit.

d. Is information stored in your device? Where? How?

 

No information is stored in my device, as there is no data storage device inside.