Hello I want to use this code for Arduino Due. I converted some parts for due but ı can't find" set pins output" for due( like DDR and PCMSK). Can you help me? How can i write for due? Thanks.
bool triggered = false;
bool Trig_in_state = false;
void setup() {
DDRD |= B00111000; // Sets D3, D4, D5 outputs
DDRB |= B00000100; // Sets D10 as output
PCICR |= (1 << PCIE0); //enable PCMSK0 scan
PCMSK0 |= (1 << PCINT0); //Set pin D8 (trigger pin) set to fire interrupt on state change.
PCMSK0 |= (1 << PCINT1); //Set pin D9 (echo in) set to fire an interrupt on state change.
}
void loop() {
if(triggered)//Burst code starts...
{
delayMicroseconds(150);
/*We have seen a delay of 250uS when we've made tests
between the 10us trig pulse and the 8 cycles burt. For some reasons, if I put 250us delay,
I get 350 on the oscilloscope. That's why I've made a 150us delay.
*/
PORTD &= B11011111; //D5 LOW //Activate the MAX323 PNP transistor for supply
PORTD |= B00001000; //D3 HIGH
PORTD &= B11101111; //D4 LOW
delayMicroseconds(12);//12us so around 40KHz. Freq = 1/2*12us
PORTD &= B11110111; //D3 LOW
PORTD |= B00010000; //D4 HIGH
delayMicroseconds(12);
PORTD &= B11000111; //D3, D4, D5 LOW //We have finished the burst. We set everything to low
PORTB |= B00000100;
triggered = false; //Reset the triggered value
}
}
ISR(PCINT0_vect){
//If digital D8 is high -> trigger was activated
if(PINB & B00000001){
Trig_in_state = true; //Set the Trig_in_state to true since we've detected the trigger pulse
}
//If trigger pin is low, the 10us pulse is over and we start the code
else if(Trig_in_state)
{
triggered = true; //Set trigered state to true
Trig_in_state = false; //Reset the D8 pin state
}
PORTB &= 11111011; //D10, echo pin out to LOW
}