//instantiates pins & speed(s) const int yright = 16; const int yleft = 17; const int button = 18; int message; int stop = 75; int speedRight = stop; int speedLeft = stop; //Setting up pins to be output & setting analog joystick value to neutral //Starting serial for script communication void setup() { Serial.begin(115200); Serial.setTimeout(1); pinMode(yright, OUTPUT); pinMode(yleft, OUTPUT); pinMode(button, OUTPUT); analogWrite(yright, 90); analogWrite(yleft, 90); digitalWrite(button, LOW); } void loop() { //when communication is not actively occurring, use last defined speed value while(!Serial.available()){ analogWrite(yright, speedRight); analogWrite(yleft, speedLeft); } message = Serial.readString().toInt(); //case statements with edge cases //if the "message" value is within the defined voltage range, it will be mapped accordingly //if the "message" value outputs 300, stops robot and performs action if(message != 0){ if(message > 0 && message < 200){ speedRight = stop + message; speedLeft = stop - message; }else if(message < 0){ speedRight = stop + message; speedLeft = stop - message; }else if (message = 200){ speedRight = 125; speedLeft = speedRight; }else if (message = 300){ speedRight = stop; speedLeft = stop; digitalWrite(button, HIGH); delay(250); digitalWrite(button, LOW); delay(250); digitalWrite(button, HIGH); delay(250); digitalWrite(button, LOW); } //message will print to terminal of external ide Serial.println(message); Serial.println(speedRight); Serial.println(speedLeft); } }