| 
  • 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
 

Lab2 writeup

Page history last edited by Benjamin Tee 8 years ago

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

The line with

pinMode(13, OUTPUT);

should be

pinMode(11, OUTPUT);

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

One could change the integer inside the lines with

delay(1000);

to a different number to change the rate of blinking.

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

One would have to add a resistor so that it doesn't exceed maxium current rating.

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

const int ledPin =  13;

should be

const int ledPin =  9;

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

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);
  }
}

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

None

b) How would you change the rate of fading?

Change the lines

delay(30); or

 for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) (change the fadeValue so that it changes in bigger chunks)

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?

You would have to change the fadeValue so that it increases expotentially as opposed to linearly

something like using the inverse square law (i.e. multiply by 1.414 or divide by 0.707

1. 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.)
(5-3.2)/0.03 = 60 ohms

2. I am using a toy

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

There is a microcontroller. It is covered by a black waxy dot on the back. Inside the computer it is deciding which button was pushed, what sound to play, and outputting that sound to the speaker.

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

The buttons are sensors. When the button is pushed, the circuit is closed and sound plays. The information is passed through the microcontroller.

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 by 2 1.5V batteries. No regulation that I could see. Most of the voltage use was due to the speaker and it took around 1.5 V.

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

The only persistant information is on the microcontroller.

Comments (1)

Benjamin Tee said

at 10:13 am on Jul 22, 2012

Good job! Do you have videos of your frankenlights?

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