Last active
May 30, 2018 01:47
-
-
Save mik30s/30be6fc83356003ee696c12e7770e9cb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <SCServo.h> | |
SMSCL sm; | |
SMSCL smB; | |
long int wait = 5000; | |
int center = 4095/2; | |
int speed = 250; | |
char data[5]; | |
int start = 0; | |
uint16_t elbowAngle = 1100; | |
uint16_t shoulderAngle = 2350; | |
void setup() | |
{ | |
//serial 3 is servos 1 & 2, serial 2 is servos 3 - 7 | |
Serial2.begin(115200); | |
Serial3.begin(115200); | |
Serial.begin(9600); | |
sm.pSerial = &Serial2; | |
smB.pSerial = &Serial3; | |
sm.WritePos(3,1100, 0, speed); | |
smB.WritePos(2,2350, 0, speed); | |
delay(wait); | |
pinMode(32, INPUT); // shoulder servo -- left | |
pinMode(34, INPUT); // shoulder servo -- right | |
pinMode(36, INPUT); // elbow servo -- left | |
pinMode(38, INPUT); // elbow servo -- right | |
} | |
void loop() | |
{ | |
int voltA = analogRead(A0); | |
float voltB = voltA*0.05+.13; | |
if (voltB<11.5) { | |
exit(0); | |
} | |
if (digitalRead(32) == HIGH) { | |
shoulderAngle -= 100; | |
smB.WritePos(2,shoulderAngle, 0, speed); | |
} | |
if (digitalRead(34) == HIGH) { | |
shoulderAngle += 100; | |
smB.WritePos(2,shoulderAngle, 0, speed); | |
} if (digitalRead(36) == HIGH) { | |
elbowAngle -= 100; | |
sm.WritePos(3,elbowAngle, 0, speed); | |
} if (digitalRead(38) == HIGH) { | |
elbowAngle += 100; | |
sm.WritePos(3,elbowAngle, 0, speed); | |
} | |
Serial.println("elbow " + String(elbowAngle) | |
+ " shoulder " + String(shoulderAngle) | |
+ " size " + String(digitalRead(32))); | |
delay(speed); | |
} | |
This file contains hidden or 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
package com.example.michael.jrokisim; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.Button; | |
import ioio.lib.api.DigitalOutput; | |
import ioio.lib.api.Uart; | |
import ioio.lib.api.exception.ConnectionLostException; | |
import ioio.lib.util.BaseIOIOLooper; | |
import ioio.lib.util.android.IOIOActivity; | |
import static android.support.constraint.Constraints.TAG; | |
public class MainActivity extends IOIOActivity { | |
Button upBtn; | |
Button downBtn; | |
Button leftBtn; | |
Button rightBtn; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
upBtn = findViewById(R.id.upBtn); | |
downBtn = findViewById(R.id.downBtn); | |
leftBtn =findViewById(R.id.leftBtn); | |
rightBtn = findViewById(R.id.rightBtn); | |
} | |
class CustomLooper extends BaseIOIOLooper { | |
final int IOIO_RX_PIN = 35; | |
final int IOIO_TX_PIN = 34; | |
final int BAUD_RATE = 57600; | |
Uart uart; | |
DigitalOutput outPin1; | |
DigitalOutput outPin2; | |
DigitalOutput outPin3; | |
DigitalOutput outPin4; | |
@Override | |
protected void setup() throws ConnectionLostException { | |
Log.i("IOIOSetup", "called"); | |
// initialize IOIO board uart. | |
uart = ioio_.openUart( | |
IOIO_RX_PIN, | |
IOIO_TX_PIN, | |
BAUD_RATE, | |
Uart.Parity.NONE, | |
Uart.StopBits.ONE | |
); | |
upBtn.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view){ | |
try { | |
Log.i(TAG, "Pressing up."); | |
outPin1 = ioio_.openDigitalOutput(10, false); | |
outPin1.write(true); | |
Thread.sleep(100); | |
outPin1.write(false); | |
outPin1.close(); | |
} catch (Exception ex){ | |
Log.i("UpButton", ex.getMessage()); | |
} | |
} | |
}); | |
downBtn.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view){ | |
try { | |
Log.i(TAG, "Pressing down."); | |
outPin2 = ioio_.openDigitalOutput(11, false); | |
outPin2.write(true); | |
Thread.sleep(100); | |
outPin2.write(false); | |
outPin2.close(); | |
} catch (Exception ex){} | |
} | |
}); | |
leftBtn.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view){ | |
try { | |
Log.i(TAG, "Pressing left."); | |
outPin3 = ioio_.openDigitalOutput(12, false); | |
outPin3.write(true); | |
Thread.sleep(100); | |
outPin3.write(false); | |
outPin3.close(); | |
} catch (Exception ex){} | |
} | |
}); | |
rightBtn.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view){ | |
try { | |
Log.i(TAG, "Pressing right."); | |
outPin4 = ioio_.openDigitalOutput(13,false); | |
outPin4.write(true); | |
Thread.sleep(100); | |
outPin4.write(false); | |
outPin4.close(); | |
} catch (Exception ex){} | |
} | |
}); | |
} | |
@Override | |
public void loop() throws ConnectionLostException { | |
} | |
} | |
@Override | |
protected CustomLooper createIOIOLooper() { | |
Log.i("Main","looper called"); | |
//return IOIOLooper(buttonList) | |
return new CustomLooper(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment