如何在arduino中添加子程序
我现在在写一个只能家居的程序,想把所有判断执行语句写进子程序里,却发现无法运行,这该怎么办呢,程序贴在下面。
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
} //摄氏温度度转化为华氏温度
double Kelvin(double celsius)
{
return celsius + 273.15;
} //摄氏温度转化为开氏温度
#include <dht11.h>
#include <Stepper.h>
#define STEPS 100
Stepper stepper(STEPS, 8, 10,9, 11);
dht11 DHT11;
#define DHT11PIN 2
int motorpin=3;
void setup()
{
analogWrite(motorpin,0);
Serial.begin(9600);
Serial.println();
}
void loop()
{
stepper.setSpeed(90);
Serial.println("\n");
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (oC): ");
Serial.println((float)DHT11.temperature, 2);
Serial.print("Temperature (oF): ");
Serial.println(Fahrenheit(DHT11.temperature), 2);
Serial.print("Temperature (K): ");
Serial.println(Kelvin(DHT11.temperature), 2);
bhf();
}
void bhf ()
{
int i;
i=(float)DHT11.temperature;
if(i<25)
{
analogWrite(motorpin,105);
stepper.step(2048);
}
else
{
analogWrite(motorpin,255);
}
}