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


Lab 2 - Spencer Shulem

Page history last edited by spshulem@... 9 years, 3 months ago




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


change the LED to pin 11


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


delay(1000)… change the (1000) part to how ever many milliseconds you want.


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





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


You need to add a variable for the button to tell it which pin it is at… i.e. = const int buttonAtP = 2;


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.




  Turns on an LED only while the button is depressed




 //declare where each thing is at in the curcuit

const int buttonAtP = 2;

const int ledAtP = 9;


//since this variable changes not a const

int buttonState = 0;


void setup() {


  //saying the led is an output (port 9)

  pinMode(ledAtP, OUTPUT);

  //saying that the button is an input (port 2)

  pinMode(buttonAtP, INPUT);




void loop() {

  //check which state it is at

  buttonState = digitalRead(buttonAtP);


  //check if it is down - so turn the light on

  if(buttonState == LOW){

     digitalWrite(ledAtP, HIGH);

  } else {

    //if it is up then turn it off

    digitalWrite(ledPin, LOW);





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


int ledAtP should designate as one of the outputs.

create int buttonAtP = 2;


b) How would you change the rate of fading?


change the delay


c) (Extra) 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?


by having the resistance lower by 1 and then delay in a loop.



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


1.8v/(30x10 ^-3a) = 60 (ohms)

5.0v = 3.2 = 1.8v



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


There is a micro controller that is part of the circuit to control which switch turns on which LED. It is placed at the center of the circuit.


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




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 plugs that you can plug in 5V (which it says next to the positive and ground).. so I just plugged in a 5v battery.


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


The only information that I could think is stored is which switch is on and which switch is on so the micro controller can tell which LED to turn on accordingly. 




Comments (1)

Benjamin Tee said

at 5:35 pm on Jul 24, 2011

Great job! Maybe resize your image and provide caption next time for easier reading?

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