| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

Pranav Rajpurkar_Lab2

Page history last edited by Pranav Rajpurkar 9 years, 3 months ago

Part A

 

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

pinMode(11, OUTPUT);

digitalWrite(11, HIGH);

digitalWrite(11, LOW);

 

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

The two lines:

delay(1000);

 

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

It is imperative to add a resistor to the circuit to prevent the LED from blowing up.

 

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

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

const int ledPin = 13; to const int ledPin =9; // the number on the LED pin

 

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.

Change if(buttonState==HIGH) to if (buttonState == LOW)

 

Full code:

const int buttonPin = 2; 

const int ledPin = 9; 

int buttonState = 0; 

void setup() {

pinMode(ledPin, OUTPUT);

pinMode(buttonPin, INPUT);

}

void loop(){

buttonState = digitalRead(buttonPin);

if (buttonState == LOW) {

digitalWrite(ledPin, HIGH);

}

else {

digitalWrite(ledPin, LOW);

}

}

 

Which lines of code do you need to modify to correspond with your button and LED pins?

int ledPin = 9; // LED connected to digital pin 9

 

b) How would you change the rate of fading?

fadeValue +=5 //change the fade increase rate

delay(30); //change the delay time

 

Since the human eye doesn't see increases in brightness linearly how could you change the code to make the light appear to fade linearly?

The fadeValue should change logarithmically:  fadeValue+=sqrt(fadeValue) when fading in and : fadeValue-=sqrt(fadeValue) when fading out.

 

Part B

 

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 voltage drop across the LED is 3.2 V. Since the total voltage supplied is 5 V, the voltage across the resistor is 5-3.2 = 1.8 V.

Since R = V/I ,

R= 1.8/0.03 = 60 ohms.

 

2. Take apart your electronic device, and draw a schematic of what is inside.

 

Using this photo to draw a schematic:

Comments (1)

Benjamin Tee said

at 5:58 pm on Jul 24, 2011

Good job! Next time include some videos to show your hack operating.

You don't have permission to comment on this page.