UPD: I forgot to paste the important part, this:
#error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
I want to show angular value (0-300) upstream to Home Assistant as a sensor, and lockstep to it from there to control home assistant services - volume control, scene selector, media seek, etc.
Mysensors 2.11 in arduino, gateway is still 2.0. This is the sensor, not the same as encoder evidently:
http://wiki.seeed.cc/Grove-Rotary_Angle_Sensor/
and the code. Thanks!
#include <SPI.h>
#include <GroveEncoder.h>
#include <MyConfig.h>
#include <MySensors.h>
#define ROTARY_ANGLE_SENSOR A0
#define ADC_REF 5//reference voltage of ADC is 5v.If the Vcc switch on the seeeduino
//board switches to 3V3, the ADC_REF should be 3.3
#define VCC 5//VCC of the grove interface is normally 5v
#define FULL_ANGLE 300//full value of the rotary angle is 300 degrees
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
#define SN "RotaryAngleSensor"
#define SV "1.0"
#define CHILD_ID
unsigned long SLEEP_TIME = 100
Rotary Angle Sensor;
MyMessage msg(CHILD_ID, V_VAR1);
int lastDegrees;
void setup()
{
Serial.begin(9600);
pinsInit();
sendSketchInfo(SN, SV);
present(CHILD_ID, S_CUSTOM);
}
void loop()
{
int degrees;
degrees = getDegree();
Serial.println(degrees);
if (degrees != lastDegrees) {
send(msg.set(degrees));
lastDegrees = degrees;
}
sleep(SLEEP_TIME);
}
void pinsInit()
{
pinMode(ROTARY_ANGLE_SENSOR, INPUT);
}
/************************************************************************/
/*Function: Get the angle between the mark and the starting position */
/*Parameter:-void */
/*Return: -int,the range of degrees is 0~300 */
int getDegree()
{
int sensor_value = analogRead(ROTARY_ANGLE_SENSOR);
float voltage;
voltage = (float)sensor_value*ADC_REF/1023;
float degrees = (voltage*FULL_ANGLE)/VCC;
return degrees;
}```