wireless start light button problem
hi folks beginner planning make start light simulation using 3 push buttons , nrf24l01 modules. having issues pushbutton code implementation. when button red pressed 1 time want lit constantly. press green , should lit same way. when push reset leds should go off. can see diagram , code code not working properly.
what problem? appreciate help.
what problem? appreciate help.
code: [select]
const int buttonpin_one = 1;
const int ledpin_one = 13;
const int buttonpin_two=3;
const int ledpin_two=11;
const int button_reset=5;
int buttonpushcounter_one = 0;
int buttonstate_one = 0;
int lastbuttonstate_one = 0;
int buttonpushcounter_two = 0;
int buttonstate_two = 0;
int lastbuttonstate_two = 0;
//int buttonpushcounter_three = 0;
boolean buttonstate_three = false;
boolean lastbuttonstate_three = false;
int state=0;
void setup() {
pinmode(buttonpin_one, input_pullup);
pinmode(ledpin_one, output);
pinmode(buttonpin_two,input_pullup);
pinmode(ledpin_two, output);
pinmode(button_reset,input);
}
void loop()
{
buttonstate_one = digitalread(buttonpin_one);
buttonstate_two = digitalread(buttonpin_two);
buttonstate_three=digitalread(button_reset);
///////////////////////////////////////////////////////////////
if (buttonstate_one != lastbuttonstate_one)
{
if (buttonstate_one == high)
{
buttonpushcounter_one++;
}
delay(20);
}
lastbuttonstate_one = buttonstate_one;
if (buttonpushcounter_one % 2 == 0)
{
digitalwrite(ledpin_one, high);
}
////////////////////////////////////////////////////////////////
if (buttonstate_two != lastbuttonstate_two)
{
if (buttonstate_two == high)
{
buttonpushcounter_two++;
}
delay(20);
}
lastbuttonstate_two = buttonstate_two;
if (buttonpushcounter_two % 2 == 0)
{
digitalwrite(ledpin_two, high);
}
///////////////////////////////////////////////////////////////////
if (buttonstate_three != lastbuttonstate_three) {
if (buttonstate_three == high) {
digitalwrite(ledpin_two, low);
digitalwrite(ledpin_one, low);
}
delay(50);
}
lastbuttonstate_three = buttonstate_three;
}
code: [select]
const int buttonpin_one = 1;
your fritz shows pin 2. fyi pin 1 hardware serial tx pin.
code: [select]
pinmode(buttonpin_one, input_pullup);
this implies button wired input ground, button state high when not pushed , low when pushed. assuming open switches. have assume cause frtz doesn't say, schematic more clear.
code: [select]
if (buttonstate_one == high)
{
buttonpushcounter_one++;
}
and here increment counter if button not pushed. right?
the same button 2.
does reset button have external pulldown (or pullup) resistor. ask cause has no input_pullup.
common button wiring:
please read "how use forum" stickies. tell how format , post code , hoe ask effective question. better if post code instead of attaching it.
Arduino Forum > Using Arduino > Project Guidance > wireless start light button problem
arduino
Comments
Post a Comment