Introduction: Multiple PICAXE Interrupts
This Instructable tells you how to set up multiple picaxe interrupts.
You will need:
1 x PICAXE chip (any), I will draw a circuit diagram for a 14M
2 x diode
2 x switch
1 x LED
1 x 330R resistor
3 x 10K resistor
1 x 22K resistor
1 x 3.5 mm serial plug
1 x PICAXE programming cable + software
Step 1: Make Circuit to Program Chip
To program the chip, build the circuit below:
Connect the serial in on the chip to a 22K resistor.
Connect a 10K resistor to the end of this.
Connect the joint to section "B" on the jack.
Connect the 10K resistor to negative.
Connect part "C" of the jack to negative.
Connect serial out on the chip to the centre pin ("A") on the jack.
Connect the chip to positive and negative.
Step 2: Set Up Inputs
To connect the two switches:
Connect one side of the switch to positive.
Connect the other side of the switch to a 10K resistor, then to negative.
Connect the joint between the switch and the resistor to an input pin.
Connect the joint between the switch and the resistor to a diode, then to a spare input pin.
Repeat this for both switches, but connect the ends of the diodes to the same input.
Step 3: Connect the LED
To connect the LED:
Connect the LED to an output pin.
Connect the other end to a 300R resistor.
Connect the other end of the resistor to negative.
Step 4: Program
Connect the circuit to a computer, and open the programming software. Enter the following code: (This code is for the circuit in the diagram below)
Below is what the code means:
This code sets an interrupt for pin 3, which is connect to both switches by diodes.
This is a label for a routine named "main"
This runs the routine "main". These two lines of code constantly loop, doing nothing. This is to show the interrupt.
This is a label for a subroutine called "interrupt", which is run when pin 3 is triggered.
This sets pin 5 (connected to the LED) to high, which turns on the LED.
This tells the code to wait for 5000 milliseconds (5 seconds) before continuing.
This sets pin 5 to low, which turns off the LED.
This renables the interrupt again, because it is disabled when it is triggered.
This tells the code to return to the point at which the subroutine was activated (when either switch was pressed)
Step 5: Test
When you press either switch, the LED should turn on for 5 seconds, then off again.
We have a be nice policy.
Please be positive and constructive.