Files
ESPEasy/_P002_ADC.ino
T
mvdbro f26a553141 Added HC-SR04
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
2015-09-13 10:47:29 +02:00

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;
}