Zajac_Lab2


Richard Zajac

Lab 2 – Report

EE-47

 

1.

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

To make the LED blink, the code needs to be changed such that “pinMode(13, OUTPUT);” reads “pinMode(11, OUTPUT);” ”digitalWrite(13, HIGH)” reads “digitalWrite(11, HIGH)” and “digitalWrite(13, LOW)” reads “digitalWrite(11, LOW)”, thus changing the Arduino ‘canned’ code to control the Teensy hardware.

 

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

To change the rate of blinking, the code needs to be changed such that the original code:

-----------------------------------------------------

digitalWrite(11, HIGH); // set the LED on

delay(1000); // wait for a second

digitalWrite(11, LOW); // set the LED off

delay(1000);

-----------------------------------------------------

now reads:

-----------------------------------------------------

digitalWrite(11, HIGH); // set the LED on

delay(500); // wait for a second

digitalWrite(11, LOW); // set the LED off

delay(500);

-----------------------------------------------------

and thus each of the deays in the blinking times, after the on, and off commands, respectively are cut in half by halving the delay ms values.

 

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

 I would want to add a resistor to protect the board and LED.

 

2. Toggle LEDs on and off using the Teensy

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

I need to change the line that reads: “const int ledPin = 13;” to “const int ledPin = 9;” in order to control the LED.

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.

The relavent portion of the code is as follows:

  if (buttonState == HIGH) {

// turn LED on (My note, this now equals 'off':

digitalWrite(ledPin, LOW);

}

else {

// turn LED off(My note, this now equals 'on':

digitalWrite(ledPin, HIGH);

}

 

3. Fading LEDs on and off using the Teensy 

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

The LED pin is already set to pin 9, and the button can be controlled with a while statement, as well as defining “const int buttonPin = 2;”, also initializing “ pinMode(buttonPin, INPUT); . In addition, I added “int buttonState = 0;”. I have included the code in its final entirety below, with all modifications, including those not named above.

 

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

const int ledPin = 9;

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() {

buttonState = digitalRead(buttonPin);

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

for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {

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

analogWrite(ledPin, fadeValue);

// wait for 30 milliseconds to see the dimming effect

delay(30);

}

 

while(buttonState == HIGH){

 

buttonState = digitalRead(buttonPin);

// do something repetitive 200 times

digitalWrite(ledPin, LOW);

}

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

for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {

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

analogWrite(ledPin, fadeValue);

// wait for 30 milliseconds to see the dimming effect

delay(30);

}

 

}

 

b) How would you change the rate of fading?

I would change the rate of fading by modifying the fade string:delay(30); such that it would read a higher, delay(300);or lower, delay(3); number, respectively, to change the rate.

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?

To make the light appear to fade linearly, I would need to change the code to address the logarithmic perceived luminosity changes addressed in the Weber-Fechner Law seen at :

http://www.stanford.edu/class/ee368b/Handouts/09-HumanPerception.pdf

-----------------------------------

"Weber-Fechner Law”

ΔL = cLB where c = 0.01 ... 0.02

-----------------------------------

Good job finding the references. So how would you change the code? 

Part B.

 

1. Super bright LEDs

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

 

5V – 3.2V = 1.8V

1.8V/0.03A=R (in Ohms)

60 Ohms.

 

The minimum resistor size that should be used with these LEDs is: 60 Ohms

 

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

 

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

There is computation in the device. The microchip of the mouse is calculating the position of the mouse in real-time based off the output from the laser and corresponding sensor on the bottom of the mouse.

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

As stated above, there is a sensor in the device, the laser on the bottom of the mouse reflects back, and the beam is analyzed in the microchip to ultimately track x,y coordinates of the cursor on-screen. On the PCB, the bottom sensor is linked to 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 from the +5V and ground USB connection. The device appears to run wholly off of this five-volt line voltage. It is possible that there is regulation for the actual laser, as it is plausible that that is not naturally a five-volt component.

d. Is information stored in your device? Where? How?The only information stored in the device, aside from the firmware burned into the EEPROM is likely the buffer data from the mouse’s movement to the USB protocol.

 

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

 This device was broken, and thus, non-functional when I found it in the bin. I cut the USB cable, and re-attached the frayed leads, but this time, I took the +5V Hot, and Ground, and attached them to the third pin from the top on the right, and the fifth pin from the bottom on the left of the microchip. This made the device now a USB powered light with one important feature. It incorporated the proximity sensor, and preserved the ‘dimming and brightening based on motion’ functionality by tapping pins 3L and 4R.

4. Build your light!

 

Include any schematics or photos in your lab write-up.