source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/examples/10.StarterKit_BasicKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

File size: 1.3 KB
Line 
1/*
2  Arduino Starter Kit example
3 Project 5  - Servo Mood Indicator
4
5 This sketch is written to accompany Project 5 in the
6 Arduino Starter Kit
7
8 Parts required:
9 servo motor
10 10 kilohm potentiometer
11 2 100 uF electrolytic capacitors
12
13 Created 13 September 2012
14 by Scott Fitzgerald
15
16 http://www.arduino.cc/starterKit
17
18 This example code is part of the public domain
19 */
20
21// include the servo library
22#include <Servo.h>
23
24Servo myServo;  // create a servo object
25
26int const potPin = A0; // analog pin used to connect the potentiometer
27int potVal;  // variable to read the value from the analog pin
28int angle;   // variable to hold the angle for the servo motor
29
30void setup() {
31  myServo.attach(9); // attaches the servo on pin 9 to the servo object
32  Serial.begin(9600); // open a serial connection to your computer
33}
34
35void loop() {
36  potVal = analogRead(potPin); // read the value of the potentiometer
37  // print out the value to the serial monitor
38  Serial.print("potVal: ");
39  Serial.print(potVal);
40
41  // scale the numbers from the pot
42  angle = map(potVal, 0, 1023, 0, 179);
43
44  // print out the angle for the servo motor
45  Serial.print(", angle: ");
46  Serial.println(angle);
47
48  // set the servo position
49  myServo.write(angle);
50
51  // wait for the servo to get there
52  delay(15);
53}
54
55
Note: See TracBrowser for help on using the repository browser.