source: rtos_arduino/trunk/arduino_lib/libraries/Servo/examples/Knob/Knob.ino@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 929 bytes
Line 
1/*
2 Controlling a servo position using a potentiometer (variable resistor)
3 by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
4
5 modified on 8 Nov 2013
6 by Scott Fitzgerald
7 http://arduino.cc/en/Tutorial/Knob
8*/
9
10#include <Servo.h>
11
12Servo myservo; // create servo object to control a servo
13
14int potpin = 0; // analog pin used to connect the potentiometer
15int val; // variable to read the value from the analog pin
16
17void setup()
18{
19 myservo.attach(9); // attaches the servo on pin 9 to the servo object
20}
21
22void loop()
23{
24 val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
25 val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
26 myservo.write(val); // sets the servo position according to the scaled value
27 delay(15); // waits for the servo to get there
28}
29
Note: See TracBrowser for help on using the repository browser.