<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[RemoteXY community — I need help with joystick and l298n]]></title>
		<link>https://forum.remotexy.com/viewtopic.php?id=1126</link>
		<atom:link href="https://forum.remotexy.com/extern.php?action=feed&amp;tid=1126&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in I need help with joystick and l298n.]]></description>
		<lastBuildDate>Tue, 11 Aug 2020 14:10:51 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: I need help with joystick and l298n]]></title>
			<link>https://forum.remotexy.com/viewtopic.php?pid=3290#p3290</link>
			<description><![CDATA[<div class="quotebox"><cite>marc6194 wrote:</cite><blockquote><p>I got it buddy thank you</p></blockquote></div><p>hi marc, welcome to the forum...</p><p>You&#039;ve used this code a couple of times ....</p><div class="codebox"><pre><code> 
  if (v&gt;100) v=100;
  if (v&lt;-100) v=-100; </code></pre></div><p>Nothing wrong with it, it works, but take a look at the &quot;constrain&quot; function. It toes the job in one go ....</p><div class="codebox"><pre><code>v = constrain(v, -100, 100);</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Daba)]]></author>
			<pubDate>Tue, 11 Aug 2020 14:10:51 +0000</pubDate>
			<guid>https://forum.remotexy.com/viewtopic.php?pid=3290#p3290</guid>
		</item>
		<item>
			<title><![CDATA[Re: I need help with joystick and l298n]]></title>
			<link>https://forum.remotexy.com/viewtopic.php?pid=3289#p3289</link>
			<description><![CDATA[<p>I got it buddy thank you</p>]]></description>
			<author><![CDATA[null@example.com (marc6194)]]></author>
			<pubDate>Tue, 11 Aug 2020 12:29:18 +0000</pubDate>
			<guid>https://forum.remotexy.com/viewtopic.php?pid=3289#p3289</guid>
		</item>
		<item>
			<title><![CDATA[Re: I need help with joystick and l298n]]></title>
			<link>https://forum.remotexy.com/viewtopic.php?pid=3245#p3245</link>
			<description><![CDATA[<p>Hello,<br />probably you should describe what your problem is, so that one can concentrate on this looking at your code, instead of searching through it.</p><p>The only thing I&#039;ve found at first glance is the following. You define motor speed to be -100 to +100. And later you multiply the speed with 2.55.<br />The range of analogWrite is 0 to 255. I&#039;m wondering if this mixed usage of float ( 2.55 ) and int ( v ) might confuse the analogWrite command, as<br />the type cast to int is missing.<br /></p><div class="codebox"><pre><code>/*
   v - motor speed can be set from -100 to 100
*/
...
    analogWrite(motor[2], v*2.55); </code></pre></div><p>I haven&#039;t tried it, but maybe </p><div class="codebox"><pre><code>analogWrite(motor[2], (int)(v*2.55)); </code></pre></div><p> could help.<br />Otherwise use the map() function like this </p><div class="codebox"><pre><code>analogWrite(motor[2], map(v,0,100,0,255); </code></pre></div><p> </p><p>rgs</p>]]></description>
			<author><![CDATA[null@example.com (Seventh Dwarf)]]></author>
			<pubDate>Sun, 02 Aug 2020 17:47:59 +0000</pubDate>
			<guid>https://forum.remotexy.com/viewtopic.php?pid=3245#p3245</guid>
		</item>
		<item>
			<title><![CDATA[I need help with joystick and l298n]]></title>
			<link>https://forum.remotexy.com/viewtopic.php?pid=3242#p3242</link>
			<description><![CDATA[<p>Can anyone help me please I want to use two joysticks the first joystick to tell 1 motor to go clockwise when pushed forward and counterclockwise when pushed backward and the second joystick to tell the other motor to go clockwise when pushed left and counterclockwise when pushed right I’m using l298n h bridge the code below controls both motors with one joystick I need two joysticks one for each motor i am using RemoteXY for joysticks My code is below</p><p>//////////////////////////////////////////////<br />//&nbsp; &nbsp; &nbsp; &nbsp; RemoteXY include library&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //<br />//////////////////////////////////////////////</p><p>// RemoteXY select connection mode and include library <br />#define REMOTEXY_MODE__SOFTSERIAL<br />#include &lt;SoftwareSerial.h&gt;</p><p>#include &lt;RemoteXY.h&gt;</p><p>// RemoteXY connection settings <br />#define REMOTEXY_SERIAL_RX 2<br />#define REMOTEXY_SERIAL_TX 3<br />#define REMOTEXY_SERIAL_SPEED 9600</p><br /><p>// RemoteXY configurate&nbsp; <br />#pragma pack(push, 1)<br />uint8_t RemoteXY_CONF[] =<br />&nbsp; { 255,5,0,0,0,62,0,10,0,0,<br />&nbsp; 5,48,67,28,29,29,12,24,31,5,<br />&nbsp; 46,4,29,29,29,12,24,31,2,1,<br />&nbsp; 39,56,21,5,12,24,31,31,79,78,<br />&nbsp; 0,79,70,70,0,129,0,25,1,50,<br />&nbsp; 6,12,82,67,45,88,68,32,67,111,<br />&nbsp; 110,116,114,111,108,108,101,114,0 };<br />&nbsp; <br />// this structure defines all the variables and events of your control interface <br />struct {</p><p>&nbsp; &nbsp; // input variables<br />&nbsp; int8_t Steering_x; // =-100..100 x-coordinate joystick position <br />&nbsp; int8_t Steering_y; // =-100..100 y-coordinate joystick position <br />&nbsp; int8_t Acceleration_x; // =-100..100 x-coordinate joystick position <br />&nbsp; int8_t Acceleration_y; // =-100..100 y-coordinate joystick position <br />&nbsp; uint8_t switch_1; // =1 if switch ON and =0 if OFF </p><p>&nbsp; &nbsp; // other variable<br />&nbsp; uint8_t connect_flag;&nbsp; // =1 if wire connected, else =0 </p><p>} RemoteXY;<br />#pragma pack(pop)</p><p>/////////////////////////////////////////////<br />//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;END RemoteXY include&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //<br />/////////////////////////////////////////////<br />/* defined the Steering motor control pins */ <br />#define in1 7 <br />#define in2 6 <br />#define enA 10 </p><p>/* defined the Acceleration motor control pins */ <br />#define in3 5 <br />#define in4 4 <br />#define enB 9 </p><p>/* defined the LED pin */ <br />#define PIN_SWITCH_1 13</p><p>/* defined two arrays with a list of pins for each motor */ <br />unsigned char SteeringMotor[3] =&nbsp; <br />&nbsp; {in1, in2, enA}; <br />unsigned char AccelerationMotor[3] =&nbsp; <br />&nbsp; {in3, in4, enB}; </p><p>/* <br />&nbsp; &nbsp;speed control of the motor <br />&nbsp; &nbsp;motor - pointer to an array of pins <br />&nbsp; &nbsp;v - motor speed can be set from -100 to 100 <br />*/ <br />void Wheel1 (unsigned char * motor, int v) <br />{ <br />&nbsp; if (v&gt;100) v=100; <br />&nbsp; if (v&lt;-100) v=-100; <br />&nbsp; if (v&gt;0) { <br />&nbsp; &nbsp; digitalWrite(motor[0], HIGH); <br />&nbsp; &nbsp; digitalWrite(motor[1], LOW); <br />&nbsp; &nbsp; analogWrite(motor[2], v*2.55); <br />&nbsp; } <br />&nbsp; else if (v&lt;0) { <br />&nbsp; &nbsp; digitalWrite(motor[0], LOW); <br />&nbsp; &nbsp; digitalWrite(motor[1], HIGH); <br />&nbsp; &nbsp; analogWrite(motor[2], (-v)*2.55); <br />&nbsp; } <br />&nbsp; else { <br />&nbsp; &nbsp; digitalWrite(motor[0], LOW); <br />&nbsp; &nbsp; digitalWrite(motor[1], LOW); <br />&nbsp; &nbsp; analogWrite(motor[2], 0); <br />&nbsp; } <br />} <br />void Wheel2 (unsigned char * motor, int v) <br />{ <br />&nbsp; if (v&gt;100) v=100; <br />&nbsp; if (v&lt;-100) v=-100; <br />&nbsp; if (v&gt;0) { <br />&nbsp; &nbsp; digitalWrite(motor[0], HIGH); <br />&nbsp; &nbsp; digitalWrite(motor[1], LOW); <br />&nbsp; &nbsp; analogWrite(motor[2], v*2.55); <br />&nbsp; } <br />&nbsp; else if (v&lt;0) { <br />&nbsp; &nbsp; digitalWrite(motor[0], LOW); <br />&nbsp; &nbsp; digitalWrite(motor[1], HIGH); <br />&nbsp; &nbsp; analogWrite(motor[2], (-v)*2.55); <br />&nbsp; } <br />&nbsp; else { <br />&nbsp; &nbsp; digitalWrite(motor[0], LOW); <br />&nbsp; &nbsp; digitalWrite(motor[1], LOW); <br />&nbsp; &nbsp; analogWrite(motor[2], 0); <br />&nbsp; } <br />} <br />void setup() <br />{<br />&nbsp; /* initialization pins */ <br />&nbsp; pinMode (in1, OUTPUT); <br />&nbsp; pinMode (in2, OUTPUT); <br />&nbsp; pinMode (in3, OUTPUT); <br />&nbsp; pinMode (in4, OUTPUT); <br />&nbsp; pinMode (PIN_SWITCH_1, OUTPUT);<br />&nbsp; <br />&nbsp; /* initialization module RemoteXY */ <br />&nbsp; RemoteXY_Init (); </p><p>}</p><p>void loop() <br />{ <br />&nbsp; /* event handler module RemoteXY */ <br />&nbsp; RemoteXY_Handler ();<br />&nbsp; <br />&nbsp; /* manage LED pin */ <br />&nbsp; digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH);</p><p>&nbsp; /* manage the Steering motor */ <br />&nbsp; Wheel1 (SteeringMotor, RemoteXY.Steering_y - RemoteXY.Steering_x);<br />&nbsp; Wheel1 (SteeringMotor, RemoteXY.Steering_x + RemoteXY.Steering_y);&nbsp; <br />&nbsp; <br />&nbsp; /* manage the Acceleration motor */ <br />&nbsp; Wheel2 (AccelerationMotor, RemoteXY.Acceleration_y - RemoteXY.Acceleration_x);<br />&nbsp; Wheel2 (AccelerationMotor, RemoteXY.Acceleration_x + RemoteXY.Acceleration_y); <br />&nbsp; // TODO you loop code<br />&nbsp; // use the RemoteXY structure for data transfer<br />&nbsp; // do not call delay() </p><br /><p>}</p>]]></description>
			<author><![CDATA[null@example.com (marc6194)]]></author>
			<pubDate>Sat, 01 Aug 2020 10:21:11 +0000</pubDate>
			<guid>https://forum.remotexy.com/viewtopic.php?pid=3242#p3242</guid>
		</item>
	</channel>
</rss>
