超声波模块源码:
const int TrigPin = A2;
const int EchoPin = A3;
float distance;
void setup() {
Serial.begin(9600);
pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);
Serial.println("Ultrasonic sensor:");
}
void loop() {
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
distance = pulseIn(EchoPin, HIGH) / 58.00;
Serial.print("distance is :");
Serial.print(distance);
Serial.print("cm");
Serial.println();
delay(1000);
}
点灯科技小爱同学语音控制源码:
#define BLINKER_WIFI
#define BLINKER_MIOT_OUTLET
#include <Blinker.h>
int relayPin =D1;
bool oState = false;
void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) {
digitalWrite(D1, HIGH);
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
oState = true;
delay(10000);
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(D1, LOW);
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
oState = false;
}
}
void miotQuery(int32_t queryCode)
{