Find logic errors: #include #include #define NEOS 8 #define NPX 10 #define AVGS 100 int runsamps[AVGS]; double curavg; int count; Adafruit_NeoPixel pixels(NPX, NEOS, NEO_GRB+NEO_KHZ800); void setup() { // put your setup code here, to run once: pixels.begin(); memset(runsamps, 0, AVGS*sizeof(int)); count = 0; curavg = 50; } void loop() { // put your main code here, to run repeatedly: int newdata; int scaleavg; pixels.clear(); newdata = analogRead(8); curavg += (double)runsamps[count]/AVGS; runsamps[count] = newdata; curavg -= (double)newdata/AVGS; scaleavg = round(map(curavg, 0, 1023, 0, 10)); for (int n = 0; n < scaleavg; n++) { pixels.setPixelColor(n, pixels.Color(82, 35, 152)); pixels.show(); } delay(10); count++; }
Find logic errors:
#include <Adafruit_NeoPixel.h>
#include <string.h>
#define NEOS 8
#define NPX 10
#define AVGS 100
int runsamps[AVGS];
double curavg;
int count;
Adafruit_NeoPixel pixels(NPX, NEOS, NEO_GRB+NEO_KHZ800);
void setup() {
// put your setup code here, to run once:
pixels.begin();
memset(runsamps, 0, AVGS*sizeof(int));
count = 0;
curavg = 50;
}
void loop() {
// put your main code here, to run repeatedly:
int newdata;
int scaleavg;
pixels.clear();
newdata = analogRead(8);
curavg += (double)runsamps[count]/AVGS;
runsamps[count] = newdata;
curavg -= (double)newdata/AVGS;
scaleavg = round(map(curavg, 0, 1023, 0, 10));
for (int n = 0; n < scaleavg; n++)
{
pixels.setPixelColor(n, pixels.Color(82, 35, 152));
pixels.show();
}
delay(10);
count++;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps