Browse Source

Основной код переписан под Sensor.h

master
Defend 7 years ago
parent
commit
a757da736e
  1. 12
      src/main.cpp

12
src/main.cpp

@ -13,8 +13,6 @@ ESP8266WebServer server(80);
Sensor accelerometer = Sensor(); Sensor accelerometer = Sensor();
long int lastUpdate = 0;
int acc = 0;
Graph graphAcc = Graph(200, 50); Graph graphAcc = Graph(200, 50);
@ -42,19 +40,19 @@ void handleAccelerometer()
void updateAccelerometer() void updateAccelerometer()
{ {
if ((millis() - lastUpdate) > (1000 / graphAcc.graphUpdateRate)) if ((millis() - accelerometer.lastUpdate) > (1000 / graphAcc.graphUpdateRate))
{ {
acc = map(analogRead(A0), 512, 768, 200, 0); accelerometer.lastValue = map(analogRead(A0), 512, 768, 200, 0);
if (graphAcc.graphCounter < graphAcc.graphSize - 1) { if (graphAcc.graphCounter < graphAcc.graphSize - 1) {
graphAcc.graphArray[graphAcc.graphCounter] = acc; graphAcc.graphArray[graphAcc.graphCounter] = accelerometer.lastValue;
graphAcc.graphCounter++; graphAcc.graphCounter++;
} else { } else {
for(int i = 0; i != graphAcc.graphCounter; i++) { for(int i = 0; i != graphAcc.graphCounter; i++) {
graphAcc.graphArray[i] = graphAcc.graphArray[i + 1]; graphAcc.graphArray[i] = graphAcc.graphArray[i + 1];
} }
graphAcc.graphArray[graphAcc.graphCounter] = acc; graphAcc.graphArray[graphAcc.graphCounter] = accelerometer.lastValue;
} }
lastUpdate = millis(); accelerometer.lastUpdate = millis();
} }
} }

Loading…
Cancel
Save