Week2 – Labs Document – Input & Output

Lab: Digital Input and Output

1 Everything goes pretty well when I try to set the pushbutton to control 2 LEDs through programming. The physical output does consistent with my expectations. And I also measure the changes in voltage across the pushbutton. 


w2p1

2 But after I tried to replace the LED with a speaker and write the code as figure 1, the speaker was not working. If I add the delay() after the tone(), as figure 2, it works. I still haven’t figured out the reason. (Q)

w2p3 w2p2

Lab: Analog In with an Arduino

1 Lab that follows the video of “Analog Input”

w2p5   w2p4

2 Lab of “Analog Output”

w2p6

Code Note: 1 analogRead(10 bits) — INPUT; analogWrite(8 bits) — OUTPUT; 2 const int: the pointer can point to a constant int and the value of the int pointed by this pointer cannot be changed. 3

3 Replacing the LED with a speaker. (Remember give a good enough tonal range!)

w2p16

4  Wiring a photocell to measure light

w2p8

5 find your sensor range

1 photocell & 1 LED

w2p9

6 1 photocell &1 FSR & 2 LEDs

w2p10

1 photocell & 1LED & 1FSR & 1Speaker

Code Note: For sensor to control digital input: analogWrite(pinMode, variables (brightness, pitch))

Lab: Sensor change detection

1 Read the pushbutton statement change

w2p11

2 Count button presses

 w2p12

I found that the pressing condition would be recorded continuously by the serial monitor, so I give a delay after the comparison. But the value of delay was tested by several times, does the value come from experience?  And can the delay be replaced by millis? I guess. (Q)

3 Long press & Short press

w2p13

4 Threshold Detection

w2p14

5 Detecting a Peak Value

w2p15

Leave a Reply

Your email address will not be published. Required fields are marked *