Advertisement
pleasedontcode

**Joystick Display** rev_01

May 8th, 2025
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **Joystick Display**
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-05-08 10:51:20
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop code for ESP32 Dev module to facilitate */
  21.     /* wireless communication with a microcontroller. */
  22.     /* Utilize two common anode 7-segment displays to */
  23.     /* reflect joystick movements. Rightward joystick */
  24.     /* turn updates displays in real-time. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <Wire.h>
  31. #include <Adafruit_GFX.h>
  32. #include <Adafruit_LEDBackpack.h>
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. // Instantiate the display objects for two 7-segment displays
  39. Adafruit_7segment display1 = Adafruit_7segment();
  40. Adafruit_7segment display2 = Adafruit_7segment();
  41.  
  42. // Variables to hold joystick values
  43. int joystickX = 0;
  44. int joystickY = 0;
  45.  
  46. void setup(void)
  47. {
  48.     // Initialize the I2C communication
  49.     Wire.begin();
  50.    
  51.     // Initialize the displays
  52.     display1.begin(0x70); // Address for the first display
  53.     display2.begin(0x71); // Address for the second display
  54.  
  55.     // Set brightness for the displays
  56.     display1.setBrightness(15); // Max brightness
  57.     display2.setBrightness(15); // Max brightness
  58.  
  59.     // Initialize Serial for debugging
  60.     Serial.begin(115200);
  61. }
  62.  
  63. void loop(void)
  64. {
  65.     // Simulate reading joystick values (replace with actual joystick reading code)
  66.     joystickX = analogRead(34); // Assuming joystick X-axis is connected to GPIO 34
  67.     joystickY = analogRead(35); // Assuming joystick Y-axis is connected to GPIO 35
  68.  
  69.     // Map joystick values to display digits (0-9)
  70.     int displayValue1 = map(joystickX, 0, 4095, 0, 9);
  71.     int displayValue2 = map(joystickY, 0, 4095, 0, 9);
  72.  
  73.     // Update the displays with the joystick values
  74.     display1.print(displayValue1);
  75.     display1.writeDisplay();
  76.    
  77.     display2.print(displayValue2);
  78.     display2.writeDisplay();
  79.  
  80.     // Add a small delay to avoid flickering
  81.     delay(100);
  82. }
  83.  
  84. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement