-
-
Save keionbis/f6b9415aff74f952c2f361c27276f454 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//If your DyIO is using a lower voltage power source, you need to disable the brownout detect | |
def myDyIO =DeviceManager.getSpecificDevice( "dyio",{ | |
//If the device does not exist, prompt for the connection | |
SerialConnection s =new SerialConnection("/dev/ttyACM0"); | |
DyIO m = new DyIO(s) | |
return m | |
}) | |
myDyIO.setServoPowerSafeMode(false); | |
ArrayList<ServoChannel> chans = new ArrayList<ServoChannel>(); | |
//Loop 10 times setting the position of the servo | |
//the time the loop waits will be the time it takes for the servo to arrive | |
int[] pwmArray = [2,3,4,5,6,7,8,9,10,29,30, 23, 22, 21, 20,14, 38, 37, 36, 35]; | |
float time = 0.1; | |
for(int i=0;i<pwmArray.length;i++){ | |
chans.add(new ServoChannel(myDyIO.getChannel(pwmArray[i]))); | |
} | |
while(!Thread.interrupted()){ | |
for(ServoChannel srv:chans){ | |
//System.out.println("Moving with time"); | |
for(int i = 0; i < 2&&!Thread.interrupted(); i++) { | |
// Set the value high every other time, exit if unsuccessful | |
int pos; | |
if(i%2==0){ | |
pos=255; | |
}else{ | |
pos=0; | |
} | |
//This will move the servo from the position it is currentlly in | |
srv.SetPosition(pos, time); | |
System.out.println("Setting to "+pos+" in "+time+" seconds"); | |
// pause between cycles so that the changes are visible | |
Thread.sleep((long) (time*1000)); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment