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

  • Get control of your email attachments. Connect all your Gmail accounts and in less than 2 minutes, Dokkio will automatically organize your file attachments. You can also connect Dokkio to Drive, Dropbox, and Slack. Sign up for free.

View
 

Lab 2 - June 2

Page history last edited by Vivien Tsao 6 years, 11 months ago

Part 1

 

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

 digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)

 digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW

When you change the HIGH and the LOW

✓ do you need to do so in this case?

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

delay(1000);               // wait for a second

When you change the number in front of the delay is when you change the blinking rate

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

A resistor can do this

Part 2

 

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

I need to modify these lines to correspond with the button and the LED

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

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.

 

// constants won't change. They're used here to
// set pin numbers:
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 == HIGH) {    
    // turn LED on:   
    digitalWrite(ledPin, LOW); 
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, HIGH);
  }
}

Part B - 3. Fadding LEDs

 

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

int ledPin = 9;    // If a change this number "9", I will change the pin that correspond to the LED

b) How would you change the rate of fading?

I understand as the rate of fading, the time that took to the LED fade.... in this case I need to change

the delay time, just by change the number that follows the delay, 

The first delay correspond to the time that the LED takes to be ON and the second one to the time that the LED takes to be OFF

delay(50)

c) (Extra) Since the human eye doesn't see increases in brightness linearly and the diode brightness is also nonlinear with voltage, how could you change the code to make the light appear to fade linearly?

 

 

Part C. Frankenlight

 

1. Super bright LEDs

We have included some nifty superbright LEDs in your kit. They are clear and have two leads. The link to their datasheet is here. They have ~3.2V forward drop, and a max current rating of 30mA.

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.) 

Vres = Vbat-Vled

Vres = 5V - 3.2V

Vres = 1.8V

 

V=r*i

1.8 =r * 0.030

r = 60 Ohm's

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

 Drawn in the notebook

 

My Frankenlight

 

http://www.youtube.com/watch?v=1EdRsxv5vf8

 

 

 

Comments (1)

Vivien Tsao said

at 12:59 am on Jul 15, 2013

Good job! Please put up pics of your schematic next time.

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