Browse Source

В догонку к предыдущему -_-

master
Defend 7 years ago
parent
commit
952b61e90a
  1. 32
      src/main.cpp

32
src/main.cpp

@ -18,11 +18,6 @@ class Graph {
int graphUpdateRate;
int * graphArray;
int graphCounter;
// int graph_size = 200;
// int graph1[graph_size] = { 200 };
// int graph1counter = 0;
// int graphUpdate = 50;
Graph (int graphSize, int graphUpdateRate) {
this->graphSize = graphSize;
@ -30,14 +25,9 @@ class Graph {
graphArray = new int[graphSize];
graphCounter = 0;
}
Graph () {
Graph(200, 50);
}
}; // Раз в секунду
Graph graphAccelerometer;
Graph graphAcc;
void handleAccelerometer()
{
@ -49,8 +39,8 @@ void handleAccelerometer()
bias += getHtml(HTML_BEGIN, *html_code, arr_size, 0);
bias += getHtml(STYLE, *html_code, arr_size, bias);
bias += getHtml(SCRIPT_BEGIN, *html_code, arr_size, bias);
for (int i = 0; i != graphAccelerometer.graphSize - 1; i++) {
bias += snprintf((html_code+bias), arr_size - bias, "context.lineTo(%i*2, %i);", i, graphAccelerometer.graphArray[i]);
for (int i = 0; i != graphAcc.graphSize - 1; i++) {
bias += snprintf((html_code+bias), arr_size - bias, "context.lineTo(%i*2, %i);", i, graphAcc.graphArray[i]);
}
bias += getHtml(SCRIPT_END, *html_code, arr_size, bias);
//bias += snprintf((html_code+bias), arr_size - bias, "<br />Current accelerometer: %i", acc);
@ -63,17 +53,17 @@ void handleAccelerometer()
void updateAccelerometer()
{
if ((millis() - lastUpdate) > (1000 / graphAccelerometer.graphUpdateRate))
if ((millis() - lastUpdate) > (1000 / graphAcc.graphUpdateRate))
{
acc = map(analogRead(A0), 512, 768, 200, 0);
if (graphAccelerometer.graphCounter < graphAccelerometer.graphSize - 1) {
graphAccelerometer.graphArray[graphAccelerometer.graphCounter] = acc;
graphAccelerometer.graphCounter++;
if (graphAcc.graphCounter < graphAcc.graphSize - 1) {
graphAcc.graphArray[graphAcc.graphCounter] = acc;
graphAcc.graphCounter++;
} else {
for(int i = 0; i != graphAccelerometer.graphCounter; i++) {
graphAccelerometer.graphArray[i] = graphAccelerometer.graphArray[i + 1];
for(int i = 0; i != graphAcc.graphCounter; i++) {
graphAcc.graphArray[i] = graphAcc.graphArray[i + 1];
}
graphAccelerometer.graphArray[graphAccelerometer.graphCounter] = acc;
graphAcc.graphArray[graphAcc.graphCounter] = acc;
}
lastUpdate = millis();
}
@ -98,7 +88,7 @@ void handleNotFound()
void setup(void)
{
graphAccelerometer = Graph(200, 50);
graphAcc = Graph(200, 50); // Класс графики для акселерометра
pinMode(A0, INPUT);
Serial.begin(115200);
WiFi.softAP(ssid);

Loading…
Cancel
Save