4bdi3l
Newbie
Hi everyone, I am new in this forum, nice to meet you. I'd like to ask if this code of arduino it's right. I don't want to use the default functions in arduino as digitalWrite, delay...etc. instead I'd like to use the micros(); function and the port register control.
This is the code that I want to change:
and I believe that it should be something like that:
Also this code:
And I believe that it should be:
I'm new programing in this way. I'd really appreciate if someone can corroborate if it is right,
Thanks and regards.
This is the code that I want to change:
C:
delayMicroseconds(7000-valor);
digitalWrite(3,HIGH);
delayMicroseconds(10);
digitalWrite(3, LOW);
and I believe that it should be something like that:
C:
unsigned long currentMillis = micros();
if (currentMillis - previousMillis >= 7000UL -valor) {
PORTD |= B00001000;
unsigned long currentMillis2 = micros();
if (currentMillis2 - previousMillis2 >= 10UL) {
PORTD &= !B00001000;
previousMillis2 = currentMillis2;
}
previousMillis = currentMillis;
}
Also this code:
C:
pinMode(2,INPUT)
if(!digitalRead(2)){
//
}
And I believe that it should be:
C:
DDRD &= B11111011;
if (!(PIND >> 2 & B00000100 >> 2)){
//
}
I'm new programing in this way. I'd really appreciate if someone can corroborate if it is right,
Thanks and regards.