<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[RemoteXY community — More input cause bluetooth disconnected.]]></title>
	<link rel="self" href="https://forum.remotexy.com/extern.php?action=feed&amp;tid=217&amp;type=atom" />
	<updated>2017-08-03T06:46:31Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.remotexy.com/viewtopic.php?id=217</id>
		<entry>
			<title type="html"><![CDATA[Re: More input cause bluetooth disconnected.]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=854#p854" />
			<content type="html"><![CDATA[<p>Oh, thank you, man.</p>]]></content>
			<author>
				<name><![CDATA[mac]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=378</uri>
			</author>
			<updated>2017-08-03T06:46:31Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=854#p854</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: More input cause bluetooth disconnected.]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=853#p853" />
			<content type="html"><![CDATA[<p>Hello,</p><p>Here is a simple FSM I just wrote, I hope it can serve as an example to help you understand how to write your program.</p><p>This is for a modification of my computer display so that I can turn it on and off with RemoteXY. It simulates a press of 400ms on the &quot;on/off&quot; momentary pushbutton of the display, and then do nothing (but doesn&#039;t lock the microcontroller) during 4 seconds to avoid possible spam. </p><div class="codebox"><pre><code>uint8_t pwrBtnSimState = 0;

void pwrBtnSimTry()
{
    if ( pwrBtnSimState == 0 )
    {
        pwrBtnSimState = 1;
    }
}

void pwrBtnSimFSM()
{
    static uint32_t timer = 0;

    switch ( pwrBtnSimState )
    {
        case 1 :
        {
            digitalWrite( powerButtonPin, HIGH );
            timer = millis();
            pwrBtnSimState = 2;
            break;
        }
        case 2 :
        {
            if ( millis() - timer &gt;= 400UL )
            {
                digitalWrite( powerButtonPin, LOW );
                timer = millis();
                pwrBtnSimState = 3;
            }
            break;
        }
        case 3 :
        {
            if ( millis() - timer &gt;= 4000UL )
            {
                pwrBtnSimState = 0;
            }
            break;
        }
    }
}


void loop()
{
    // Try to start the simulation of the display&#039;s power button when the corresponding RemoteXY button is pressed
    uint8_t rxyPwrBtn = RemoteXY.pwrBtn;
    static uint8_t rxyPwrBtn_prev = rxyPwrBtn;

    if ( rxyPwrBtn_prev != rxyPwrBtn )
    {
        rxyPwrBtn_prev = rxyPwrBtn;

        if ( rxyPwrBtn == 1 )
        {
            pwrBtnSimTry();
        }
    }

    // Always run the FSM
    pwrBtnSimFSM();

    ...
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Guillaume]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=23</uri>
			</author>
			<updated>2017-08-02T18:31:52Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=853#p853</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: More input cause bluetooth disconnected.]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=830#p830" />
			<content type="html"><![CDATA[<p>Hi Guillaume, thank you for your reply. </p><p>I&#039;ve read that example and tried to use &#039;millis&#039; for a while. This lead me to new trouble. Can I ask about coding here.?</p>]]></content>
			<author>
				<name><![CDATA[mac]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=378</uri>
			</author>
			<updated>2017-07-28T03:33:26Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=830#p830</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: More input cause bluetooth disconnected.]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=829#p829" />
			<content type="html"><![CDATA[<p>Of course you should not use delay. It locks your code during that time. It&#039;s bad practice, especially when you have a wireless UI which must be responsive.</p><p>You have to use the method shown in the arduino&#039;s &quot;blink without delay&quot; example.</p><p>This will require that you use another coding style, the program flow will be harder to visualize, so I recommend that you also look at how to make a finite state machine.</p>]]></content>
			<author>
				<name><![CDATA[Guillaume]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=23</uri>
			</author>
			<updated>2017-07-28T01:04:32Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=829#p829</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: More input cause bluetooth disconnected.]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=827#p827" />
			<content type="html"><![CDATA[<p>Sure, and i have more info that may help clarify the problem. I found that if i remove&nbsp; delay commands, the system work fine. So, problem may be on the code side, not the App. or hardware. I think new question should be; how can i make program wait for amount of time without using delay command. </p><p>void loop() <br />{ </p><p>&nbsp; RemoteXY_Handler ();<br />&nbsp; <br />&nbsp; &nbsp; for ( int i=0; i&lt;RemoteXY.total; i++){</p><p>&nbsp; if (RemoteXY.start_button==0){<br />&nbsp; }<br />&nbsp; &nbsp;else {</p><p>&nbsp; digitalWrite(relay, HIGH);<br />&nbsp; delay(RemoteXY.wait_1);</p><p>&nbsp; if (RemoteXY.start_button==1){<br />&nbsp; digitalWrite(relay, LOW);<br />&nbsp; &nbsp; delay(RemoteXY.wait_2); </p><p>&nbsp; &nbsp; }<br />}<br />}</p><p>}</p>]]></content>
			<author>
				<name><![CDATA[mac]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=378</uri>
			</author>
			<updated>2017-07-26T08:35:57Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=827#p827</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: More input cause bluetooth disconnected.]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=824#p824" />
			<content type="html"><![CDATA[<p>Hello. Can you share a sketch that does not work?</p>]]></content>
			<author>
				<name><![CDATA[remotexy]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=2</uri>
			</author>
			<updated>2017-07-26T05:25:11Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=824#p824</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[More input cause bluetooth disconnected.]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=814#p814" />
			<content type="html"><![CDATA[<p>I have a few successful projects with RemoteXY, really like it. But for new project with 4 input, bluetooth connection was terminated within about 20 second.&nbsp; This in not a free version time limit, use RemoteXY paid version. And, this is not a hardware problem, since this set of hardware work well in other RemoteXY projects. I notice that if use one input, such as 1 text edit field, system run with no problem. But, if when place more input in a loop, bluetooth get disconnected within about 20 second. I&#039;ve tried another approach, read input first, then store data in EEPROM in void setup state, then read from EEPROM into a loop , but, no luck, bluetooth still get disconnected. Have you ever got this problem? How do you deal with it? Any ideas from all you guys are more than appreciated. Thank you.</p><p>BTW, i&#039;ve tried different 5v power sources for HC-05, excepted 3.3 v.</p>]]></content>
			<author>
				<name><![CDATA[mac]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=378</uri>
			</author>
			<updated>2017-07-24T05:20:53Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=814#p814</id>
		</entry>
</feed>
