Helicopter

import processing.serial.*;

Serial myPort;
PImage bg;
PImage copter;
int xpos;
int fire;

void setup() {
  size(1200, 900);
  printArray(Serial.list());
  String portName = Serial.list()[5];
  myPort = new Serial(this, portName, 9600);
  myPort.write("A"); //send any old character
  myPort.readStringUntil('\n');  
  copter = loadImage("copter.png");
  bg = loadImage("sunny-sky.jpg");
}

void draw() {
  background(bg);
  image(copter, mouseX, mouseY);
}

void mouseDragged() {
  int  mpos = int(map(mouseX, 0, width, 0, 255)); 
  println(mpos);
  myPort.write(mpos);
}
#include <Servo.h>      // include the servo library

Servo servoMotor;       // creates an instance of the servo object to control a servo

void setup() {
  Serial.begin(9600);       // initialize serial communications
  servoMotor.attach(6);  // attaches the servo on pin 2 to the servo object
  pinMode(7,OUTPUT);
}

void loop()
{
  digitalWrite(7,LOW);
  if (Serial.available() > 0) {
    int input = Serial.read();  //this waits for byte from Processing
    int servoAngle = map(input,0, 255, 0, 179);
    // move the servo using the angle from the sensor:
    digitalWrite(7,HIGH);
    servoMotor.write(servoAngle);
  }
}

Screen Shot 2014-03-29 at 7.31.15 PM

 

Here be a video

Leave a Reply