archive/Arduino/CompressionTest2/CompressionTest2.ino

89 lines
2.1 KiB
C++

#include <bcconfig.h>
#include <BigNumber.h>
#include <number.h>
#define numberOfSensors 50
int flexSensorPins[] = {A0, A1, A2, A3};
int mapValue;
String reference[] = {"L","H"};
String finalReadable;
String final;
int i = 0;
void setup() {
Serial.begin(9600);
BigNumber::begin();
}
String toBinary(String intString, int len) {
String binary = "";
char s[len];
intString.toCharArray(s, len);
BigNumber lrgInt(s);
BigNumber two = 2;
BigNumber zero = 0;
int remainder;
while (lrgInt > zero) {
remainder = lrgInt % two;
lrgInt = lrgInt / two;
lrgInt = lrgInt - lrgInt % lrgInt
lrgInt
binary = String(remainder) + binary;
Serial.println(binary);
}
return binary;
}
String compression(int values[]) {
String finalCompress = "";
String combinedInt = "";
String binString = "";
char* s;
int counter = 0;
int change = 0;
for (i = 0; i < numberOfSensors; i++) {
if(String(values[i]).length() < 2) {
combinedInt += "0" + String(values[i]);
} else {
combinedInt += String(values[i]);
}
}
binString = toBinary(combinedInt, combinedInt.length());
for (i = 0; i <= binString.length(); i++) {
if (binString.charAt(i) == binString.charAt(change)) {
counter += 1;
} else {
if(counter == 1) {
finalCompress = finalCompress + reference[String(binString.charAt(0)).toInt()];
} else {
finalCompress = finalCompress + String(counter) + reference[String(binString.charAt(0)).toInt()];
}
change = i;
counter = 1;
}
}
return finalCompress;
}
void loop() {
finalReadable = "";
final = "";
int dataValues[] = {32, 62, 10, 7, 45, 91, 95, 27, 54, 50, 67, 84, 92, 68, 10,
53, 79, 65, 6, 62, 60, 15, 52, 63, 71, 9, 52, 86,
68, 52, 96, 30, 31, 50, 24, 56, 61, 54, 40, 26,
33, 34, 32, 28, 2, 96, 3, 77, 66, 97};
//for(int i = 0; i < numberOfSensors; i++) {
//mapValue = map(analogRead(flexSensorPins[i]), 512, 853, 0, 180) - 25;
//finalReadable = finalReadable + String(mapValue) + ",";
//dataValues[i] = mapValue;
String hello = compression(dataValues);
//Serial.println(hello);
delay(250);
}