cancel
Showing results for 
Search instead for 
Did you mean: 

How to inverse gpio read pin?

parth kothiya
Senior

i am reading GPIO PIN using

bool X[n];

X[1] = (GPIOA->IDR >> 1)&1;

X[2] = (GPIOA->IDR >> 4)&1;

now i want to inverse reading bit because of pull up i am getting inverse output in X[n].

example

X[1] = (GPIOA->IDR >> 1)&1; gives 1 but i want 0

How can i do this ?

X[1] != (GPIOA->IDR >> 1)&1; gives warning

value computed but not used [-Wunused-value}

1 ACCEPTED SOLUTION

Accepted Solutions

X[1] = !((GPIOA->IDR >> 1)&1);

X[1] = (~GPIOA->IDR >> 1)&1 // Tilde

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

1 REPLY 1

X[1] = !((GPIOA->IDR >> 1)&1);

X[1] = (~GPIOA->IDR >> 1)&1 // Tilde

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..