@name Battery
@inputs PlugIn PlugOut
@outputs Power SocketIn SocketOut 
@trigger 

interval(500)
if(first())
{
    Power = 0
    SocketIn = 1
}

if(PlugIn & Power < 99) {timer("charge",1000)}
if(clk("charge")) {Power++}

if(Power > 0) {SocketOut = 1} else {SocketOut = 0}
if(PlugOut & Power > 1) {timer("dec",5000)}
if(clk("dec")) {Power--}
