i am using raspberry pi and arduino to create a project on iot. now when i make a gpio pin of pi high it also make a pin of arduino low....which is connected to the 4 channel relay board. now the problem is...i am using 3 of 4 relays. but cant on the 3 relays at a time...to on the third one i need to keep one of the 3 relays off...i am using external power supply for relay...
Your thoughts are hard to follow. Care to slow down, show more information in the post, give a clearer description of your circuit, and don't attach a short sketch. Read the post called How to use this forum - please read. It will help you get the best possible help from the crowd here.
Empty else blocks are useless. Exercise your right to delete them.
What this code is doing is setting f1 to state_gpio1 and writing the opposite state to pin 9.
It would require a lot less code to just do that.
f1 = state_gpio1;
digitalWrite(9, !f1);
Of course, it is not clear why you need two copies of the state of a pin, when both go out of scope at the end of loop(), so that snippet of your code could really be: