Loading...
Pages: [1]   Go Down
Author Topic: Need help with complex #define statement  (Read 70 times)
0 Members and 1 Guest are viewing this topic.
New York
Offline Offline
Full Member
***
Karma: 2
Posts: 231
xronosclock.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I need to modify definition of fWriteA to include all pins. How would I combine these 2 statements into one?
Code:
//Atmega644/1284 Version of fastWrite - for pins 0-15
#define fWriteA(_pin_, _state_) ( _pin_ < 8 ? (_state_ ? PORTB |= 1 << _pin_ : PORTB &= ~(1 << _pin_ )) : (_state_ ? PORTD |= 1 << (_pin_ -8) : PORTD &= ~(1 << (_pin_ -8) )))
//Atmega644/1284 Version of fastWrite - for pins 16-31 (Note: PORTA mapping reversed from others)
#define fWriteB(_pin_, _state_) ( _pin_ < 24 ? (_state_ ? PORTC |= 1 << (_pin_ -16) : PORTC &= ~(1 << (_pin_ -16))) : (_state_ ? PORTA |= 1 << (31- _pin_) : PORTA &= ~(1 << (31- _pin_) )))

Also would be great to know what syntax is this? smiley
Logged

Xronos Clock - A talking arduino based alarm clock is now available. Check out xronosclock.com for pictures, source code, schematics, and purchasing info smiley

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 30
Posts: 1170
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would reccomend using fatlib16's class: http://arduino.cc/forum/index.php/topic,150325.msg1128634.html#msg1128634

This should combine the two though.
Code:
#define fWrite( _pin_, _state_ ) ( ( _pin_ < 16 ) ? fWriteA( _pin_, _state_ ) : fWriteB( _pin_, _state_ ) )

It is using the C/C++ pre-processor syntax. Search macros and defines.
Logged


New York
Offline Offline
Full Member
***
Karma: 2
Posts: 231
xronosclock.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would reccomend using fatlib16's class: http://arduino.cc/forum/index.php/topic,150325.msg1128634.html#msg1128634

This should combine the two though.
Code:
#define fWrite( _pin_, _state_ ) ( ( _pin_ < 16 ) ? fWriteA( _pin_, _state_ ) : fWriteB( _pin_, _state_ ) )

It is using the C/C++ pre-processor syntax. Search macros and defines.
Wow, thanks!  I haven't thought of that!  So that translates to if (_pin_ < 16) fWriteA; else fWriteB 
Neat!
I'll check out fatlib16's class too!
Logged

Xronos Clock - A talking arduino based alarm clock is now available. Check out xronosclock.com for pictures, source code, schematics, and purchasing info smiley

Pages: [1]   Go Up
Print
 
Jump to: