This learning hour follows on from the one about TDD in a finite state machine. This time we work on the same problem but instead of working on states and transitions, we focus on the lamp microcontroller logic.
Given this list of bit operations
i |= 0x04
i = 0b11111111;
i &= ~ (1 << 2);
i = 0x00
And these desired outcomes
Match them together
You could put these on sticky notes on a whiteboard for example. The idea is to remind people that they know how to do bit manipulation, which will be useful in this exercise.
We continue to work on a finite state machine simulating a Lift Button but this time the focus is on turning the lamp on and off. In the production code this will be achieved using some bit operations on a port. In the test we need to use a different port memory address, one that we control. This is a kind of fake.
Use the starting code for a Lift Button on the branch ‘starting_point_applied_tdd_2’. Demonstrate how to set up the fake port and write the first (failing) test for switching the lamp on.
Split up and work in pairs implementing the lamp functionality.
Ask people if they experienced any challenges or difficulties using the faked hardware. Also if they had any trouble with TDD. Ask people to think about whether TDD is a good approach for embedded development.