Hirdetés
- Apple iPhone 16 Pro - rutinvizsga
- Bemutatkozott a Poco X7 és X7 Pro
- Vége a dalnak: leállt az iPhone Air gyártása
- Fordulat: időben startol S26+, nézd meg, milyen lesz!
- Xiaomi 15T Pro - a téma nincs lezárva
- Google Pixel topik
- Alma inspirálja ezt az olcsó ZTE-t is
- Samsung Galaxy S22 Ultra - na, kinél van toll?
- iPhone topik
- Samsung Galaxy A52s 5G - jó S-tehetség
-
Mobilarena
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
- iPhone 15 Pro MAX 256 GB, fekete, hivatalos garancia, 92% akku, tökéletes állapotban!
- Precision 5560 15.6" FHD+ IPS i7-11850H RTX A2000 32GB 512GB NVMe ujjlolv IR kam gar
- 6-7 gen i5 T procik
- i5 12500/ RTX3060 12GB/ 32GB DDR4 alapú konfig/ garancia/ ingyen foxpost
- -ÚJ,2 ÉV GAR- DDR5 GAMER PC: RYZEN 7 8700F/9700X/9800X3D +RX 6600/6700XT +16-64GB DDR5! SZÁMLA!
- ÁRGARANCIA! Épített KomPhone Ultra 9 285K 32/64GB RAM RTX 5070 12GB GAMER PC termékbeszámítással
- LG 50QNED85T3A / QNED / 50" - 127 cm / 4K UHD / 120Hz / HDR Dolby Vision / FreeSync Premium / VRR
- GYÖNYÖRŰ iPhone 11 Pro Max 256GB Gold -1 ÉV GARANCIA - Kártyafüggetlen, MS3268, 100% Akkumulátor
- Apple iPhone 14 pro 128GB,Újszerű,Dobozával, 12 hónap garanciával
- Telefon felvásárlás!! iPhone 13 Mini/iPhone 13/iPhone 13 Pro/iPhone 13 Pro Max
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: NetGo.hu Kft.
Város: Gödöllő
ekkold

