Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ConnectionMockingPrototype
public abstract class Arduino {
private static int speed;
public static void setSpeed(int a) {
speed = a;
}
public static int getSpeed(){
return speed;
}
public static void printSpeed(){
System.out.println(speed);
}
public static void main(String[] args) throws InterruptedException {
USBConnection usb = new USBConnection();
Thread usbThread = new Thread(usb);
usbThread.start();
while(true){
printSpeed();
Thread.sleep(1000);
}
}
}
interface USB {
public void sendSpeed(int a);
}
class USBConnection implements USB , Runnable {
public void sendSpeed(int a){
Arduino.setSpeed(a);
}
@Override
public void run() {
int i = 0;
while(true){
sendSpeed(i);
i++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment