Cleo5 0 Posted September 10, 2016 Share Posted September 10, 2016 The code I am using allows me to press SW2 or SW3 and send a notification to IFTTT. I can't figure out how to identify which switch was press so I can send that information to IFTTT. Currently I can press SW2 and press SW3 and both will send a notification to IFTTT but I don't know how I can separately identify which button was pressed. Any direction would be appreciated. Code Below /* Enable internal pullup. * Without the pin will float and the example will not work */ pinMode(PUSH1, INPUT_PULLUP); attachInterrupt(PUSH1, sendRequest, FALLING); // Interrupt is fired whenever button is pressed Serial.println("Button 1 has been activated!"); /* Enable internal pullup. * Without the pin will float and the example will not work */ pinMode(PUSH2, INPUT_PULLUP); attachInterrupt(PUSH2, sendRequest, FALLING); // Interrupt is fired whenever button is pressed Serial.println("Button 2 has been activated"); } void loop() { String IFTTT_KEY = "KEY"; String IFTTT_EVENT = "Button 1 has been activated"; if(trigger == 1){ ifttt_trigger(IFTTT_KEY, IFTTT_EVENT); Serial.println("Button 1 has been activated"); trigger = 0; } } Quote Link to post Share on other sites
Rei Vilo 695 Posted September 10, 2016 Share Posted September 10, 2016 You seem to use interrupts but I don't find the sendRequest() Quote Link to post Share on other sites
Cleo5 0 Posted September 10, 2016 Author Share Posted September 10, 2016 You seem to use interrupts but I don't find the sendRequest() Maybe that's why I am having trouble. I am looking at the wrong part of the code? Quote Link to post Share on other sites
Rei Vilo 695 Posted September 10, 2016 Share Posted September 10, 2016 If you're not a programmer, may I suggest to try and compartmentalise your code? Instead of sending a IFTT request directly, blink a LED. If the LED blinks accordingly, then add the IFTT routine. Good luck! tripwire 1 Quote Link to post Share on other sites
energia 485 Posted October 4, 2016 Share Posted October 4, 2016 Use different functions for each button in attachInterrupt(): e.g. sendRequest1 and sendRequest2 then create another function calling it from the sendRequest1 / sendRequest2 that takes the button number as argument to be able to distinguish between buttons. Set trigger to the button number and then process that in loop(). Quote Link to post Share on other sites
Cleo5 0 Posted June 18, 2017 Author Share Posted June 18, 2017 On 10/4/2016 at 1:17 PM, energia said: Use different functions for each button in attachInterrupt(): e.g. sendRequest1 and sendRequest2 then create another function calling it from the sendRequest1 / sendRequest2 that takes the button number as argument to be able to distinguish between buttons. Set trigger to the button number and then process that in loop(). Is there example code I can look at? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.