
JElectric
USA
Asked

I'm working on Blockly. Every time I finish running the program, I have to go back to the workspace and center the vertical servos. I want to run my program without having to go back and manually center it. The idea is after "else" the vertical servos would reset to 50( I have min and max at 1,100.) However, the Vertical Servos remains at 90. After that point the code doesn't work any more until I center it again. I'm not sure what 90 means. (Is it degrees?) Here is the code( this is my trial and error work. the d3, 90, 1 was me exploring the multi servos) :
if (Audio.waitForSpeech(2, "Hello")) {
Servo.SetPosition(d3, 90, 0);
} else if (Audio.waitForSpeech(2, "Goodbye")) {
Servo.SetSpeed(d3, 0, 0);
} else {
Servo.SetPosition(d3, 90, 1);
}
Related Hardware EZ-B IoTiny
Servo positions are somewhat arbitrary - for PWM hobby style servos using the default servo resolution of ARC, the number is "kind of" degrees. It's because not all servos are calibrated the same. Learn how a servo works here: https://synthiam.com/Support/Advanced-Fundamentals/servo-motor
As for your question, the answer is easier by moving the servos into the position before prompting for the wait for speech command. However, the code you have posted won't work. There is too much wrong with your code example to correct so I will demonstrate a completed example for you
. If you're using Blockly then do something like this...
Follow along with each block in order to see what the code is doing. That's what is great about Blockly when learning to program
It will generate this javascript code
Interesting. In EZ Script I'd have to end that with an EndIf. Not needed in Javascript?
JavaScript uses { and } to open and close chunks of code for if and repeats and stuff.
JavaScript is soooo much easier and faster
Thanks DJ. I'm starting to study JavaScript now. I'll be getting into it deeper over the next few weeks.
Thanks DJ Sures, your comment was super helpful.