How do I read what signal a digital out is giving?

I’m currently trying to code a function to make my life a bit easier while coding pneumatics, and I was just wondering whether there was a way to see what value is currently being outputted by a digital out.

This is what my function currently looks like. 1 is used to extend the piston, 0 is used to retract it, and I want -1 to toggle it, but I think I need to get the state of the output to do that.

def setPiston(piston, pos):
if pos == 1:
piston.set(True)
elif pos == 0:
piston.set(False)
elif pos == -1:
piston.set(not())

The vexcode python api does not have a way to get the value, so you need to do it yourself by storing the state in a variable

1 Like

Well, it does but not documented on the vex api site. I think the team did a global removal of the “value” functions as almost all device classes have it but in the majority of cases it’s not a useful function.

There should be an equivalent function for C++

value() will give the last set value.

>>> d=DigitalOut(brain.three_wire_port.a)
>>> d.value()
0
>>> d.set(1)
>>> d.value()
1
>>> 
3 Likes

Thanks, I don’t know why it didn’t cross my mind to use a variable