The question is quite long, I've only included the part I need help with.
I have to model a 555 and produce this graph
I don't know how to alternate between the two formula.
I have written in English
What you are basically writing is a simulator, albeit a very simple one. So your main loop does nothing except increment time by some small amount and you keep track of the voltages at the key nodes and what state you are in. Then in each increment you calculate how much current is flowing and how much the node voltages change and then whether the state changes and you update all of those before moving on to the next time increment.