Earth station working (With Force Sensor also working)

Connection to ESP32 works and the value from the force sensor can be used for the station.
This commit is contained in:
Nicklas 2024-03-07 16:26:47 +01:00
parent 4d1dcaf1c4
commit 6a8c461f41
4 changed files with 7 additions and 7 deletions
Assets

BIN
Assets/.DS_Store vendored

Binary file not shown.

@ -64,7 +64,7 @@ public class ConnectUnityWithSensors : MonoBehaviour
if (forceDataReceived) if (forceDataReceived)
{ {
if (receivedForceValue > 40) if (receivedForceValue > 900)
{ {
Debug.Log("Force threshold exceeded, action triggered."); Debug.Log("Force threshold exceeded, action triggered.");
isForceDetected = true; isForceDetected = true;

@ -9,13 +9,13 @@ using namespace websockets;
WebsocketsServer server; WebsocketsServer server;
WebsocketsClient client; WebsocketsClient client;
int forceSensorValue = 0; int forceSensorValue = 0;
const int forceSensorPin = 34; // Change to your actual force sensor pin // const int forceSensorPin = 34; // Change to your actual force sensor pin
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
// Initialize force sensor pin as input // Initialize force sensor pin as input
pinMode(forceSensorPin, INPUT); // pinMode(forceSensorPin, INPUT);
// Connect to WiFi // Connect to WiFi
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
@ -62,13 +62,13 @@ if (server.poll()) { //server.poll() checks if any client is waiting to connect
if (msg.data().equalsIgnoreCase("Need Force")) { if (msg.data().equalsIgnoreCase("Need Force")) {
digitalWrite(11, HIGH); //Notify user to use force sensor digitalWrite(11, HIGH); //Notify user to use force sensor
Serial.println("Reading value from Force Sensor..."); Serial.println("Reading value from Force Sensor...");
while (forceSensorValue <= 20) { while (forceSensorValue <= 40) {
analogReadResolution(10); // This statement tells in how many bits the AnalogRead should happen. analogReadResolution(10); // This statement tells in how many bits the AnalogRead should happen.
// analogRead function returns the integer 10 bit integer (0 to 1023) // analogRead function returns the integer 10 bit integer (0 to 1023)
forceSensorValue = analogRead(A0); forceSensorValue = analogRead(A0);
if (forceSensorValue > 20) { if (forceSensorValue > 40) {
digitalWrite(13, HIGH); digitalWrite(13, HIGH);
Serial.print(forceSensorValue, DEC); Serial.print(forceSensorValue, DEC);
Serial.print("\n"); // Sending New Line character is important to read data in unity Serial.print("\n"); // Sending New Line character is important to read data in unity
@ -88,5 +88,4 @@ if (server.poll()) { //server.poll() checks if any client is waiting to connect
// close the connection // close the connection
client.close(); client.close();
} }
} }

@ -19186,6 +19186,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
narrationHasFinished: 0 narrationHasFinished: 0
seedHasAppeared: 0 seedHasAppeared: 0
narrationHasStarted: 0
audioSource: {fileID: 171465764} audioSource: {fileID: 171465764}
narrationClip: {fileID: 8300000, guid: 09a27277c062f490ea6f7f06842f100f, type: 3} narrationClip: {fileID: 8300000, guid: 09a27277c062f490ea6f7f06842f100f, type: 3}
narrationClipTwo: {fileID: 8300000, guid: 33724cce213214c3e8bba7e1c8b7f9de, type: 3} narrationClipTwo: {fileID: 8300000, guid: 33724cce213214c3e8bba7e1c8b7f9de, type: 3}