Dateien hochladen nach „transform_modules/future_relics“
parent
42c1b60734
commit
fc66d52c6e
@ -0,0 +1,126 @@
|
||||
/*
|
||||
future_relics
|
||||
// board info: LilyGO TTGO T8 ESP32-S2 - with SD Card Slot
|
||||
// board select: ESP32S2 DEV Module
|
||||
|
||||
current USB port: 142200
|
||||
*/
|
||||
|
||||
|
||||
#define sensor1 1 // PCB: 35 // potentiometer: shape RV1
|
||||
#define sensor2 2 // PCB: 36 // potentiometer: rotation RV2
|
||||
#define sensor3 3 // PCB: 46 // slide potentiometer: x position RV3
|
||||
#define sensor4 4 // PCB: 45 // slide potentiometer: y position RV4
|
||||
#define sensor5 5 // PCB: 42 // slide potentiometer: graytone RV5
|
||||
#define sensorLED 0 // LED
|
||||
|
||||
String input;
|
||||
String newData;
|
||||
String output;
|
||||
String moduleID = "#FR";
|
||||
|
||||
|
||||
// the setup routine runs once when you press reset:
|
||||
void setup() {
|
||||
// initialize serial communication at 115200 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: shape
|
||||
// read analog input
|
||||
int sensorValue1 = analogRead(sensor1);
|
||||
// redefine range for font:
|
||||
int value1 = map(sensorValue1, 0, 8191, 40, 1);
|
||||
// use value1 to define shape:
|
||||
String shape = "";
|
||||
if(value1 >= 0 && value1 <= 1) {shape = "bubble";} // if value1 is bigger than or equal to 1 and value1 is smaller than or equal to 10: spike
|
||||
else if(value1 >= 2 && value1 <= 23) {shape = "spike";} // else if value1 is bigger than or equal to 11 and value1 is smaller than or equal to 20: bubble
|
||||
else if(value1 >= 24 && value1 <= 37) {shape = "fraction";}
|
||||
else if(value1 >= 38 && value1 <= 40) {shape = "square";}
|
||||
|
||||
|
||||
// sensor 2: rotation
|
||||
// read analog input
|
||||
int sensorValue2 = analogRead(sensor2);
|
||||
// redefine range for rotation:
|
||||
int rotation = map(sensorValue2, 0, 8191, 20, 0);
|
||||
|
||||
|
||||
// sensor3: x position
|
||||
// read analog input
|
||||
int sensorValue3 = analogRead(sensor3);
|
||||
// redefine range for x-position:
|
||||
int xPosition = map(sensorValue3, 0, 8191, 0, 450);
|
||||
|
||||
|
||||
// sensor4: y position
|
||||
// read analog input
|
||||
int sensorValue4 = analogRead(sensor4);
|
||||
// redefine range for y-position:
|
||||
int yPosition = map(sensorValue4, 0, 8191, 0, 700);
|
||||
|
||||
|
||||
// sensor5: graytone
|
||||
// read analog input
|
||||
int sensorValue5 = analogRead(sensor5);
|
||||
// redefine range for graytone:
|
||||
int value5 = map(sensorValue5, 0, 8191, 0, 100);
|
||||
// graytone:
|
||||
String graytone = "";
|
||||
if(value5 >= 0 && value5 <= 10) {graytone = "0.0";}
|
||||
else if(value5 >= 11 && value5 <= 20) {graytone = "0.1";}
|
||||
else if(value5 >= 21 && value5 <= 30) {graytone = "0.2";}
|
||||
else if(value5 >= 31 && value5 <= 40) {graytone = "0.3";}
|
||||
else if(value5 >= 41 && value5 <= 50) {graytone = "0.4";}
|
||||
else if(value5 >= 51 && value5 <= 60) {graytone = "0.5";}
|
||||
else if(value5 >= 61 && value5 <= 70) {graytone = "0.6";}
|
||||
else if(value5 >= 71 && value5 <= 80) {graytone = "0.7";}
|
||||
else if(value5 >= 81 && value5 <= 90) {graytone = "0.8";}
|
||||
else if(value5 >= 91 && value5 <= 100) {graytone = "0.9";}
|
||||
|
||||
|
||||
|
||||
//put all the above values in a string to define the new data from this module:
|
||||
newData = "&&&" + String(moduleID) + "," + String(shape) + "," + String(rotation) + "," + String(xPosition) + "," + String(yPosition) + "," + String(graytone) + "&&&";
|
||||
|
||||
|
||||
|
||||
//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("Future Relics, new data: " + newData);
|
||||
Serial.println("This is the output I send: " + output);
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue