/* Analog input, serial output Reads an analog input pin, maps the result to a range from 0 to 100, and prints the results to the Serial Monitor. created 29 Dec. 2008 modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInOutSerial Modified by Leen Nijim */ #include SoftwareSerial mySerial(PA2, PA3); // RX, TX // These constants won't change. They're used to give names to the pins used: const int vRx = PA0; // Analog input pin that the potentiometer is attached to const int vRy = PA1; // Analog output pin that the LED is attached to //const int button = 3; int sensorValX = 0; // value read from the potserianl monitor int sensorValY = 0; //int buttonVal = 0; int outputValX = 0; int outputValY = 0; //char outputBut; void setup() { // initialize serial communications at 9600 bps: mySerial.begin(4800); pinMode(vRx, INPUT); pinMode(vRy, INPUT); // pinMode(button, INPUT); } void loop() { // read the analog in value: sensorValX = analogRead(vRx); sensorValY = analogRead(vRy); // buttonVal = digitalRead(button); // map it to the range of the analog out: outputValX = map(sensorValX, 0, 1023, 5, 795); outputValY = map(sensorValY, 0, 1023, 5, 795); // if(buttonVal){ // outputBut = 'y'; // } // else {outputBut = 'n';} // change the analog out value: if(outputValX<100){ if(outputValX<10){ mySerial.print("00"); } else{ mySerial.print('0'); } } mySerial.print(outputValX); if(outputValY<100){ if(outputValY<10){ mySerial.print("00"); } else{ mySerial.print('0'); } } mySerial.print(outputValY); mySerial.println(); // Serial.print(outputBut); // wait 2 milliseconds before the next loop for the analog-to-digital // converter to settle after the last reading: delay(100); }