Hello) I need help! In last line of code I see error:
48: error: 'bar' was not declared in this scope
I know English language very badly!!!!! I understand the error, but I can't fix it.
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneEthernet.h> // Change this to use a different communication device. See Communications examples.
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "AuthenticationToken";
// Virtual Pin of the widget.
#define VIRTUAL_PIN V1
void setup()
{
Serial.begin(9600);
Cayenne.begin(token);
}
void loop()
{
Cayenne.run();
// MEASUREMENT
// make 16 readings and average them (reduces some noise) you can tune the number 16 of course
int count = 16;
int raw = 0;
for (int i=0; i< count; i++) raw += analogRead(A0); // return 0..1023 representing 0..5V
raw = raw / count;
// CONVERT TO VOLTAGE
float voltage = 5.0 * raw / 1023; // voltage = 0..5V; we do the math in millivolts!!
// INTERPRET VOLTAGES
float bar = mapFloat(voltage, 0.5, 4.5, 0.0, 8.0); // variation on the Arduino map() function
}
float mapFloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(VIRTUAL_PIN)
{
// Read data from the sensor and send it to the virtual channel here.
// You can write data using virtualWrite or other Cayenne write functions.
// For example, to send a temperature in Celsius you can use the following:
// Cayenne.virtualWrite(VIRTUAL_PIN, 25.5, TEMPERATURE, CELSIUS);
Cayenne.virtualWrite(VIRTUAL_PIN, bar, 2);
}