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.
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)
Lab: Analog In with an Arduino
1 Lab that follows the video of “Analog Input”
2 Lab of “Analog Output”
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!)
4 Wiring a photocell to measure light
5 find your sensor range
1 photocell & 1 LED
6 1 photocell &1 FSR & 2 LEDs
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
2 Count button presses
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
4 Threshold Detection
5 Detecting a Peak Value