<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[RemoteXY community — "if" function not working]]></title>
	<link rel="self" href="https://forum.remotexy.com/extern.php?action=feed&amp;tid=1646&amp;type=atom" />
	<updated>2023-04-17T15:57:41Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.remotexy.com/viewtopic.php?id=1646</id>
		<entry>
			<title type="html"><![CDATA[Re: "if" function not working]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=5104#p5104" />
			<content type="html"><![CDATA[<p>Change <br /></p><div class="codebox"><pre><code> if (speed = 0){</code></pre></div><p>into <br /></p><div class="codebox"><pre><code> if (speed == 0){</code></pre></div><p>.</p><p>= is an assignment. == a compairison.</p>]]></content>
			<author>
				<name><![CDATA[jw]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=2417</uri>
			</author>
			<updated>2023-04-17T15:57:41Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=5104#p5104</id>
		</entry>
		<entry>
			<title type="html"><![CDATA["if" function not working]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=5100#p5100" />
			<content type="html"><![CDATA[<p>before i start- i am a complete newb when it comes to programming, microcontrollers, electronics etc. </p><p>I am trying to build a remote controlled car using an arduino nano. HC-05, sg90 servo, l298n motor driver and a simple BO motor. I will attach the code at the end. Here&#039;s my issue:</p><p>for the life of me, i cannot get any of the &quot;if&quot; statements to work. i tried to check if the pins are outputting anything using LEDs, and they&#039;re not.</p><p>i tried to test it by simplifying the code(again, with LEDs) . i first only kept the digital writes, it works. then i tried only the analogwrite, that works too. but when i put it all together, it doesnt work. i initially had the digitalwrite and analogwrite within the &quot;if&quot; conditions, then i moved it out as part of my trial to fix it. the &quot;lead1&quot; and &quot;lead2&quot; chars were also part of that modification. initally it was a straight high/low in the digital write.</p><p>the servo works flawlessly through all this.</p><p>PS: I&#039;m unable to work the text sprintf too, but its secondary. I&#039;d appreciate help with that too, but i can do without it. i did simila debug attempts with this too.</p><div class="codebox"><pre><code>#define REMOTEXY_MODE__HARDSERIAL

#include &lt;RemoteXY.h&gt;

// RemoteXY connection settings 
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 9600


// RemoteXY configurate  
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =   // 61 bytes
  { 255,2,0,51,0,54,0,16,31,0,4,176,42,29,49,5,2,26,4,48,
  19,10,5,45,2,26,129,0,3,30,14,5,17,83,112,101,101,100,0,129,
  0,59,37,15,6,17,83,116,101,101,114,0,67,4,31,17,61,5,2,26,
  51 };
  
// this structure defines all the variables and events of your control interface 
struct {

    // input variables
  int8_t steer; // =-100..100 slider position 
  int8_t speed; // =-100..100 slider position 

    // output variables
  char monitor[51];  // string UTF8 end zero 

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0 

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////
#include &lt;Servo.h&gt;

const int pedal = 6; //motor PWM
const int motora = 7; // motor direction
const int motorb = 8; // motor direction
const int servopin = 5;
Servo servo1;
int move;
char lead1;
char lead2;

void setup() 
{
  RemoteXY_Init (); 
  pinMode(motora, OUTPUT);
  pinMode(motorb, OUTPUT);
  pinMode(pedal, OUTPUT);
  servo1.attach(servopin);
  // TODO you setup code
  
}

void loop() 
{ 
  RemoteXY_Handler ();

  int steer = RemoteXY.steer;
  int speed = RemoteXY.speed;
  int servoPosition = map(steer, -100, 100, 0, 180);
  servo1.write(servoPosition);

  if (speed = 0){
   lead1 = LOW;
   lead2 = LOW;
  sprintf (RemoteXY.monitor, &quot;Brake..&quot;);
  }

  else if (speed &gt; 0){
   lead1 = HIGH;
   lead2 = LOW;
    move = map(speed, 0, 100, 0, 255);
  }

  else if (speed &lt; 0){
   lead2 = HIGH;
   lead1 = LOW;
    move = map(speed, 0, 100, 0, 255);
  }
  digitalWrite(motora, lead1);
  digitalWrite(motorb, lead2);
  analogWrite(pedal, move);
  sprintf (RemoteXY.monitor, move);
  // TODO you loop code
  // use the RemoteXY structure for data transfer
  // do not call delay() 


}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[siva.kanth.sharma]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=2405</uri>
			</author>
			<updated>2023-04-12T17:00:12Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=5100#p5100</id>
		</entry>
</feed>
