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

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Benjamin Tee Lab2

Page history last edited by Benjamin Tee 12 years, 9 months ago

Benjamin Tee EE-47 Lab 2

(cktee)

1.

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

Simply comment out Line 20: digitalWrite(ledPin, HIGH)

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

Line 21: delay(1000);

Line 23: delay(1000);

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

 A resistor from LED to ground in series.

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

Line 30: const int ledPin = 9; Change to Pin 11.

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.

See Appendix.

3.

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

I added the function fadeInOut to the button program so that when I pressed the button, it starts fading. Otherwise, it just stays lit. I used pin 10 for the LED.

b) How would you change the rate of fading?

Change the fadeValue+= or fadeValue-= value in the for loop. I created an int fadeValuePreset and replaced the for loop to use that value in the increments.

See appendix for code.

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?

We need to increase the step size logarithmically. One possibility is to use fadeValue+=fadeValue in the increment so that the increase is logarithmic. In this case, it goes like 1, 2, 4, 8, 16, … so powers of 2.

See appendix for code.

Part B

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

Resistance of LED: 3.2/0.03 = 107 ohm.

So 5/(107+R)<0.030 => R > 60 ohm.

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

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?

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

3. Using your schematic, figure out where a good point would be to hijack your device and implant an LED.

/ 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 = 11; // 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);

}

}

 

/*

Button

Turns on and off a light emitting diode(LED) connected to digital

pin 13, when pressing a pushbutton attached to pin 2.

The circuit:

* LED attached from pin 13 to ground

* pushbutton attached to pin 2 from +5V

* 10K resistor attached to pin 2 from ground

* Note: on most Arduinos there is already an LED on the board

attached to pin 13.

created 2005

by DojoDave <http://www.0j0.org>

modified 28 Oct 2010

by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/Button

*/

 

// 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 = 10; // the number of the LED pin

int fadeValuePreset=10;

 

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

Serial.begin(9600);

}

 

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, LOW);

int numTimes=2;

fadeInOut(fadeValuePreset, numTimes);

}

}

 

void fadeInOut (int fadeValuePreset, int numTimes)

{

int i=0;

while(i <= numTimes) {

for(int fadeValue = 1 ; fadeValue <= 255; fadeValue +=fadeValue) {

// sets the value (range from 0 to 255):

Serial.println(fadeValue);

analogWrite(ledPin, fadeValue);

// wait for 30 milliseconds to see the dimming effect

delay(30);

}

 

// fade out from max to min in increments of 5 points:

for(int fadeValue = 255 ; fadeValue >= 1; fadeValue -=int(sqrt(fadeValue))) {

// sets the value (range from 0 to 255):

Serial.println(fadeValue);

analogWrite(ledPin, fadeValue);

// wait for 30 milliseconds to see the dimming effect

delay(30);

}

Serial.println(i);

i++;

}

}

 

Comments (1)

Akil Srinivasan said

at 4:05 pm on Aug 15, 2011

Good answers, of course. I couldn't find your Frankenlight photos, schematics, and hacking .. did you upload them?

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