Bravia
Ireland
Asked
— Edited
trying to read four digital inputs need a little help please eg there are five possible options
all are "1" or each is at "0" in turn. (d1,d2,d3,d4)
say d1 "0" moves servo d7 to position 50,once it changes to "1" move servo back to position 40
d2 "0" moves servo d7 to position 30, once it changes to "1" move servo to position 40
d3 "0" moves servo d8 to position 50 , once it changes to "1" move servo back to position 40
d4 "0" moves servo d8 to position 30 , once it changes to "1" move servo back to position 40
finally if all inputs are "1" both d7 and d8 are at position 40
hope I have explained my request clearly
Use the GetDigital() command to read the digital port, i.e. GetDigital(D1) Use Ifs and ElseIfs to check the status and perform the action depending on the result. Use an If with the And operator to check for all 4. I would do it with an If statement inside another If statement...
Each of the single port checks would be like this;
Do the same for the other 3.
The "tricky" part comes by needing to know about all 4 being 1. Although not too tricky...
Something like that.
And loop it with the :loop label at the start and a Goto(loop) at the end
I guess the ElseIf(GetDigital(D1)=1) could be just an Else to save typing, it's going to be one or the other so if it isn't 0 then you don't need it to check if it's a 1.
So;
Thanks for your help Rich
Code: :start If(GetDigital(D1)=0) Servo(D7,50) ElseIf(GetDigital(D1)=1) Servo(D7,40) EndIf If(GetDigital(D2)=0) Servo(D7,30) ElseIf(GetDigital(D2)=1) Servo(D7,40) EndIf If(GetDigital(D3)=0) Servo(D8,50) ElseIf(GetDigital(D3)=1) Servo(D8,40) EndIf If(GetDigital(D4)=0) Servo(D8,30) ElseIf(GetDigital(D4)=1) Servo(D8,40) EndIf goto(start)
I am attempting to read the four digital inputs ,two move servo d7 ,two move servo d8
So as you can see I once it finds a low it moves a particular servo, ( and continues to read all ports) so I need to stop script until that input state changes Thanks:Pat
I only have a few minutes so this will be short.
Take a look at the Digital_Wait (digitalPort, on/off/true/false) command, but it will pause until the specified port changes, I don't know if it can use multiple ports in the one statement (I've never tried).
You could use variables and check for a change, such as;
The ... parts need the rest of the code, I'm too lazy to write it
That will typically check for a change in status on the digital port and if it has changed it'll run the code. An IF with ORs can do that in one IF statement;
Appreciate your time Rich Will try your suggestion later Pat