Lecture
One Dimensional Arrays
Arrays are a type of data structure that allows for working with a group of values using a single identifier.
Lab
Servos
Servos rotate to a particular angular position and stay there until told to move to a new position.
There are both standard and continuous rotation servos. Unmodified ones have a fixed range due to a potentiometer in line with the drive shaft that is used for reporting the present position. Servos are controlled by sending a pulse of a certain length; this length determines the position it will rotate to. However, in a continuous rotation servo, there is no potentiometer and the servo rotates continuously, and the pulse length determines the speed instead.
Servos draw a significant amount of current, typically more than an Arduino can supply, so it is best to use a separate power supply.
Homework
Hardware
//Servo Potentiometer Control
#include <Servo.h>
const int SERVO=9; //Servo on Pin 9
const int pir=2; //pir on pin 2
Servo myServo;
int val = 0; //for storing the reading from the POT
void setup()
{
myServo.attach(SERVO);
myServo.write(90);
}
void loop()
{
val = digitalRead(pir); //Read pir
if(val==HIGH)
{
myServo.write(0);
delay(2000);
myServo.write(90);
}
delay(15); //waits for the servo
}
Comments
Post a Comment