Button Function Fires repeatedly but no button was pushed
hey all,
i'm working huzzah feather , usual can pieces work not whole. button function keeps firing despite no button pushes.
i've wired capacitive touch button , loaded arduino debounce example sketch , works intended.
i'm using mqtt send data , io.adafruit.com. i've set couple of feeds , can toggle pins on board io.adafruit.com, super cool!
when add button function code works keeps firing on , over. how can write executes when button pressed?
thanks!
rich
i'm working huzzah feather , usual can pieces work not whole. button function keeps firing despite no button pushes.
i've wired capacitive touch button , loaded arduino debounce example sketch , works intended.
i'm using mqtt send data , io.adafruit.com. i've set couple of feeds , can toggle pins on board io.adafruit.com, super cool!
when add button function code works keeps firing on , over. how can write executes when button pressed?
code: [select]
#include "config.h"
#define led_pin 5
const int button_pin = 16; // number of pushbutton pin
int ledstate = low; // current state of output pin
int buttonstate; // current reading input pin
int lastbuttonstate = low; // previous reading input pin
long lastdebouncetime = 0; // last time output pin toggled
long debouncedelay = 50; // debounce time; increase if output flickers
adafruitio_feed *digital = io.feed("digital");
void handlemessage(adafruitio_data *data) {
serial.print("received digital feed <- ");
if (data->topinlevel() == high)
serial.println("high");
else
serial.println("low");
// write current state led
digitalwrite(led_pin, data->topinlevel());
}
void button() {
int reading = digitalread(button_pin);
if (reading != lastbuttonstate) {
lastdebouncetime = millis();
}
if ((millis() - lastdebouncetime) > debouncedelay) {
if (reading != buttonstate) {
buttonstate = reading;
if (buttonstate == high) {
ledstate = !ledstate;
}
}
}
lastbuttonstate = reading;
serial.print("digital pin status"); serial.println(ledstate);
digitalwrite(led_pin, ledstate);
digital->save(ledstate);
}
void setup() {
pinmode(button_pin, input);
pinmode(led_pin, output);
digitalwrite(led_pin, ledstate);
serial.begin(115200);
while (! serial);
serial.print("connecting adafruit io");
io.connect();
digital->onmessage(handlemessage);
while (io.status() < aio_connected) {
serial.print(".");
delay(500);
}
serial.println();
serial.println(io.statustext());
}
void loop() {
io.run();
button();
}
thanks!
rich
how button wired ?
Arduino Forum > Using Arduino > Programming Questions > Button Function Fires repeatedly but no button was pushed
arduino
Comments
Post a Comment