Notifications
Clear all

I want to change this code according to my joystick shield but how ?

7 Posts
2 Users
0 Likes
2,108 Views
Gulshan
(@gulshan)
Member
Joined: 4 years ago
Posts: 127
Topic starter  
This topic was modified 4 years ago 2 times by Gulshan

   
Quote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

Eric


   
ReplyQuote
Gulshan
(@gulshan)
Member
Joined: 4 years ago
Posts: 127
Topic starter  

@zeferby

Thank you I will try this code tomorrow


   
ReplyQuote
Gulshan
(@gulshan)
Member
Joined: 4 years ago
Posts: 127
Topic starter  

   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

@gulshan

yes this code overall structure is nearly the same and you can use the same technique as for the previous one.

Eric


   
ReplyQuote
Gulshan
(@gulshan)
Member
Joined: 4 years ago
Posts: 127
Topic starter  

   
ReplyQuote
(@zeferby)
Member
Joined: 5 years ago
Posts: 355
 

@gulshan

You now have a mess there, because of partial edits, mingling your own values with the original ones ? 

Go back to Bill's original code AND accompanying explanation and try to edit it in 2 stages :

  1. first replace hard-coded values with #define'd ones keeping the original values so you don't get "lost in translation"
  2. only then, introduce your own values, which should actually only be in your #define's at the top

You'll see that the 2 codes from Bill and HowToMechatronics are actually identical, except for two aspects; first they use a different "neutral range", and second :

  • Bill managed the low values of the pots between 0 and POT_NEUTRAL_LOW "by hand", substracting POT_NEUTRAL_LOW and then reversing the negative sign to positive
  • HowToMechatronics used that feature from the map function

Note that the "lower bounds" of either range may be larger or smaller than the "upper bounds" so the map() function may be used to reverse a range of numbers, for example y = map(x, 1, 50, 50, 1);

Otherwise everything is pretty much the same...

 

There remains one hard-coded value in both scripts, that you could (and probably should) replace with a new #define MOTOR_SPEED_MIN , and experiment with for your own motors.  It is  the lowest speed for the motors to avoid buzzing at the end of void loop() : 70 for HowToMechatronics' motors, 8 for Bill's, and probably another value for yours

 

Also beware that we use the same #define'ed values for the two axes of the joystick, so if your joystick has a different behaviour for the X and Y axes (giving readings of 0-661 on one axis and 15-725 on the other for example), then you may want to duplicate/separate all the pots #define's to have for example separate POT_MIN_X and POT_MIN_Y, POT_MAX_X and POT_MAX_Y, etc... available for use in the X axis code and Y axis code respectively.

 

 

Eric


   
ReplyQuote