Last active
July 3, 2021 16:58
-
-
Save brocksprogramming/acf9dda4c7d017a7568a089a2ec821a6 to your computer and use it in GitHub Desktop.
Analog read from serial green
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This software was made in hopes of pioneering machine learning gloves. The main application is for typing on any hard surface without a keyboard. | |
// Copyright (C) 2020 Brock Sterling Lynch | |
// This program is free software: you can redistribute it and/or modify | |
// it under the terms of the GNU General Public License as published by | |
// the Free Software Foundation, either version 3 of the License, or | |
// (at your option) any later version. | |
// This program is distributed in the hope that it will be useful, | |
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// GNU General Public License for more details. | |
//You should have received a copy of the GNU General Public License | |
//along with this program. If not, see <https://www.gnu.org/licenses/>. | |
//You may reach the author of this software at brocksprogramming@gmail.com | |
// The device with green colored wires | |
#include <math.h> | |
void setup() { | |
Serial.begin(1200); | |
} | |
// Smooth the input to eliminate random values from machine learning model | |
int AverageFilter(int aNum) | |
{ | |
float AverageAnalogValue = 0; | |
int MeasurementsToAverage = 16; | |
for(int i = 0; i < MeasurementsToAverage; ++i) | |
{ | |
AverageAnalogValue += analogRead(aNum); | |
delay(1); | |
} | |
AverageAnalogValue /= MeasurementsToAverage; | |
return TakeFraction(.10,AverageAnalogValue); | |
} | |
int TakeFraction(float FractionAmount,int AveragedAnalogValue) | |
{ | |
return round(AveragedAnalogValue * FractionAmount); | |
} | |
void loop() { | |
// It won't work with the I2C while loop for some reason. Perhaps it is getting stuck up on it | |
// 16 BYTES all together | |
// Create a block to synchronize the data | |
// Removed DEC from serial.print, because it was sending over as a 2-byte integer | |
// Appar | |
// Probably counts lowByte at 3 character bytes | |
Serial.print("A"); | |
Serial.print("5"); | |
Serial.print(lowByte(AverageFilter(0))); // Read the local analog signal | |
delay(5); | |
Serial.print("A"); | |
Serial.print("6"); | |
Serial.print(lowByte(AverageFilter(1))); // Read the local analog signal | |
delay(5); | |
Serial.print("A"); | |
Serial.print("7"); | |
Serial.print(lowByte(AverageFilter(2))); // Read the local analog signal | |
delay(5); | |
Serial.print("A"); | |
Serial.print("8"); | |
Serial.print(lowByte(AverageFilter(3))); // Read the local analog signal | |
delay(5); | |
Serial.print("A"); | |
Serial.print("9"); | |
Serial.print(lowByte(AverageFilter(4))); | |
Serial.print("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment