Advertisement
pleasedontcode

"Arduino Input Control" rev_01

Apr 10th, 2024
93
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: "Arduino Input Control"
  13.     - Source Code compiled for: Arduino Pro Mini 3.3V
  14.     - Source Code created on: 2024-04-10 07:01:15
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* make joystick xy axis controled by 2 potentiometer */
  21.     /* and 3 joy buttons */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF ANALOG INPUT PINS *****/
  32. const uint8_t X_axis_Potentiometer_PIN = A0;
  33. const uint8_t Y_axis_Potentiometer_PIN = A1;
  34. const uint8_t button1_Pin = 2;
  35. const uint8_t button2_Pin = 3;
  36. const uint8_t button3_Pin = 4;
  37.  
  38. void setup(void)
  39. {
  40.     // put your setup code here, to run once:
  41.     pinMode(X_axis_Potentiometer_PIN, INPUT);
  42.     pinMode(Y_axis_Potentiometer_PIN, INPUT);
  43.     pinMode(button1_Pin, INPUT_PULLUP);
  44.     pinMode(button2_Pin, INPUT_PULLUP);
  45.     pinMode(button3_Pin, INPUT_PULLUP);
  46. }
  47.  
  48. void loop(void)
  49. {
  50.     // put your main code here, to run repeatedly:
  51.     int x_axis_value = analogRead(X_axis_Potentiometer_PIN);
  52.     int y_axis_value = analogRead(Y_axis_Potentiometer_PIN);
  53.    
  54.     // Use the analog input values to control the joystick
  55.     // Your code to control the joystick goes here
  56.  
  57.     // Read the button states
  58.     bool button1_state = digitalRead(button1_Pin);
  59.     bool button2_state = digitalRead(button2_Pin);
  60.     bool button3_state = digitalRead(button3_Pin);
  61.  
  62.     // Use the button states to control the buttons
  63.     // Your code to control the buttons goes here
  64.  
  65.     delay(100); // Add a small delay to avoid reading the analog inputs too quickly
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement