Hardware Reference
In-Depth Information
#define SENSOR1_PIN 2
#define EMITTER1_PIN 5
#define EMITTER2_PIN 6
#define BEATS 6
In listing 9-2 the interrupt pin is defined as PIN_INT1. This is a generic way to refer to interrupt 1. Depending
on what kind of ChipKit you use these can map to different pins on the hardware. For a ChipKit Uno32 these map to
pin 2. If you wanted to use a different interrupt you could use:
Listing 9-2. define hardware values
PIN_INT0 38
PIN_INT1 2
PIN_INT2 7
PIN_INT3 8
PIN_INT4 35
When ever you switch to a different board you will want to double check which pins correspond to the correct
interrupt.
int emmiter1_id;
int emmiter2_id;
unsigned long blink1_var;
unsigned long blink2_var;
In listing 9-3 the the required ChipKit Task Manager variables are defined emmiter1_id, and emmiter2_id are the
task identifier variable that are used to register the task. The blink1_var, and blink2_var are the the data variables that
are passed into the task function and represent the current time information.
Listing 9-3. ChipKit Task Manager Library require variables
volatile boolean emitter1State = LOW;
volatile boolean emitter2State = LOW;
volatile boolean prevEmitter1State = LOW;
volatile boolean prevEmitter2State = LOW;
volatile boolean detected = LOW;
volatile boolean e1detected = LOW;
volatile boolean e2detected = LOW;
volatile unsigned long emit1Count = 0;
volatile unsigned long emit2Count = 0;
volatile unsigned long detectCount = 0;
The meta data about the task are defined. This includes detection count, current emitter status, previous emitter
status, and which emitter was detected. These values will be adjusted in the task manger functions, and the when the
detection interrupt is triggered.
Search WWH ::




Custom Search