我有一项三周未交的作业,但是我的老师仍然希望我把它交出来,因为它值15 %。我的方法是使用超声波测距仪和LED条来测量物体离物体有多近,但我不知道从哪里开始。请帮帮我!
发布于 2015-06-17 09:22:29
这取决于你所拥有的零件。检查每个设备的说明书,并考虑如何与它们通信(例如读取模拟输入或使用SPI进行通信等)。拥有设备部件编号的快速Google还应该提供库和示例代码,如果它是一个受欢迎的设备。
此外,代码的复杂性取决于项目的可交付性(即您的代码标记了还是只检查了功能)。
代码的一个简单解决方案是具有以下结构的循环和一些函数:
// declare any variables you need for your processing below
void setup() {
// Set up your pins here
}
void loop() {
ReadRange();
// process ultrasonic ranger input here
OutputLED(/*either pass a variable here or leave the variable global - Loads of ways to run this*/);
//Add a delay here to slow down the response (if it's very noisy (very dodgy low pass filter)
}
void ReadRange(){
// code that reads the range using methods that you will research
}
void OutputLED(/*depends if you want to pass variables*/){
// code that outputs to the LEDs using methods that you will research
}编辑:所以我只是想添加一下,如果你在编码时也被标记了,你可以把变量定位到函数中,然后传递给你等等。我不会详细讨论这些信息,因为这些信息在网上很容易获得,因此我会教你基本的编码。
https://stackoverflow.com/questions/30886760
复制相似问题