Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
void loop(){ boolean a = digitalRead(0); digitalWrite(2, a); boolean b = digitalRead(3); digitalWrite(1, b);}
if (PIND & 0b10000000)
if(bit_is_cleaar(PIND,0)) //if pin D0 is grounded...{//pin D0 is grounded!}
I use bit_is_clear and bit_is_set.clear returns true if the pin is grounded, set returns true if the pin is high.Code: [Select]if(bit_is_cleaar(PIND,0)) //if pin D0 is grounded...{//pin D0 is grounded!}
if (PIND&0){ PORTD&2; else{ PORTD||2; }
if (PIND&0){ PORTD|=B00000100; else{ PORTD|=B00000000; }
I am still trying to find the right bitwise operator to clear only one bit (pin) in the port and leave the rest, i will get back to you when i find it.
#define BIT_SET(REG, bit) ( REG |= (1UL << (bit) ) )#define BIT_CLR(REG, bit) ( REG &= ~(1UL << (bit) ) )#define BIT_TST(REG, bit, val) ( ( (REG & (1UL << (bit) ) ) == ( (val) << (bit) ) ) )
if ( BIT_TST( PIND, 0, 1 ) ) { BIT_SET( PORTD, 2); } else { BIT_CLR( PORTD, 2); }
Another way is to define these macros:Code: [Select]#define BIT_SET(REG, bit) ( REG |= (1UL << (bit) ) )#define BIT_CLR(REG, bit) ( REG &= ~(1UL << (bit) ) )#define BIT_TST(REG, bit, val) ( ( (REG & (1UL << (bit) ) ) == ( (val) << (bit) ) ) )And then write your code like this:Code: [Select] if ( BIT_TST( PIND, 0, 1 ) ) { BIT_SET( PORTD, 2); } else { BIT_CLR( PORTD, 2); }
Gearmotion, could you post what little macros you had? Just recently I had to manipulate some ports and it took me quite a bit to dig through my old code and relearn what I used