#if in compilation for use or arduino UNO and ATMEGA 328 or LILY with ATTINY 85

Hi,

I try to setup a code for the ATTINY 85 within the lily twinkle (https://www.sparkfun.com/products/11364), but as it has limitation on debug, I try to have the same code usable with my arduino uno ... so I do a :

#define TARGET_ARDUINO
//#define TARGET_LILY

#if defined TARGET_LILY
blablabla ...
#endif

#if defined TARGET_ARDUINO
blablable ....
#endif

but when I try to setup the interruptions, I got an error depending on the board I select in arduino IDE :

#if defined TARGET_ARDUINO
    GIMSK = 0b00100000;    // PCIE on
    PCMSK = 0b00000011;    // mask pour le pcint0 et pcint1
#endif
#if defined TARGET_ARDUINO
    PCICR = 0x02;          // Enable PCINT1 interrupt
    PCMSK1 = 0b00000111;
#endif

with the uno selected : test_pression_2.ino: In function 'void InitialiseInterrupt()': test_pression_2:120: error: 'GIMSK' was not declared in this scope test_pression_2:121: error: 'PCMSK' was not declared in this scope

with the attiny 85 : test_pression_2.ino: In function 'void InitialiseInterrupt()': test_pression_2:124: error: 'PCICR' was not declared in this scope test_pression_2:125: error: 'PCMSK1' was not declared in this scope

How can I deal with that ? Thanks for reading ;)

Stéphane

How can I deal with that ?

Post your snippets at http://snippets-r-us.com.

This may help answer why: http://arduino.land/FAQ/content/2/12/en/why-do-#ifdef-macro_s-stop-the-sketch-from-compiling.html

Also this may help your board selection. ( replace CHIPSET macro with whatever you like ).

// 168 and 328 Arduinos
#if defined(__AVR_ATmega168__) ||defined(__AVR_ATmega168P__) ||defined(__AVR_ATmega328P__)
    #define CHIPSET ATmega_168_168P_328P 

// Mega 1280 & 2560
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    #define CHIPSET ATmega_1280_2560 

// Sanguino
#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
    #define CHIPSET ATmega_644_644P_1284P 

#elif defined(__AVR_ATmega32U4__)

    // Teensy 2.0
    #ifdef CORE_TEENSY 
        #define CHIPSET ATmega_32U4_A 

    // Teensy
    #else
        #define CHIPSET ATmega_32U4_B 
    #endif

// Teensy++ 1.0 & 2.0
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
    #define CHIPSET AT90USB_646_1286 
#endif

PaulS:

How can I deal with that ?

Post your snippets at http://snippets-r-us.com.

done … sorry

pYro_65: This may help answer why: http://arduino.land/FAQ/content/2/12/en/why-do-#ifdef-macro_s-stop-the-sketch-from-compiling.html

no way to see that page, I got an Access denied and subscription is not working (never received the confirmation email and the login pass doesn't get through ..)

Also this may help your board selection. ( replace CHIPSET macro with whatever you like ).

// 168 and 328 Arduinos
#if defined(__AVR_ATmega168__) ||defined(__AVR_ATmega168P__) ||defined(__AVR_ATmega328P__)
    #define CHIPSET ATmega_168_168P_328P 

// Mega 1280 & 2560
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    #define CHIPSET ATmega_1280_2560 

// Sanguino
#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
    #define CHIPSET ATmega_644_644P_1284P 

#elif defined(__AVR_ATmega32U4__)

    // Teensy 2.0
    #ifdef CORE_TEENSY 
        #define CHIPSET ATmega_32U4_A 

    // Teensy
    #else
        #define CHIPSET ATmega_32U4_B 
    #endif

// Teensy++ 1.0 & 2.0
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
    #define CHIPSET AT90USB_646_1286 
#endif

Thanks, just need to add the lily with it's attiny85 ...

but still If the compiler or arduino ide check the interrupt register from the chipset selected within the IDE over the non selected #if part ... I am screwed ...

Stéphane

pfff ... I am such a dummy sometime ... my code was false :

#if defined TARGET_ARDUINO
    GIMSK = 0b00100000;    // PCIE on
    PCMSK = 0b00000011;    // mask pour le pcint0 et pcint1
#endif
#if defined TARGET_ARDUINO
    PCICR = 0x02;          // Enable PCINT1 interrupt
    PCMSK1 = 0b00000111;
#endif

if I use twice ARDUINO there is nothing for LILY ....

thanks for your help, sorry to have had you loose your time !!