its easier for folks if you post your code here:
/**
* This is a simple "sketch" that calls a web page when a button is pressed. It is a proof-of-concept
* for my boss and hastily written in about 2 hours. The remote URL is a PHP script that handles
* making the API calls to a remote SMS-messaging service.
*
* I'm sure it could make use of interrupts somehow, but I'm not sure how off the top of my head.
*
* It uses the onboard RGB LED as status display:
* - Red = Waiting to be pressed
* - Green = Making HTTP request
* - Blue = Finished HTTP request
*
* Hardware:
* - Normally-off momentary button
* - Spark Core
*
* Setup:
* - Connect one pin of the button to GND
* - Connect the other pin of the button to the desired digital pin on the Spark Core
*
* The configuration is in the variables defined at the top of the script. They should be pretty
* self-explanatory.
**/
int millLast = 0; // Last time (in millis()) the doorbell was pressed
int blueTeam = D0; // blue team pin #
int redTeam = D1; // red team pin #
int millDelay = 100; // How much time to wait until we allow another doorbell "ring" again
char srvIP[] = "10.0.0.251"; // Server IP address
char srvHost[] = "http://bobafett.local"; // HTTP 1.1 hostname
int srvPort = 3000; // Server port number
char srvPathBlue[] = "/game/blueplus"; // URL path
char srvPathRed[] = "/game/redplus"; // URL path
void setup() {
pinMode(blueTeam, INPUT_PULLUP);
pinMode(redTeam, INPUT_PULLUP);
RGB.control(true);
}
void loop() {
if(digitalRead(blueTeam)==HIGH)
bluePointPlus();
else if(digitalRead(redTeam)==HIGH)
redPointPlus();
else
RGB.color(255, 0, 0);
}
void bluePointPlus() {
if(millLast==0 || (millLast+millDelay)<millis()) {
millLast = millis();
RGB.color(0, 255, 0);
httpGetRequest(srvIP, srvHost, srvPort, srvPathBlue);
RGB.color(0, 0, 255);
delay(1000);
}
}
void redPointPlus() {
if(millLast==0 || (millLast+millDelay)<millis()) {
millLast = millis();
RGB.color(0, 255, 0);
httpGetRequest(srvIP, srvHost, srvPort, srvPathRed);
RGB.color(0, 0, 255);
delay(1000);
}
}
void httpGetRequest(char* ip, char* hostname, int port, char* url) {
char line[255];
TCPClient client;
client.connect(ip, port);
strcpy(line, "GET ");
strcat(line, url);
strcat(line, " HTTP/1.1");
client.println(line);
delay(100);
strcpy(line, "Host: ");
strcat(line, hostname);
client.println(line);
delay(100);
strcpy(line, "Content-Length: 0");
client.println(line);
delay(100);
client.println();
delay(100);
client.flush();
delay(100);
client.stop();
delay(250);
}
You have some blocking code in your functions -> delay(1000)
<- that may prevent your code from responding during that delay.
you can study the classic state change example and consider using that… before you consider an interrupt:
const int buttonPin = D2; // the pin that the pushbutton is attached to
const int ledPin = D7; // the pin that the LED is attached to
int lastButtonState = 0; // previous state of the button
void setup()
{
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState)
{
if (buttonState == HIGH)
{
Serial.println("on");
}
else
{
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(25);
}
lastButtonState = buttonState;
}