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
Task 6 | Name: 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 |
To cover:
// Sweep
// by BARRAGAN
// additions by rhoadley
// servo red to 5v, black to ground, yellow to digital pin 9;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
int pos2 = random(180);
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
pos2 = random(18);
for(pos = 0; pos < pos2; pos += 1) // goes from 0 degrees to a random variation of 18 degrees - play with this!
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(random(20)); // wait a random time for the servo to reach the position
}
for(pos2; pos>=1; pos-=1) // goes fromthe previous position to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(random(20)); // waits a random time for the servo to reach the position
}
}
// Sweep
// by BARRAGAN
// additions by rhoadley
// servo red to 5v, black to ground, yellow to digital pin 9;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 45; pos += 1) // goes from 0 degrees to 45 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 5ms for the servo to reach the position
}
for(pos = 45; pos>=1; pos-=1) // goes from 45 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1); // waits 1ms for the servo to reach the position
}
}
// Sweep
// by BARRAGAN
// additions by rhoadley
// servo red to 5v, black to ground, yellow to digital pin 9;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}
void loop()
{
for(pos = 0; pos < 45; pos += 1) // goes from 0 degrees to 45 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
// Here we add a rhythm, choosing a delay if a random condition is met...
if (random(100) < 50)
{
Serial.println("200");
delay(200);
}
else
{
Serial.println("1");
delay(1);
}
for(pos = 45; pos>=1; pos-=1) // goes from 45 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1); // waits 15ms for the servo to reach the position
}
}
// Two Servos
// by BARRAGAN
// additions by rhoadley
// servo red to 5v, black to ground, yellow to digital pins 9 and 10;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo myservo2; // a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
int pos2 = 0;
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10);
Serial.begin(9600);
}
void loop()
{
for(pos = 0; pos < 45; pos += 1) // goes from 0 degrees to 45 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}
// Here we add a rhythm, choosing a delay if a random condition is met...
if (random(100) < 50)
{
Serial.println("200");
delay(200);
}
else
{
Serial.println("1");
delay(1);
}
// second servo
for(pos2 = 45; pos2>=1; pos2-=1) // goes from 45 degrees to 0 degrees
{
myservo2.write(pos2); // tell servo to go to position in variable 'pos'
delay(1); // waits 15ms for the servo to reach the position
}
for(pos2 = 0; pos2 < 180; pos2 += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo2.write(pos2); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos2 = 180; pos2>=1; pos2-=1) // goes from 180 degrees to 0 degrees
{
myservo2.write(pos2); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
/*
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
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
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // 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
}