Button Project
hey guys,
i need i'm new arduino , programming in generel. try arduino micro work buttons. goal if button pressed send information serial. -i using button.h libary able use ishold , onrelease. buttons connected ground. dont receve on serial. heres code:
thanky in advance
i need i'm new arduino , programming in generel. try arduino micro work buttons. goal if button pressed send information serial. -i using button.h libary able use ishold , onrelease. buttons connected ground. dont receve on serial. heres code:
code: [select]
#include <button.h>
button button2 = button(2, low);
button button3 = button(3, low);
button button4 = button(4, low);
button button5 = button(5, low);
button button6 = button(6, low);
button button7 = button(7, low);
button button8 = button(8, low);
button button9 = button(9, low);
button button10 = button(10, low);
button button11 = button(11, low);
button button12 = button(12, low);
boolean holding2 = false;
boolean holding3 = false;
boolean holding4 = false;
boolean holding5 = false;
boolean holding6 = false;
boolean holding7 = false;
boolean holding8 = false;
boolean holding9 = false;
boolean holding10 = false;
boolean holding11 = false;
boolean holding12 = false;
void setup()
{
serial.begin(9600);
pinmode(2, input_pullup);
pinmode(3, input_pullup);
pinmode(4, input_pullup);
pinmode(5, input_pullup);
pinmode(6, input_pullup);
pinmode(7, input_pullup);
pinmode(8, input_pullup);
pinmode(9, input_pullup);
pinmode(10, input_pullup);
pinmode(11, input_pullup);
pinmode(12, input_pullup);
}
void loop()
{
button2.listen();
if (button2.onpress()) {
serial.print("<click:");
serial.print("20");
serial.print(">");
}
if(!holding2 && button2.ishold()) {
serial.print("<hold:");
serial.print("20");
serial.print(">");
holding2 = true;
}
if(holding2 && button2.onrelease()) {
serial.print("<release:");
serial.print("20");
serial.print(">");
holding2 = false;
}
button3.listen();
if (button3.onpress()) {
serial.print("<click:");
serial.print("30");
serial.print(">");
}
if(!holding3 && button3.ishold()) {
serial.print("<hold:");
serial.print("30");
serial.print(">");
holding3 = true;
}
if(holding3 && button3.onrelease()) {
serial.print("<release:");
serial.print("30");
serial.print(">");
holding3 = false;
}
button4.listen();
if (button4.onpress()) {
serial.print("<click:");
serial.print("40");
serial.print(">");
}
if(!holding4 && button4.ishold()) {
serial.print("<hold:");
serial.print("40");
serial.print(">");
holding4 = true;
}
if(holding4 && button4.onrelease()) {
serial.print("<release:");
serial.print("40");
serial.print(">");
holding4 = false;
}
button5.listen();
if (button5.onpress()) {
serial.print("<click:");
serial.print("50");
serial.print(">");
}
if(!holding5 && button5.ishold()) {
serial.print("<hold:");
serial.print("50");
serial.print(">");
holding5 = true;
}
if(holding5 && button5.onrelease()) {
serial.print("<release:");
serial.print("50");
serial.print(">");
holding5 = false;
}
button6.listen();
if (button6.onpress()) {
serial.print("<click:");
serial.print("60");
serial.print(">");
}
if(!holding6 && button6.ishold()) {
serial.print("<hold:");
serial.print("60");
serial.print(">");
holding6 = true;
}
if(holding6 && button6.onrelease()) {
serial.print("<release:");
serial.print("60");
serial.print(">");
holding6 = false;
}
button7.listen();
if (button7.onpress()) {
serial.print("<click:");
serial.print("70");
serial.print(">");
}
if(!holding7 && button7.ishold()) {
serial.print("<hold:");
serial.print("70");
serial.print(">");
holding7 = true;
}
if(holding7 && button7.onrelease()) {
serial.print("<release:");
serial.print("70");
serial.print(">");
holding7 = false;
}
button8.listen();
if (button8.onpress()) {
serial.print("<click:");
serial.print("80");
serial.print(">");
}
if(!holding8 && button8.ishold()) {
serial.print("<hold:");
serial.print("80");
serial.print(">");
holding8 = true;
}
if(holding8 && button8.onrelease()) {
serial.print("<release:");
serial.print("80");
serial.print(">");
holding8 = false;
}
button9.listen();
if (button9.onpress()) {
serial.print("<click:");
serial.print("90");
serial.print(">");
}
if(!holding9 && button9.ishold()) {
serial.print("<hold:");
serial.print("90");
serial.print(">");
holding9 = true;
}
if(holding9 && button9.onrelease()) {
serial.print("<release:");
serial.print("90");
serial.print(">");
holding9 = false;
}
button10.listen();
if (button10.onpress()) {
serial.print("<click:");
serial.print("100");
serial.print(">");
}
if(!holding10 && button10.ishold()) {
serial.print("<hold:");
serial.print("100");
serial.print(">");
holding10 = true;
}
if(holding10 && button10.onrelease()) {
serial.print("<release:");
serial.print("100");
serial.print(">");
holding10 = false;
}
button11.listen();
if (button11.onpress()) {
serial.print("<click:");
serial.print("110");
serial.print(">");
}
if(!holding11 && button11.ishold()) {
serial.print("<hold:");
serial.print("110");
serial.print(">");
holding11 = true;
}
if(holding11 && button11.onrelease()) {
serial.print("<release:");
serial.print("110");
serial.print(">");
holding11 = false;
}
button12.listen();
if (button12.onpress()) {
serial.print("<click:");
serial.print("120");
serial.print(">");
}
if(!holding12 && button12.ishold()) {
serial.print("<hold:");
serial.print("120");
serial.print(">");
holding12 = true;
}
if(holding12 && button12.onrelease()) {
serial.print("<release:");
serial.print("120");
serial.print(">");
holding12 = false;
}
}
thanky in advance
where did button library using? version linked playground doesn't have listen() method.
Arduino Forum > Using Arduino > Project Guidance > Button Project
arduino
Comments
Post a Comment