mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
Added support for the HC-SR04 Ultrasonic distance sensor Input switch can now be set to send switch state or dimvalue Other minor internal changes
42 lines
1.3 KiB
Arduino
42 lines
1.3 KiB
Arduino
//#######################################################################################################
|
|
//#################################### Plugin 002: Analog ###############################################
|
|
//#######################################################################################################
|
|
|
|
#define PLUGIN_002
|
|
#define PLUGIN_ID_002 2
|
|
|
|
boolean Plugin_002(byte function, struct EventStruct *event, String& string)
|
|
{
|
|
boolean success = false;
|
|
|
|
switch (function)
|
|
{
|
|
|
|
case PLUGIN_DEVICE_ADD:
|
|
{
|
|
Device[++deviceCount].Number = PLUGIN_ID_002;
|
|
strcpy(Device[deviceCount].Name, "Analog input");
|
|
Device[deviceCount].Type = DEVICE_TYPE_ANALOG;
|
|
Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
|
|
Device[deviceCount].Ports = 0;
|
|
Device[deviceCount].PullUpOption = false;
|
|
Device[deviceCount].InverseLogicOption = false;
|
|
Device[deviceCount].FormulaOption = true;
|
|
Device[deviceCount].ValueCount = 1;
|
|
strcpy(Device[deviceCount].ValueNames[0], "Analog");
|
|
break;
|
|
}
|
|
|
|
case PLUGIN_COMMAND:
|
|
{
|
|
int value = analogRead(A0);
|
|
UserVar[event->BaseVarIndex] = (float)value;
|
|
Serial.print("ADC : Analog value: ");
|
|
Serial.println(value);
|
|
success = true;
|
|
break;
|
|
}
|
|
}
|
|
return success;
|
|
}
|