Use the force sensor attached to the fly to fly away. More force leads to an increase in speed.
Arduino code
/* Ardunio Code to get input from analog sensors */
const int input1 = A0; // sensor to control red color
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.flush();
Serial.write(analogRead(input1));
}
Processing code
import processing.serial.*;
Serial port;
int pressValue = 0;
float elevation = 0;
PImage imgChoppy, imgBackground; // Declare variable "imgChoppy" of type PImage
float height = 200;
float widthBG = 0;
void setup() {
size(600, 600);
println(Serial.list());
port = new Serial(this, Serial.list()[1], 9600);
imgBackground = loadImage("background2.jpg"); // Load the image into the program
imgChoppy = loadImage("vlieg.png"); // Load the image into the program
//noLoop(); // Makes draw() only run once
}
void draw() {
noStroke();
background(0);
// Displays the image at its actual size at point (0,0)
image(imgBackground, 0, 0);
if(widthBG == -1000){
widthBG = 0;
}
else{
widthBG = widthBG - 5;
image(imgBackground, widthBG, 0);
}
while (port.available() > 0) {
pressValue = port.read();
println("press "+pressValue);
if(pressValue >= 2 && pressValue <= 120){
elevation = .2;
println(elevation);
}
else if(pressValue >= 121 && pressValue <= 160){
elevation = .5;
println(elevation);
}
else if(pressValue >= 161 && pressValue <= 300){
elevation = .9;
println(elevation);
}
else if(pressValue == 0){
elevation = .6;
}
if(elevation == .2 || elevation == .5 || elevation == .9) {
//elevation = pressValue / 120;
height = height - elevation;
if(height <= 0){
image(imgChoppy, 200, 600);
height = 600;
}
else{
image(imgChoppy, 200, height);
}
}
else {
if(height >= 600){
image(imgChoppy, 200, 0);
height = 0;
}
else{
height = height + .2;
image(imgChoppy, 200, height);
}
}
}
}