Use the ON and OFF lamp button with the remoteXY
But how do I use an external push button that reflects the status of the button on the app
I cannot make sense of your problem / comment / whatever it was ?
Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.
So you have a Bluetooth module and a button on the breadboard?
You want to be able to control the LED from both?
You have a (cellphone?) app that controls the led (on/off)?
You now want to use the button to switch the LED off when it is on and on when it is off?
If all of the above is true, the basics is to remember the status of the LED on a variable. If you're using an Uno as in your picture, you can actually read back the status of the led pin and toggle it; no need for the variable.
Show your code (use code tags as described in the stickies) for further help.
Additional info: study the state change detection example how you can detect when a button becomes pressed (not the same as is pressed).
I am using esp 8266
But the code did not work for me to control the LED through the button and the application
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT
#include <RemoteXY.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "any think"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,1,0,0,0,31,0,10,13,0,
2,0,8,16,22,11,2,26,97,31,
79,78,0,79,70,70,0,129,0,7,
6,12,6,17,76,69,68,0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
uint8_t switch_1; // =1 if switch ON and =0 if OFF
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define PIN_SWITCH_1 11
void setup()
{
RemoteXY_Init ();
pinMode (PIN_SWITCH_1, OUTPUT);
// TODO you setup code
}
void loop()
{
RemoteXY_Handler ();
digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH);
// TODO you loop code
// use the RemoteXY structure for data transfer
}
How do I add a button code to control the مLED as well
Please do not center your text, it's a nightmare to read, specifically the code like that.
Thanks for using code tags.
I will look at your code later; I do not have an ESP so can't test.
i'm sorry This code, however, I did not find the appropriate format for dealing with the portlet "pbutton"
[code]
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "any think"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,1,0,0,0,31,0,10,13,0,
2,0,8,16,22,11,2,26,97,31,
79,78,0,79,70,70,0,129,0,7,
6,12,6,17,76,69,68,0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
uint8_t switch_1; // =1 if switch ON and =0 if OFF
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define PIN_SWITCH_1 11
int pbutton =9 ;
void setup()
{
RemoteXY_Init ();
pinMode (pbutton,INPUT_PULLUP);
pinMode (PIN_SWITCH_1, OUTPUT);
// TODO you setup code
}
void loop()
{
RemoteXY_Handler ();
digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH);
// TODO you loop code
// use the RemoteXY structure for data transfer
}[/code]
Thank you all, I saccessful after modifying the code
I must try before the question
This code is to control the LED via the push button and also through the Internet application
esp 8266
At the same time
void loop()
{
RemoteXY_Handler ();
if (digitalRead(pus)==LOW){//push button
digitalWrite(PIN_SWITCH_1,!val);
RemoteXY.switch_1=!val;
delay(500);
}
if (RemoteXY.switch_1!=0){ digitalWrite(PIN_SWITCH_1, HIGH);
val=255;
RemoteXY.led1_r=val;
}
else { digitalWrite(PIN_SWITCH_1, LOW);
val=0;
RemoteXY.led1_r=val;
}
// TODO you loop code
// use the RemoteXY structure for data transfer
}
thank you
Great
below was my tested version on an Uno with comments; works slightly different.
It uses the serial port (as replacement of remoteXY). Note that the button is wired differently from yours; I don't know if the ESP supports internal pull-up resistor so I have put some comments in the code for your set up. Further you need to adjust the pin numbers.
// change to HIGH for your setup with a pull-down resistor
#define ISPRESSED LOW
const byte buttonPin = 2;
const byte ledPin = LED_BUILTIN;
byte ledStatus = HIGH;
void setup()
{
Serial.begin(57600);
// button between pin and ground
// change to INPUT for your setup with a pull-down resistor
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, ledStatus);
}
void loop()
{
static byte currentButtonStatus = !ISPRESSED;
byte buttonStatus = digitalRead(buttonPin);
/********************
simulate remoteXY
********************/
// if data received on serial
if (Serial.available() > 0)
{
// read the byte
char x = Serial.read();
// set the led status based on received data
if (x == '0')
{
ledStatus = LOW;
}
else if (x == '1')
{
ledStatus = HIGH;
}
}
/********************
read button
********************/
if (buttonStatus != currentButtonStatus)
{
currentButtonStatus = buttonStatus;
if (currentButtonStatus == ISPRESSED)
{
// change the led status when the button becomes pressed
ledStatus = !ledStatus;
}
// simple debounce using delay
delay(50);
}
/********************
set the led
********************/
digitalWrite(ledPin, ledStatus);
}
The above code uses a short delay. If that is an issue, improvents can be made based on the debounce example in the IDE.
Thanks ... yes it works