Hello all,
I'm super new to all this so please bear with me .
I'm working with a potentiometer and a button and would like to export their values to Unreal Engine and possibly drive 2 different interactions in the engine . i.e. Potentiometer value woul move a car right/left and the button would turn headlights on/off (Like a simple game).
This code is giving me results that I could split in Unreal, however I'm experiencing a huge delay in the potentiometer. Is there anything in the code that is causing this and could be improved? Or this is expected for some reason?
Thank you so much in advance.
int sensorPin = A0;
int sensorValue = 0;
int YELLOW_LED = 9;
int RED_LED = 7;
int button = 3;
void setup() {
Serial.begin(9600);
pinMode (YELLOW_LED, OUTPUT);
pinMode (RED_LED, OUTPUT);
pinMode(button, INPUT);
}
void loop() {
int buttonState = digitalRead(button);
//potentiometer
// read the analog in value:
sensorValue = analogRead(sensorPin) / 4;
//delay(100);
Serial.print(sensorValue); //this value will be read by Unreal
analogWrite(YELLOW_LED, sensorValue);
Serial.print(",");
//button
if (buttonState == HIGH) {
digitalWrite(RED_LED, LOW);
Serial.println(1);
}
else {
digitalWrite(RED_LED, HIGH);
Serial.println(2);
}
}