rhoadley.net   music   research   software   blogs

aru    seminars    m&t    critski    focm1a    cmc    circuit bending    mic2b    sensor technology    comp 3    sonic art    major project
youtube    vimeo    facebook

 

 

Sensor Technology Tasks

Joining Code

Task 6 Ping - Joining Code Set: w4i Due: Monday 19th December 2016 Weighting: assessable/recommended (10%) Courses: stech
Prev Task: Servos Next Task: Investigating sensors - Make your own sensor - Make your own arduino
Task Summary All sTech tasks

Joining Code

How to join together two different pieces of code with the Arduino.

Examples

NB The below does not work particularly well, but does show the joining together of two pieces of code for the ping and the servo.

/* Ping))) Sensor

   This sketch reads a PING))) ultrasonic rangefinder and returns the
   distance to the closest object in range. To do this, it sends a pulse
   to the sensor to initiate a reading, then listens for a pulse
   to return.  The length of the returning pulse is proportional to
   the distance of the object from the sensor.

   The circuit:
    * +V connection of the PING))) attached to +5V
    * GND connection of the PING))) attached to ground
    * SIG connection of the PING))) attached to digital pin 7

   http://www.arduino.cc/en/Tutorial/Ping

   created 3 Nov 2008
   by David A. Mellis
   modified 30 Aug 2011
   by Tom Igoe

   This example code is in the public domain.

 */
 
 /*
 Controlling a servo position using a potentiometer (variable resistor)
 by Michal Rinott 

 modified on 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Knob

*/

#include 

Servo myservo;  // create servo object to control a servo

// this constant won't change.  It's the pin number
// of the sensor's output:
const int pingPin = 7;

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600); // don't really need this...
}

void loop() {
  ////////////////////////////
  // ping
  ////////////////////////////
  // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);


  ////////////////////////////
  // servo
  ////////////////////////////
  
  //val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(duration, 0, 5023, 10, 90); 
  
  
  if ( val > 10) {
    Serial.println(val);// scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  }
  
  delay(15);                           // waits for the servo to get there
}




to top of page The Task

  • Take two pieces of code and join them together so that both functions work.
  • Test and demonstrate this.

  • Clearly, I don't want you to submit your Arduinos. That means you need to submit some documentary evidence that you've completed your task. The most obvious way to do this is to submit some sort of video of your task working, as well as of the code running. If you can't do this, take photos.

  • Media files
    You must submit media files, such as video, audio or image files, but please ensure that video files are compressed to a reasonable degree. You should never submit dv files, but compress these to mp4. You should submit no file that is greater in size than 25MB/minute.

  • Added value
    By completing the details of the task you will achieve at least a pass mark. By imaginatively and creatively considering how you might implement the task originally you can add value to your submission, and this added value may increase your mark significantly. Even when making videos of short demonstration tasks try to consider musical and performance criteria.

  • Bearing this in mind, try to adapt and make more interesting your files. Simply repeating what we've already done will get minimal marks. So try each patch out in various ways. Even if it's just a blinking LED, try using patterns of colours and/or timings.

  • Compress (zip) your patches, demos, etc. into one file called your_student_number_"joining" (e.g. 0504335_joining.zip), include a readme with your name and student number and, if necessary, how to use or just open the patch.

  • Submit a copy of the files to the i-Centre on Monday 19th December 2016