// PROJECT :JoyStickPlotter // PURPOSE :Plotter confirmation of ADC readings from a Thumb Joystick // RESULT :Serial Display (Plotter or Monitor) of ADC Readings // AUTHOR :C. D'Arcy // DATE :2022 11 21 // uC :328P // STATUS :Working // REFERENCE:https://learn.sparkfun.com/tutorials/thumb-joystick-hookup-guide/all // :http://darcy.rsgc.on.ca/ACES/TEI3M/images/ThumbJoystickPlotter.png //Thumb Joystick (TJ) Compiler predefines... #define TJGND A0 //Breakout Board's (BoB's) 0V reference #define TJSEL A1 //BoB's Momentary Button. N/A in this application #define TJHORZ A2 //BoB's access to C pin of horizontal pot #define TJVERT A3 //BoB's access to C pin of vertical pot #define TJVCC A4 //BoB's 5V reference #define PACE 100 //adjustaable delay between ADCs //Variables... uint8_t horizontal; //scaled horizontal position (pot) ADC reading uint8_t vertical; //scaled vertical position (pot) ADC reading void setup() { pinMode(TJGND, OUTPUT); //declare IO directions pinMode(TJVCC, OUTPUT); // digitalWrite(TJGND, LOW); //present reference states digitalWrite(TJVCC, HIGH); // Serial.begin(9600); //request acces to serial stream while (!Serial); //wait for acknowledgment Serial.print('H'); //a one-time legend is seldom a bad idea Serial.print(' '); // Serial.print('V'); // Serial.println(); // } void loop() { // Note: [0,1023]>>7 maps to [0,7] //bitshifting is more efficient than division, where possible horizontal = analogRead(TJHORZ) >> 7; //ADC reading and scaling of horizontal pot vertical = analogRead(TJVERT) >> 7; //ADC reading and scaling of vertical pot Serial.print(horizontal); //place the postions on the serial stream Serial.print(' '); // Serial.print(vertical); // Serial.println(); // delay(PACE); //adjustable pacing... }