Need help coding interrupts

I’m having a bit of trouble getting the photon to monitor the status of a single pin (D0) causing an LED (D7) to light up as it(D0) rises.

What have you tried so far?

Such as…?

//Declaring pins at output

int led1 = D0;
int butt = D1;
int led2 = D7;

/*
LED1 (output) indicates an interrupt by blinking (goes high).
BUTT (input) is a button for an interrupt.
LED2 (output) always outputs a HIGH. For the purpose of this prototype testing, it is a HIGH so that the signal can be manually used as an input. */

//Setup runs once at boot up or reset
void setup()
{	
	pinMode(led1, OUTPUT);
	pinMode(led2, OUTPUT);
	digitalWrite(led2, HIGH);
	attachInterrupt(butt, trigger, CHANGE);
}

void loop()
{
	digitalWrite(led1,LOW);
}

void trigger(){
	digitalWrite(led1, HIGH);
}

Lets just say I’m having a lot of trouble. I used other forum posts to get this part and so far the LED is always on unless the monitored pin is grounded

With a change trigger you’ll need either a pullup or a pulldown since even the slightest fluctuations will cause the CHANGE to trigger. Since you haven’t declared the button as an input, it’s presumably floating. Try an INPUT_PULLDOWN.

Any reason why you need an interrupt?

1 Like

My project is a piggy bank that will accept up to six coins. Each coin has its own input pin and for now I just need an LED to flash when its corresponding coin is received, only one coin can be input at a time.

With a change trigger you’ll need either a pullup or a pulldown since even the slightest fluctuations will cause the CHANGE to trigger. Since you haven’t declared the button as an input, it’s presumably floating. Try an INPUT_PULLDOWN

I just added the pull down and it seems to be working great, thank you!

1 Like

I made an earlier topic highlighting my issues with interrupts on the Photon and with some advice it managed to work on its own. However once adding more interrupts the code stopped working entirely.

I need a code that will poll pins D1-D6 for rising values, no more than one will rise at a time, and then blink an LED at D1 with the number of blinks changing based on the pin that was rising.

Please and Thank you.

Same question as before: what have you tried so far?

2 Likes

No need to clutter the forum with one and the same question really.

2 Likes