/* Made by Jefferson Sandoval during the Embedded programming for the FabAcademy2021 * * This is just a simple code in Arduino for testing a Grove - Thumb Joystick v1.1 connected * to my own board, MyMiniBoard_X14, based on the ATtiny1614. * The code reads the value from the sensor and print it on the Serial monitor. * * Documentation: http://fabacademy.org/2021/labs/kamplintfort/students/jefferson-sandoval/assignments/week11/ */ //Declare variables linked to the pins where the joystick is connected. const int X = 0; const int Y = 1; void setup() { Serial.begin(9600); //initialize serial communication } void loop() { int ValueX, ValueY; // //Read values from Joysticks and convert them to percentages, //I used 200 cause the joystick can rotate only 50% on any direction. ValueX = map(analogRead(X),0,1023,200,-200); //X axis values ValueY = map(analogRead(Y),0,1023,-200,200); //Y axis values //Print values on Serial monitor Serial.print("X: "); Serial.print(ValueX); Serial.println("%"); Serial.print("Y: "); Serial.print(ValueY); Serial.println("%"); Serial.println(" "); delay(100); //Wait 0.1 seconds }