Skip to content

Instantly share code, notes, and snippets.

@alexglow
Created April 25, 2014 16:15
Show Gist options
  • Save alexglow/11294937 to your computer and use it in GitHub Desktop.
Save alexglow/11294937 to your computer and use it in GitHub Desktop.
pinoccio servos
#include <SPI.h>
#include <Wire.h>
#include <Scout.h>
#include <GS.h>
#include <bitlash.h>
#include <lwm.h>
#include <js0n.h>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int v = 50;
void setup() {
myservo.attach(4); // attaches the servo on digital (pwm-capable) pin 4 to the servo object
addBitlashFunction("myservo.write", (bitlash_function)servoMove);
Scout.setup();
}
void loop() {
Scout.loop();
myservo.write(v);
}
numvar servoMove(void) {
myservo.write(getarg(1));
}
mashing up "Knob" and "Button" from Arduino examples
using: http://support.pinocc.io/hc/en-us/articles/200675735-Write-a-Custom-ScoutScript-Function
STARTING GOALS
Be able to enter a new "val" manually (0-100) and have the servo move to that position (0-180).
Then, have the servo position be 0 unless I'm pushing the button -- in which case, set it to 100.
Finally, see if I can pipe data to it from BRAINWAVES!!!! :)
Version 1:
#include <SPI.h>
#include <Wire.h>
#include <Scout.h>
#include <GS.h>
#include <bitlash.h>
#include <lwm.h>
#include <js0n.h>
#include <Servo.h> // add servo library
Servo myservo; // create servo object to control a servo
int val = 50; //
void setup() {
myservo.attach(5); // attaches the servo on pin 9 to the servo object
addBitlashFunction("myservo.write", (bitlash_function)servoMove);
Scout.setup();
}
void loop() {
Scout.loop();
myservo.write(val);
}
numvar servoMove(void) {
myservo.write(getarg(1));
}
put in startup function:
function startup { pin.makeinput("d2", INPUT_PULLUP); }
function event.button2
compile & upload: it's blinking its torch color very quickly. Then, when the upload is supposedly done, blinks slowly. Then stopped.
Try, in the serial monitor:
myservo.write("100")
...Ahhahahaahaha. When I open up the monitor, get:
dbT
next time: nothing.
Torch is blinking on/off at about 4Hz.
...Urk.
Pinoccio pins D2-D5 can act as PWM.
Servo takes a value of 0-180.
Changed to pin 4 and re-uploaded sketch.
Torch quickly blinks on/off, stopped after a reasonable interval (<30sec). Then it stops and the servo twitches.
Tried:
> print val
----------^
unexpected number
Scouts like one-letter variables. Changing to "v" and re-uploading.
> print v
0
> v = 60
> servoMove(60)
-----------^
unexpected number
> myservo.write(60)
> myservo.write(120)
>
No response from the servo.
Switching to the servo we got in our tryday kits and opening it up to the group.
It twitches when I plug it in :)
Hmm... I closed and reopened the serial monitor. The servo moved a fair bit in one direction. Serial monitor window shows nothing, though. :/ Even with autoscroll off!
Rebooting Scout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment