<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[RemoteXY community — Adding switch button to existing code using l298n module with 1 dc mot]]></title>
		<link>https://forum.remotexy.com/viewtopic.php?id=1776</link>
		<atom:link href="https://forum.remotexy.com/extern.php?action=feed&amp;tid=1776&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Adding switch button to existing code using l298n module with 1 dc mot.]]></description>
		<lastBuildDate>Mon, 18 Mar 2024 01:29:36 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Adding switch button to existing code using l298n module with 1 dc mot]]></title>
			<link>https://forum.remotexy.com/viewtopic.php?pid=5435#p5435</link>
			<description><![CDATA[<p>#include &lt;dht.h&gt;<br />#include &lt;BTS7960.h&gt;</p><p>dht DHT;<br />int Sensor = 12;<br />int temperature;<br />int humidity;</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__ESP8266_HARDSERIAL_POINT</p><p>#include &lt;RemoteXY.h&gt;</p><p>// RemoteXY connection settings <br />#define REMOTEXY_SERIAL Serial<br />#define REMOTEXY_SERIAL_SPEED 115200<br />#define REMOTEXY_WIFI_SSID &quot;&quot;<br />#define REMOTEXY_WIFI_PASSWORD &quot;&quot;<br />#define REMOTEXY_SERVER_PORT 6377</p><p>// L298N motor driver pins<br />#define ENA 13 // Enable A<br />#define IN1 7 // Input 1<br />#define IN2 2 // Input 2</p><p>// RemoteXY configurate&nbsp; <br />#pragma pack(push, 1)<br />uint8_t RemoteXY_CONF[] =&nbsp; &nbsp;// 116 bytes<br />&nbsp; { 255,3,0,22,0,109,0,17,0,0,0,93,2,106,200,200,84,1,1,5,<br />&nbsp; 0,5,22,86,60,60,86,36,25,25,16,121,27,26,2,32,166,44,22,60,<br />&nbsp; 70,83,9,0,136,26,31,31,79,78,0,79,70,70,0,67,7,39,40,10,<br />&nbsp; 13,16,75,4,4,39,27,11,67,59,39,40,10,112,16,75,4,4,178,27,<br />&nbsp; 11,129,6,29,87,8,13,11,117,4,24,84,101,109,112,101,114,97,116,117,<br />&nbsp; 114,101,32,32,32,32,72,117,109,105,100,105,116,121,32,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 joystick_1_x; // from -100 to 100&nbsp; <br />&nbsp; int8_t joystick_1_y; // from -100 to 100&nbsp; <br />&nbsp; uint8_t switch_01; // =1 if switch ON and =0 if OFF</p><p>&nbsp; &nbsp; // output variables<br />&nbsp; char text_temp[11];&nbsp; // string UTF8 end zero <br />&nbsp; char text_hum[11];&nbsp; // string UTF8 end zero </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>// Left motor<br />const uint8_t LEFT_R_PWM_PIN = 6;<br />const uint8_t LEFT_L_PWM_PIN = 11;<br />const uint8_t LEFT_R_EN_PIN = 8;<br />const uint8_t LEFT_L_EN_PIN = 9;</p><p>// Right motor<br />const uint8_t RIGHT_R_PWM_PIN = 10;<br />const uint8_t RIGHT_L_PWM_PIN = 3;<br />const uint8_t RIGHT_R_EN_PIN = 4;<br />const uint8_t RIGHT_L_EN_PIN = 5;</p><p>// Control motor<br />BTS7960 motorController_1(RIGHT_R_EN_PIN, RIGHT_L_EN_PIN, RIGHT_R_PWM_PIN, RIGHT_L_PWM_PIN);<br />BTS7960 motorController_2(LEFT_R_EN_PIN, LEFT_L_EN_PIN, LEFT_R_PWM_PIN, LEFT_L_PWM_PIN);</p><p>void Wheel(int joystickX, int joystickY) {<br />&nbsp; &nbsp;int speed = map(joystickX, -100, 100, -20, 20); // Map joystick X-axis to motor speed range<br />&nbsp; int turnValue = map(joystickY, -100, 100, -20, 20); // Map joystick Y-axis to turning value</p><p>&nbsp; // Calculate individual motor speeds based on turnValue<br />&nbsp; int speedLeft = speed - turnValue;<br />&nbsp; int speedRight = speed + turnValue;</p><p>&nbsp; // Control the left motor<br />&nbsp; if (speedLeft &gt; 0) {<br />&nbsp; &nbsp; motorController_2.pwm = speedLeft;<br />&nbsp; &nbsp; motorController_2.front();<br />&nbsp; } else if (speedLeft &lt; 0) {<br />&nbsp; &nbsp; motorController_2.pwm = -speedLeft;<br />&nbsp; &nbsp; motorController_2.back();<br />&nbsp; } else {<br />&nbsp; &nbsp; motorController_2.stop();<br />&nbsp; }</p><p>&nbsp; // Control the right motor<br />&nbsp; if (speedRight &gt; 0) {<br />&nbsp; &nbsp; motorController_1.pwm = speedRight;<br />&nbsp; &nbsp; motorController_1.front();<br />&nbsp; } else if (speedRight &lt; 0) {<br />&nbsp; &nbsp; motorController_1.pwm = -speedRight;<br />&nbsp; &nbsp; motorController_1.back();<br />&nbsp; } else {<br />&nbsp; &nbsp; motorController_1.stop();<br />&nbsp; }<br />}</p><p>void setup() {<br />&nbsp; RemoteXY_Init();<br />&nbsp; Serial.begin(115200); // Begin the serial monitor for output<br />&nbsp; motorController_1.begin(); // Set the motor driver pins as output<br />&nbsp; motorController_1.enable();<br />&nbsp; motorController_2.begin(); // Set the motor driver pins as output<br />&nbsp; motorController_2.enable();<br />&nbsp; pinMode(ENA, OUTPUT);<br />&nbsp; pinMode(IN1, OUTPUT);<br />&nbsp; pinMode(IN2, OUTPUT);<br />}</p><p>void loop() {<br />&nbsp; RemoteXY_Handler();<br />&nbsp; int dhtCheck = DHT.read11(Sensor);<br />&nbsp; temperature = DHT.temperature;<br />&nbsp; humidity = DHT.humidity;</p><p>&nbsp; dtostrf(temperature, 0, 1, RemoteXY.text_temp);<br />&nbsp; dtostrf(humidity, 0, 1, RemoteXY.text_hum);</p><p>&nbsp; // Manage the motors<br />&nbsp; Wheel(RemoteXY.joystick_1_x, RemoteXY.joystick_1_y);<br />&nbsp; delay(200);</p><p>&nbsp; // Control the separate DC motor<br />&nbsp; digitalWrite(ENA, RemoteXY.switch_01 == 0 ? LOW : HIGH);<br />&nbsp; <br />}</p>]]></description>
			<author><![CDATA[null@example.com (Vin1)]]></author>
			<pubDate>Mon, 18 Mar 2024 01:29:36 +0000</pubDate>
			<guid>https://forum.remotexy.com/viewtopic.php?pid=5435#p5435</guid>
		</item>
	</channel>
</rss>
