Нужна помощь с вызовом значения float
- Войдите на сайт для отправки комментариев
Вс, 13/08/2017 - 14:21
В последней строчке не могу вызвать "bar". 'bar' was not declared in this scope.
Пробовал переносить, не выходит...
Пожалуйста, помогите!
#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); }
В последней строчке не могу вызвать "bar". 'bar' was not declared in this scope.
Пробовал переносить, не выходит...
Пожалуйста, помогите!
Ни вопрос ни разу! Всегда рад помочь :) Читайте на здорове! http://cpp.com.ru/kr_cbook/index.html
Битая ссылка
Открыл, ща почитаю. Подскажите, в каком разделе искать?
Ну вот все равно не понимаю как вернуть значение этой функции в область доступную для
CAYENNE_OUT(VIRTUAL_PIN)
{
...
}
Открыл, ща почитаю. Подскажите, в каком разделе искать?
1.10 Внешние переменные и область видимости
Получилось! Создал в начале программы float с новым именем pressureresult а потом после "float bar" передал pressureresult = bar;
ну и в CAYENNE_OUT вызывал уже pressureresult
Открыл, ща почитаю. Подскажите, в каком разделе искать?
Читать всё подряд. Иначе не поможет.
Да это понятно... но иногда ты вроде это уже читал, но как применить не помнишь, я ж не практикую ежедневное программирование ардуинки)))
И действительно... ещё несколько раз прочитал и вроде сообразил...
вуд