-
PROHARDVER!
Arduino hardverrel és szoftverrel foglakozó téma. Minden mikrovezérlő ami arduinoval programozható, és minden arduino program, board, és hardverrel kapcsolatos kérdések helye.
Új hozzászólás Aktív témák
-
Tomika86
senior tag
válasz
Tankblock #17103 üzenetére
Nem látok benne én:
#include <movingAvg.h>
// initialize - allocate the interval array
void movingAvg::begin()
{
m_readings = new int[m_interval];
}
// add a new reading and return the new moving average
int movingAvg::reading(int newReading)
{
// add each new data point to the sum until the m_readings array is filled
if (m_nbrReadings < m_interval)
{
++m_nbrReadings;
m_sum = m_sum + newReading;
}
// once the array is filled, subtract the oldest data point and add the new one
else
{
m_sum = m_sum - m_readings[m_next] + newReading;
}
m_readings[m_next] = newReading;
if (++m_next >= m_interval) m_next = 0;
return (m_sum + m_nbrReadings / 2) / m_nbrReadings;
}
// just return the current moving average
int movingAvg::getAvg()
{
return (m_sum + m_nbrReadings / 2) / m_nbrReadings;
}
// start the moving average over again
void movingAvg::reset()
{
m_nbrReadings = 0;
m_sum = 0;
m_next = 0;
}
header:#ifndef MOVINGAVG_H_INCLUDED
#define MOVINGAVG_H_INCLUDED
class movingAvg
{
public:
movingAvg(int interval)
: m_interval(interval), m_nbrReadings(0), m_sum(0), m_next(0) {}
void begin();
int reading(int newReading);
int getAvg();
int getCount() {return m_nbrReadings;}
void reset();
int* getReadings() {return m_readings;}
private:
int m_interval; // number of data points for the moving average
int m_nbrReadings; // number of readings
long m_sum; // sum of the m_readings array
int m_next; // index to the next reading
int *m_readings; // pointer to the dynamically allocated interval array
};
#endif
Új hozzászólás Aktív témák
- Dobozos Új gamer MSI Katana 15 /i7-12650H/16GB/1TB SSD/RTX 4070 8GB GB/144Hz/Gari
- Huawei Watch Fit 4 Pro 3 év garancia, Huawe Freebuds 2
- Xiaomi Redmi 14 PRO 5 G 8/256 DUAL garanciával
- Dell Precision 7670 FHD+ i9-12950HX 16C / 64G D5 / 1T G4 / Quadro RTX A4500 16GB / HU vb Pro tervező
- LG OLED55G42LW LG Gyári garancia 3 év
- Telefon felváráslás!! Samsung Galaxy S22/Samsung Galaxy S22+/Samsung Galaxy S22 Ultra
- Felújított számítógépek/merevlemezek Számlával, garanciával! Ingyen Foxpost!
- Xiaomi Redmi Note 10 Pro 128GB, Kártyafüggetlen, 1 Év Garanciával
- ÁRGARANCIA!Épített KomPhone Ryzen 7 5700X3D 32/64GB RAM RTX 5070 12GB GAMER PC termékbeszámítással
- Bomba ár! HP ProBook 450 G7 - i5-10GEN I 16GB I 256SSD I HDMI I 15,6" FHD I Cam I W11 I Gar
Állásajánlatok
Cég: Promenade Publishing House Kft.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest