Direct reading of a PORTD bit


in code below if use digitalread(6) can read logic level on portd pin6. if use led = portd & b11000000 statement not bit6 wiggling i'd expect.

what doing wrong?



void setup()
{
   serial.begin(9600);
   // prints title ending line break
   serial.println("setup starting");
 
   // data direction register of port d, don't touch the
   // lower 2 bits serial io
   ddrd = ddrd | b00111100 ;

}

void loop()
{
   int = 0 ;
   int iled = 0 ;
   while (true) {

       // iled = digitalread (6) ;
       iled = portd & b11000000 ;
       serial.println("iled =");
       serial.print(iled, oct);    

i take "wiggling" mean "toggling"  :) ie 1 becomes 0 , 0 becomes 1

you can , operation, because 1 , 1 = 1 , 0 in there, output 0, never flip 1 again.

you need xor operation eg

portd ^= bv(5);

will flip bit 5



Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > Direct reading of a PORTD bit


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums