Dateien hochladen nach „transform_modules/whoosh“

main
ohjian 1 year ago
parent 9eee6c8850
commit e7edd3df05

@ -0,0 +1,167 @@
/*
WHOOSH
// board info: LilyGO TTGO T8 ESP32-S2 - with SD Card Slot
// board select: ESP32S2 DEV Module
current USB port: 142300
To DO:
define pins for all the inputs!
redefine range for parameters?
*/
#define sensor1 1 // PCB: 41 // potentiometer: font RV1
#define sensor2 2 // PCB: 46 // potentiometer: paraA RV2
#define sensor3 3 // PCB: 45 // potentiometer: paraB RV3
#define sensor4 4 // PCB: 42 // potentiometer: paraC RV4
#define sensor5 5 // PCB: 36 // potentiometer: paraD RV5
#define sensor6 6 // PCB: 37 // potentiometer: paraE RV6
#define sensor7 7 // PCB: 38 // potentiometer: paraF RV7
#define sensor8 8 // PCB: 40 // potentiometer: paraG RV8
#define sensor9 16 // PCB: 39 // slide potentiometer: paraLine RV9
#define sensorLED 0 // LED
String input;
String newData;
String output;
String moduleID = "#WH";
// the setup routine runs once when you press reset:
void setup() {
// initialize serial and serial1 communication at 115200 and 9600 bits per second:
Serial.begin(115200); //goes to serial monitor, just for debugging purposes
Serial1.begin(9600); // goes to the next module via patch cable (use transmit pin TX on IO17 and also connect to GND)
Serial1.setTimeout(100); // there is a small bug, so there needs to be a checksum?
// set mode for digital input to not give floating values, but either 0 or 1:
pinMode(sensorLED, OUTPUT); // set LED pin to output
//LED initial state
digitalWrite(sensorLED, LOW);
}
// the loop routine runs over and over again forever:
void loop() {
// sensor 1: font
// read analog input
int sensorValue1 = analogRead(sensor1);
// redefine range for font:
int value1 = map(sensorValue1, 0, 8191, 8191, 0);
// use value1 to define font: not get int but string with fontname:
String font = "";
if(value1 >= 0 && value1 < 1) {font = "T-1";} // if value1 is bigger than or equal to 1 and value1 is smaller than or equal to 10: Times-Roman
else if(value1 >= 1 && value1 <= 2) {font = "T-2";} // else if value1 is bigger than or equal to 11 and value1 is smaller than or equal to 20: Times-Bold
else if(value1 >= 50 && value1 <= 920) {font = "T-3";}
else if(value1 >= 921 && value1 <= 1830) {font = "T-4";}
else if(value1 >= 1831 && value1 <= 3199) {font = "H-1";}
else if(value1 >= 3200 && value1 <= 4399) {font = "H-2";}
else if(value1 >= 4400 && value1 <= 5600) {font = "H-3";}
else if(value1 >= 5601 && value1 <= 6350) {font = "H-4";}
else if(value1 >= 6351 && value1 <= 7250) {font = "C-1";}
else if(value1 >= 7251 && value1 <= 7870) {font = "C-2";}
else if(value1 >= 7871 && value1 <= 8189) {font = "C-3";}
else if(value1 >= 8190 && value1 <= 8191) {font = "C-4";}
// sensor 2: paraA
// read analog input
int sensorValue2 = analogRead(sensor2);
// redefine range:
int paraA = map(sensorValue2, 0, 8191, 5, 2);
// sensor 3: paraB
// read analog input
int sensorValue3 = analogRead(sensor3);
// redefine range:
int paraB = map(sensorValue3, 0, 8191, 5, 2);
// sensor 4: paraC
// read analog input
int sensorValue4 = analogRead(sensor4);
// redefine range:
int paraC = map(sensorValue4, 0, 8191, 10, 1);
// sensor5: paraD
// read analog input
int sensorValue5 = analogRead(sensor5);
// redefine range:
int paraD = map(sensorValue5, 0, 8191, 50, 5);
// sensor6: paraE
// read analog input
int sensorValue6 = analogRead(sensor6);
// redefine range:
int paraE = map(sensorValue6, 0, 8191, 100, 10);
// sensor7: paraF
// read analog input
int sensorValue7 = analogRead(sensor7);
// redefine range:
int paraF = map(sensorValue7, 0, 8191, 10, 2);
// sensor8: paraG
// read analog input
int sensorValue8 = analogRead(sensor8);
// redefine range:
int paraG = map(sensorValue8, 0, 8191, 8, 2);
// sensor9: paraLine
// read analog input
int sensorValue9 = analogRead(sensor9);
// redefine range:
int paraLine = map(sensorValue9, 0, 8191, 10, 99);
//put all the above values in a string to define the new data from this module:
newData = "&&&" + String(moduleID) + "," + String(font) + "," + String(paraA) + "," + String(paraB) + "," + String(paraC) + "," + String(paraD) + "," + String(paraE) + "," + String(paraF) + "," + String(paraG) + "," + String(paraLine) + "&&&";
//Receive data from previous module (RX):
input = Serial1.readStringUntil('\n'); // read received data until line break and store in input variable
//LED
if (input != "") {
digitalWrite(sensorLED, HIGH); //turn LED on
}
else {
digitalWrite(sensorLED, LOW); //turn LED off
}
output = input + newData;
//Send data to next module (TX):
Serial1.println(output); //the data received + new data
//Print data on Serial Monitor:
Serial.println("This is the input I received: " + input);
Serial.println("Whoosh, new data: " + newData);
Serial.println("This is the output I send: " + output);
}
Loading…
Cancel
Save