You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
6.1 KiB
Arduino
174 lines
6.1 KiB
Arduino
2 years ago
|
/*
|
||
|
friction label
|
||
|
// board info: LilyGO TTGO T8 ESP32-S2 - with SD Card Slot
|
||
|
// board select: ESP32S2 DEV Module
|
||
|
|
||
|
current USB port: 142300
|
||
|
*/
|
||
|
|
||
|
#define sensor1 1 // PCB: 42 // potentiometer: fontsize RV1
|
||
|
#define sensor2 2 // PCB: 37 // potentiometer: font RV2
|
||
|
#define sensor3 3 // PCB: 35 // potentiometer: outline RV3
|
||
|
#define sensor4 4 // PCB: 36 // potentiometer: rotation RV4
|
||
|
#define sensor5 5 // PCB: 46 // slide potentiometer: x position RV5
|
||
|
#define sensor6 6 // PCB: 45 // slide potentiometer: y position RV6
|
||
|
#define sensor7 7 // PCB: 39 // slide potentiometer: graytone 1 RV7
|
||
|
#define sensor8 8 // PCB: 38 // slide potentiometer: graytone 2RV8
|
||
|
#define sensorLED 0 // LED
|
||
|
|
||
|
String input;
|
||
|
String newData;
|
||
|
String output;
|
||
|
String moduleID = "#FL";
|
||
|
|
||
|
|
||
|
// 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: fontsize
|
||
|
// read analog input
|
||
|
int sensorValue1 = analogRead(sensor1);
|
||
|
// redefine range for fontsize:
|
||
|
int fontsize = map(sensorValue1, 0, 8191, 100, 1);
|
||
|
|
||
|
|
||
|
// sensor 2: font
|
||
|
// read analog input
|
||
|
int sensorValue2 = analogRead(sensor2);
|
||
|
// redefine range for font:
|
||
|
int value2 = map(sensorValue2, 0, 8191, 8191, 0);
|
||
|
// use value2 to define font: not get int but string with fontname:
|
||
|
String font = "";
|
||
|
if(value2 >= 0 && value2 < 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(value2 >= 1 && value2 <= 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(value2 >= 50 && value2 <= 920) {font = "T-3";}
|
||
|
else if(value2 >= 921 && value2 <= 1830) {font = "T-4";}
|
||
|
else if(value2 >= 1831 && value2 <= 3199) {font = "H-1";}
|
||
|
else if(value2 >= 3200 && value2 <= 4399) {font = "H-2";}
|
||
|
else if(value2 >= 4400 && value2 <= 5600) {font = "H-3";}
|
||
|
else if(value2 >= 5601 && value2 <= 6350) {font = "H-4";}
|
||
|
else if(value2 >= 6351 && value2 <= 7250) {font = "C-1";}
|
||
|
else if(value2 >= 7251 && value2 <= 7870) {font = "C-2";}
|
||
|
else if(value2 >= 7871 && value2 <= 8189) {font = "C-3";}
|
||
|
else if(value2 >= 8190 && value2 <= 8191) {font = "C-4";}
|
||
|
|
||
|
|
||
|
|
||
|
// sensor 3: outline
|
||
|
// read analog input
|
||
|
int sensorValue3 = analogRead(sensor3);
|
||
|
// redefine range for outline:
|
||
|
int outline = map(sensorValue3, 0, 8191, 120, 20);
|
||
|
|
||
|
|
||
|
// sensor 4: rotation
|
||
|
// read analog input
|
||
|
int sensorValue4 = analogRead(sensor4);
|
||
|
// redefine range for rotation:
|
||
|
int rotation = map(sensorValue4, 0, 8191, 20, 0);
|
||
|
|
||
|
|
||
|
|
||
|
// sensor5: x position
|
||
|
// read analog input
|
||
|
int sensorValue5 = analogRead(sensor5);
|
||
|
// redefine range for x-position:
|
||
|
int xPosition = map(sensorValue5, 0, 8191, 0, 450);
|
||
|
|
||
|
|
||
|
// sensor6: y position
|
||
|
// read analog input
|
||
|
int sensorValue6 = analogRead(sensor6);
|
||
|
// redefine range for y-position:
|
||
|
int yPosition = map(sensorValue6, 0, 8191, 0, 700);
|
||
|
|
||
|
|
||
|
// sensor7: graytone 1
|
||
|
// graytone1 = text
|
||
|
// read analog input
|
||
|
int sensorValue7 = analogRead(sensor7);
|
||
|
// redefine range for graytones:
|
||
|
int value7 = map(sensorValue7, 0, 8191, 0, 110);
|
||
|
// graytone1:
|
||
|
String graytone1 = "";
|
||
|
if(value7 >= 0 && value7 <= 10) {graytone1 = "0.0";} //black
|
||
|
else if(value7 >= 11 && value7 <= 20) {graytone1 = "0.1";}
|
||
|
else if(value7 >= 21 && value7 <= 30) {graytone1 = "0.2";}
|
||
|
else if(value7 >= 31 && value7 <= 40) {graytone1 = "0.3";}
|
||
|
else if(value7 >= 41 && value7 <= 50) {graytone1 = "0.4";}
|
||
|
else if(value7 >= 51 && value7 <= 60) {graytone1 = "0.5";}
|
||
|
else if(value7 >= 61 && value7 <= 70) {graytone1 = "0.6";}
|
||
|
else if(value7 >= 71 && value7 <= 80) {graytone1 = "0.7";}
|
||
|
else if(value7 >= 81 && value7 <= 90) {graytone1 = "0.8";}
|
||
|
else if(value7 >= 91 && value7 <= 100) {graytone1 = "0.9";}
|
||
|
else if(value7 >= 101 && value7 <= 110) {graytone1 = "1.0";} //white
|
||
|
|
||
|
|
||
|
// sensor8: graytone 2
|
||
|
// graytone2 = outline
|
||
|
// read analog input
|
||
|
int sensorValue8 = analogRead(sensor8);
|
||
|
// redefine range for graytones:
|
||
|
int value8 = map(sensorValue8, 0, 8191, 0, 100);
|
||
|
// graytone2:
|
||
|
String graytone2 = "";
|
||
|
if(value8 >= 0 && value8 <= 10) {graytone2 = "0.0";} //black
|
||
|
else if(value8 >= 11 && value8 <= 20) {graytone2 = "0.1";}
|
||
|
else if(value8 >= 21 && value8 <= 30) {graytone2 = "0.2";}
|
||
|
else if(value8 >= 31 && value8 <= 40) {graytone2 = "0.3";}
|
||
|
else if(value8 >= 41 && value8 <= 50) {graytone2 = "0.4";}
|
||
|
else if(value8 >= 51 && value8 <= 60) {graytone2 = "0.5";}
|
||
|
else if(value8 >= 61 && value8 <= 70) {graytone2 = "0.6";}
|
||
|
else if(value8 >= 71 && value8 <= 80) {graytone2 = "0.7";}
|
||
|
else if(value8 >= 81 && value8 <= 90) {graytone2 = "0.8";}
|
||
|
else if(value8 >= 91 && value8 <= 100) {graytone2 = "0.9";} //almost white
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//put all the above values in a string to define the new data from this module:
|
||
|
newData = "&&&" + String(moduleID) + "," + String(font) + "," + String(fontsize) + "," + String(rotation) + "," + String(outline) + "," + String(xPosition) + "," + String(yPosition) + "," + String(graytone1) + "," + String(graytone2) + "&&&";
|
||
|
|
||
|
//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("Friction Label, new data: " + newData);
|
||
|
Serial.println("This is the output I send: " + output);
|
||
|
|
||
|
}
|