I have done a lot of successful changes and got them working. My next change is a hard nut for me, and if anyone please could point me in direction to have success, I would be very greatful!
I\’ll describe the change like this:
- only one output to be on at the same time
- if GPIO2 is ON and GPIO4 is clicked, GPIO2 LED goes off and GPIO4 LED goes on – this I have solved in the main.cpp
- when clicking the switch for GPIO4, GPIO2 goes OFF and the State changes to OFF, the switch GPIO4 goes ON and State changes to ON
If I understand correctly the simplest way would be to check for a click (Doesn’t matter which one at this stage); If you get one, turn OFF all GPIO’s; Now check which one was clicked and turn that GPIO ON; Now wait for a click….
For something else to learn you could make the whole thing interrupt driven.
Thanks for the answer Steve!
This just what I have done, but my problem is to the the web-page updated correctly. In my browser, I have the switches. I have changed the original colors to red=off and green=on. Let’s say GPIO2 is on and green. Then I click on GPIO4, the switch change color to green, the LED connected to GPIO2 turns off and the LED at GPIO4 turns on, but the GPIO2-switch in the web page does not change to red and off state!
I’m afraid I’m going to have to leave that up to Sara/Rui. I don’t have that book so don’t know what they do for that. Good luck.
If you look further down the book, you will find what you are looking for.
They solve the problem for you.
I think you can figure out a solution for your problem if you continue following the eBook to the WebSocket projects.
You’ll learn how to send commands from the server to keep the client updated. So, you can send a command to change the state on the web interface.
Try following the WebSocket projects, and I’m sure you’ll figure it out.
I hope you’re enjoying the eBook.