/* Sample using OneButton Library to activate the BlueTooth power switch via a transistor. The library internals are explained at http://www.mathertel.de/Arduino/OneButtonLibrary.aspx Setup a test circuit: * Connect a pushbutton to pin A1 (ButtonPin) and ground. * The Serial interface is used for output the detected button events. In the loop function the Magic_Button.tick function check the button state. */ #include "OneButton.h" OneButton Magic_Button(5, true); // Initialize a new OneButton object on pin 5. int BlueTooth_Power_Pin; // Initialize pin that activates the Transistor switch for BlueTooh Power // setup code here, to run once: void setup() { //pinMode(BlueTooth_Power_Pin, OUTPUT); // Declare this pin as an ouput pinMode(A0, OUTPUT); // Declare this pin as an ouput // Attach the button's functions. // This calls the declared function on click event Magic_Button.attachClick(Magic_Button_click); // Magic_Button.attachDoubleClick(Magic_Button_doubleclick); // Magic_Button.attachLongPressStart(Magic_Button_longPressStart); // when button is held down, call Magic_Button_longPressStart function. Magic_Button.attachLongPressStop(Magic_Button_longPressStop); // Magic_Button.attachDuringLongPress(Magic_Button_longPress); // } // setup // main code here, to run repeatedly: void loop() { // keep watching the push buttons: Magic_Button.tick(); // You can implement other code in here or just wait a while delay(10); } // loop // ----- button 1 callback functions // This function will be called when the Magic_Button was pressed 1 time (and no 2. button press followed). void Magic_Button_click() { } // This function will be called when the Magic_Button was pressed 2 times in a short timeframe. void Magic_Button_doubleclick() { // } // This function will be called once, when the Magic_Button is first pressed down and held for a long time.. void Magic_Button_longPressStart() { // test to activate the Bluetooth Power switch via a transistor. //digitalWrite(BlueTooth_Power_Pin,HIGH); digitalWrite(A0,HIGH); digitalWrite(13,HIGH); } // This function will be called once, when the Magic_Button is released after beeing pressed for a long time. void Magic_Button_longPressStop() { // //digitalWrite(BlueTooth_Power_Pin,LOW); digitalWrite(A0,LOW); digitalWrite(13,LOW); } // This function will be called often, while the Magic_Button is pressed for a long time. void Magic_Button_longPress() { // }