Hi, with this code as TX when I monitor the output window in SM I see sometimes button B come on when I connect button A to +5V -
I am using pull_down resistor 10K. - arduino Pro mini 5V
Am I doing something wrong?
// Define variables
int L_Button = LOW;
int R_Button = LOW;
#include <SPI.h>
#include "RF24.h"
#include "printf.h"
RF24 radio(9, 10);
// Controller Address
const uint64_t Controller_1 = 0xE8E8F0F0E1LL;
/*-----( Declare Variables )-----*/
uint8_t command[16]; // 2 element array of unsigned 8-bit type, holding readings
void setup()
{
Serial.begin(115000);
printf_begin();
pinMode(2, INPUT); // A Button
pinMode(3, INPUT); // B Button
radio.begin();
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(Controller_1);
radio.printDetails();
}
void loop()
{
Buttons();
delay(50);
}
void Buttons(void)
{
// Check Buttons
L_Button = digitalRead(2);
R_Button = digitalRead(3);
if (R_Button == 1)
{
command[0] = 1; // Command to turn on
Serial.println("A Button 1");
}
else
{
command[0] = 0; // Turn off
}
if (L_Button == 1)
{
command[1] = 1; // Command to turn on
Serial.println("B Button 1");
}
else
{
command[1] = 0; // Turn off
}
Send_Data();
}
// Function to send the data
void Send_Data(void)
{
radio.write(command, sizeof(command));
//Serial.println("0");
}
If a pin is floating it will follow the pins next to it... Basically a floating pin is undefined, if you want
it defined use INPUT_PULLUP or an external pull-up or pull-down.
@ Tammytam, printing to see what it is doing ( the state ) - I don't get you . what should I Print? maybe I miss explained - are you talking about the swapping of the buttonName?,,if so that is not the problem , I will correct it , what I am saying is that if I keep button A or B pressed/touched/+5V it eventually triggers the vice versa button (like noise or something call it) instead of it behaving independently
@MarkT : defining input is not equal to Pull down?
it is setup as : -0V ---<---10K----<---Pin2 ----->+5V