klew wrote: Wed Nov 18, 2020 10:19 pm
Na podstawie twoich podpowiedzi wydziergałem coś takiego
Code: Select all
class Anemometr : public Supla::Sensor::Wind {
public:
Anemometr(int _WindImpuls, double _One_rpm_speed) { // podaj potrzebne parametry do uruchomienia czujnika wiatru - np. pin do odczytu danych
WindImpuls =_WindImpuls;
One_rpm_speed = _One_rpm_speed;
}
ICACHE_RAM_ATTR void RpmFan() { //
unsigned long static last_event = 0;
if (millis() - last_event < 5) { //debouncing
return;
}
half_revolution_time = (millis() - last_event);
last_event = millis();
}
void onInit() {
// wstaw wszytko co konfiguruje urządzenie (np ustawienie pinMode,
pinMode(WindImpuls, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(WindImpuls), RpmFan, FALLING);
channel.setNewValue(getValue());
}
double getValue() {
double wind;
noInterrupts();
if (half_revolution_time>0) rpm = (30000 / half_revolution_time) ;
interrupts() ;
if (rpm>0) {
wind = One_rpm_speed *(rpm /60);
}
return wind;
}
void iterateAlways() {
if (lastReadTime + 1000 < millis()) {
lastReadTime = millis();
channel.setNewValue(getValue());
}
}
protected:
int WindImpuls; // jakieś zmienne, które są potrzebne - np nr pinu
int half_revolution_time = 0;
double One_rpm_speed;
double rpm = 0;
};
Niestety jest błąd podczas kompilacji
Code: Select all
Arduino:1.8.13 (Windows 7), Płytka:"LOLIN(WEMOS) D1 R2 & mini, 80 MHz, Flash, Legacy (new can return nullptr), Basic SSL ciphers (lower ROM use), 4MB (FS:3MB OTA:~512KB), v2 Lower Memory, Serial, None, All Flash Contents, 115200"
C:\Users\Supla\Documents\Arduino\Wind_new_lib_v1\Wind_new_lib_v1.ino: In member function 'virtual void Anemometr::onInit()':
Wind_new_lib_v1:84:73: error: cannot convert 'Anemometr::RpmFan' from type 'void (Anemometr::)()' to type 'void (*)()'
attachInterrupt(digitalPinToInterrupt(WindImpuls), RpmFan, FALLING);
^
exit status 1
cannot convert 'Anemometr::RpmFan' from type 'void (Anemometr::)()' to type 'void (*)()'
jak temu zaradzić ?
W elektronice jak nie wiadomo o co chodzi to zwykle chodzi o zasilanie
Wezmę udział w Supla Offline Party 2024
