Lesson 8: Servo plus (+) Potentiometer. Let's rock it!!!

This is a practice lesson. Let's look back in Potentiometer lesson and find out how to make a connection with controlled rotation of Servo motor. Please, be kind and do not forget that Servo is OUTPUT device, and Potentiometer is INPUT device. Which means we use Potentiometer to control Servo, not wise versa.


Before you write or copy the code, please look to "float x" value and explain why do we divide value of A0 to 5.6? Explain what is "int(x)" operation do.

#include <Servo.h>
Servo s;

void setup()
{
  s.attach(3);
  pinMode(A0, INPUT);
}

float x;
void loop()
{
  x = analogRead(A0)/5.6;
  s.write(int(x));
}

Comments

Popular posts from this blog

Lesson 9: Piezo Buzzer

Lesson 10: Piezo Buzzer controlled with Potentiometer

Lesson 6: Potentionmeter & LED