“Lesson 8--Microduino "Pulse Recorder"”的版本间的差异
(→Result) |
|||
第76行: | 第76行: | ||
==Result== | ==Result== | ||
− | For stabilization, add a ceramic capacitor in the signal change port. You | + | For stabilization, add a ceramic capacitor in the signal change port. You will be able to see better results. |
[[File:lesson8-capacitance.jpg|600px|center|thumb]] | [[File:lesson8-capacitance.jpg|600px|center|thumb]] | ||
[[File:lesson8Result.jpg|600px|center|thumb]] | [[File:lesson8Result.jpg|600px|center|thumb]] |
2015年7月13日 (一) 22:25的版本
Language | English |
---|
目录ObjectiveIn lesson 3, you learned how to use a button and avoid the issue of electrical noise. The solution was to add a short delay. However, this solution has a disadvantage. Different people will take different amounts of time to press a button. That means the delay must be different for different people, too. This lesson will teach you how to get the duration that a button is pressed down. This program uses pulse timing calculation. In addition, you will learn about Arduino's serial port to monitor the data. Equipment
PulsePulse is a rapid, transient change in the amplitude of a signal from a baseline value to a higher or lower value, followed by a rapid return to the baseline value. In Microduino, pulse is simply a digital signal which changes between high and low in a cyclical pattern. Pulse timing is often used to calculate the speed in electronic components. Experiment SchematicUsing the internal pull-up, also connect an external ceramic capacitor for stabilization. Programint pin = 2; //Define Pin D2
float time1,time2; //Define variables to float
void setup()
{
Serial.begin(115200); //Serial port baud rate
pinMode(pin, INPUT_PULLUP); //Set pin to input mode with the internal pull-up
}
void loop()
{
//Read low pulse from the pin, the maximum pulse interval is 60 seconds, and assign the result to the variable time1
time1= pulseIn(pin, LOW, 60000000)/1000; //Convert the time to ms
Serial.print(time1); //Output the time1 by serial
Serial.print("ms ");
time2= pulseIn(pin, LOW,60000000)/1000.0; //Convert the time to ms
Serial.print(time2); //Output time1 by serial
Serial.println("ms"); //Output time2 by serial and start a new line
}
Serial MonitoringOpen the serial port monitor
pulseIn() usage
ResultFor stabilization, add a ceramic capacitor in the signal change port. You will be able to see better results. Video |