Servos with circuit playground

circuitplayground
#1

Hey does code.org allow use of servos with their code for circuit playground. If so how would we do that. If not do you plan on expanding the options next year?

#2

We do, but it’s an advanced function that’s not available as a block. Depending on the size of the servo, you may need to use an addtional power supply or battery for the + and - servo connections. After connecting the data line to one of the pins on the Circuit Playground you can create a servo object using:

// servo connected to pin 2
var servo = new Servo(2);

You can then control the angle of the servo using servo.to(deg) or make it sweep back and forth using servo.sweep()

#3

@Josh where can I find some of these advanced feature documentation. We are done with Unit 6 for CSD and I have 2 more months to go. I would love to challenge my kids with some additional resources. Any ideas?

#4

I would also like the documentation for advanced features.

#6

Thanks for the advantage feature! I was scouring the internet for resources but couldn’t find any except for python. That one group I was going to have work in python since the ones that want to use the servo are my advance students and it would be a good challenge to switch languages.

#7

So we tried the following code

var degree;

var servo = new Servo(2);

onEvent(“Rotate”,“click”,function(){

degree = getNumber(“degree”);

servo.to(degree);

});

and used the following wire set up for are wires

orange to pin 2
brown to ground
red to 3v

#8

it is saying servo or Servo is not declared.

#9

What kind of servo are you using? Brand and model number if you have them.