Hardware Reference
In-Depth Information
Listing 9-4. Emmiter data defined and initialized with default values
volatile int phaseA = 0;
volatile int phaseB = 0;
volatile int prevPhaseA = -1;
volatile int prevPhaseB = -1;
volatile int measureA = 0;
volatile int measureB = 0;
volatile int prevMeasureA = -1;
volatile int prevMeasureB = -1;
A measure is defined as the basic container of a set number of intervals that can be thought of as beats per
measure. As each of these beats is stepped through the phase of the measure is updated. The default configuration
is 6 beats per measure. Every time a task is activated it increases the phase until it reaches the end of the measure and
the measure and phases start over again.
Listing 9-5. The measeure and the phase of the measure are defined and initialized
//Prototypes
void blink_emitter1(int id, void * tptr);
void blink_emitter2(int id, void * tptr);
void readIRSensor();
void blink(int);
In Listing 9-6 the prototypes are required because the functions are defined after the loop code. So the prototypes
have to be listed.
Listing 9-6. Prototypes of the functions used by the interrupt system, and the task manger code.
void setup() {
Serial.begin(115200);
delay(2000);
// initialize the digital pin as an output.
// Pin PIN_LED1 has an LED connected on most Arduino boards:
pinMode(pinInt, INPUT);
//debugging LED, shows when pulse found
pinMode(PIN_LED1, OUTPUT);
digitalWrite(PIN_LED1, HIGH);
pinMode(SENSOR1_PIN, INPUT);
pinMode(EMITTER1_PIN, OUTPUT);
pinMode(EMITTER2_PIN, OUTPUT);
digitalWrite(EMITTER1_PIN, LOW);
digitalWrite(EMITTER2_PIN, LOW);
//blink before timers and interrups
blinkAll(6);
In Listing 9-7 the code uses the defined hardware and configure it corectly for the starting state of the project.
This includes a diagnostic called blinkAll. One you see all the LEDs blinking, the hardware is configured correctly and
is ready to detect the IR pulses.
Search WWH ::




Custom Search