Warning: Undefined array key "Plum_Code_Box_code_2_code" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 21
Warning: Undefined array key "Plum_Code_Box_code_2_type" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 22
Warning: Undefined array key "Plum_Code_Box_code_3_code" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 21
Warning: Undefined array key "Plum_Code_Box_code_3_type" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 22
Warning: Undefined array key "Plum_Code_Box_code_4_code" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 21
Warning: Undefined array key "Plum_Code_Box_code_4_type" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 22
Warning: Undefined array key "Plum_Code_Box_code_5_code" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 21
Warning: Undefined array key "Plum_Code_Box_code_5_type" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 22
Warning: Undefined array key "Plum_Code_Box_code_6_code" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 21
Warning: Undefined array key "Plum_Code_Box_code_6_type" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 22
Warning: Undefined array key "Plum_Code_Box_code_7_code" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 21
Warning: Undefined array key "Plum_Code_Box_code_7_type" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 22
Warning: Undefined array key "Plum_Code_Box_code_8_code" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 21
Warning: Undefined array key "Plum_Code_Box_code_8_type" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 22
Warning: Undefined array key "Plum_Code_Box_code_9_code" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 21
Warning: Undefined array key "Plum_Code_Box_code_9_type" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 22
Warning: Undefined array key "Plum_Code_Box_code_10_code" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 21
Warning: Undefined array key "Plum_Code_Box_code_10_type" in /var/www/codeshield.diyode.com/html/wp-content/plugins/plum-code-box/classes/Plum_Code_Box_Front.php on line 22
Rotates the servo motor to match the rotation on the potentiometer
Hardware used:
- Potentiometer
- Servo
Code Used:
- analogRead
- Library Import
- Servo Object
- Map function
#include <Servo.h>
/* Rotary encoder read example */
#define SERVO 5
#define POT 2
Servo myservo; // create servo object to control a servo
void setup()
{
myservo.attach(SERVO, 1000, 2000);
}
void loop()
{
myservo.write(map( analogRead(POT), 0, 1023, 0, 179));
// sets the servo position according to the scaled value
delay(10);
}