Author Topic: What compiler directive is present? (e.g. __AVR_ATmega32U4__, __AVR_ATtinyX5__)  (Read 5587 times)

bjmckenz

  • Newbie
  • *
  • Posts: 2
I'm looking to use the NewPing library (provides nice support for ultrasonic sensors). It has specific directives for the Mega and "normal" Arduino as follows:

void NewPing::timer_stop() { // Disable timer interrupt.
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
    TIMSK4 = 0;
#else
    TIMSK2 &= ~(1<<OCIE2A);
#endif


I wish to add something like:

#elseif defined(__AVR_ATtinyX5__)
    TIMSK &= ~(1<<OCIE0A);

but I haven't figured out what #define is present for the Digistamp. What is it?

I've tried both __AVR_ATtinyX5__ and __AVR_ATtiny85__ but neither is defined.

(I'm OK with figuring out the right timer flags and registers, and I've been RTing the FM about those. This is more about Arduino)

Thanks.

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
if defined(__AVR_ATtiny85__) is used by TinyWire which is used for all I2C with the Digispark so that should definitely work

bjmckenz

  • Newbie
  • *
  • Posts: 2
Thanks very much. You are correct. PEBKAC -- I had this:

#elseif defined(__AVR_ATtiny85__)
    OCR0A = min((frequency>>2) - 1, 255); // Every count is 4uS, so divide by 4 (bitwise shift right 2) subtract one, then make sure we don't go over 255 limit.
    TIMSK |= (1<<OCIE0A);                // Enable Timer0 interrupt.

instead of this:

#elif defined(__AVR_ATtiny85__)
    OCR0A = min((frequency>>2) - 1, 255); // Every count is 4uS, so divide by 4 (bitwise shift right 2) subtract one, then make sure we don't go over 255 limit.
    TIMSK |= (1<<OCIE0A);                // Enable Timer0 interrupt.


Interestingly, this is the error that it gives (when I used "#elseif"):
C:\Arduino Digispark\libraries\NewPing\NewPing.cpp: In static member function 'static void NewPing::timer_us(unsigned int, void (*)())':
C:\Arduino Digispark\libraries\NewPing\NewPing.cpp:154: error: 'OCR2A' was not declared in this scope
C:\Arduino Digispark\libraries\NewPing\NewPing.cpp:155: error: 'TIMSK2' was not declared in this scope
C:\Arduino Digispark\libraries\NewPing\NewPing.cpp:155: error: 'OCIE2A' was not declared in this scope

somehow the preprocessor is not handling/reporting the error the way I expected.

Thanks much!