confirmed INO good with 90 degree rotation back and forth, PY port syntax started
This commit is contained in:
parent
644432fd84
commit
3ab3f971f6
4 changed files with 87 additions and 0 deletions
BIN
Laser_Dog_Goggles/.Laser_Dog_Goggles.ino.swp
Normal file
BIN
Laser_Dog_Goggles/.Laser_Dog_Goggles.ino.swp
Normal file
Binary file not shown.
64
Laser_Dog_Goggles/Laser_Dog_Goggles.ino
Normal file
64
Laser_Dog_Goggles/Laser_Dog_Goggles.ino
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*******************************************************************
|
||||||
|
SoftServo sketch for Adafruit Trinket. Increments values to change position on the servo
|
||||||
|
(0 = zero degrees, full = 180 degrees)
|
||||||
|
|
||||||
|
Required library is the Adafruit_SoftServo library
|
||||||
|
available at https://github.com/adafruit/Adafruit_SoftServo
|
||||||
|
The standard Arduino IDE servo library will not work with 8 bit
|
||||||
|
AVR microcontrollers like Trinket and Gemma due to differences
|
||||||
|
in available timer hardware and programming. We simply refresh
|
||||||
|
by piggy-backing on the timer0 millis() counter
|
||||||
|
|
||||||
|
Required hardware includes an Adafruit Trinket microcontroller
|
||||||
|
a servo motor, and a potentiometer (nominally 1Kohm to 100Kohm
|
||||||
|
|
||||||
|
As written, this is specifically for the Trinket although it should
|
||||||
|
be Gemma or other boards (Arduino Uno, etc.) with proper pin mappings
|
||||||
|
|
||||||
|
Trinket: USB+ Gnd Pin #0
|
||||||
|
Connection: Servo+ - Servo1
|
||||||
|
|
||||||
|
*******************************************************************/
|
||||||
|
|
||||||
|
#include <Adafruit_SoftServo.h> // SoftwareServo (works on non PWM pins)
|
||||||
|
|
||||||
|
#define SERVO1PIN 0 // Servo control line (orange) on Trinket Pin #0
|
||||||
|
int moveAmount = 1; // change this value to change speed of servo
|
||||||
|
int servoPos = 0; // variable for servo position
|
||||||
|
|
||||||
|
Adafruit_SoftServo myServo1; //create servo object
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Set up the interrupt that will refresh the servo for us automagically
|
||||||
|
OCR0A = 0xAF; // any number is OK
|
||||||
|
TIMSK |= _BV(OCIE0A); // Turn on the compare interrupt (below!)
|
||||||
|
|
||||||
|
myServo1.attach(SERVO1PIN); // Attach the servo to pin 0 on Trinket
|
||||||
|
myServo1.write(90); // Tell servo to go to position per quirk
|
||||||
|
delay(15); // Wait 15ms for the servo to reach the position
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
myServo1.write(servoPos); // tell servo to go to position
|
||||||
|
servoPos = servoPos + moveAmount; // increment servo position (value between 0 and 180)
|
||||||
|
if (servoPos == 0 || servoPos == 180){
|
||||||
|
moveAmount = -moveAmount; //reverse incrementer at bounds
|
||||||
|
}
|
||||||
|
delay(15); // waits 15ms for the servo to reach the position
|
||||||
|
}
|
||||||
|
|
||||||
|
// We'll take advantage of the built in millis() timer that goes off
|
||||||
|
// to keep track of time, and refresh the servo every 20 milliseconds
|
||||||
|
// The SIGNAL(TIMER0_COMPA_vect) function is the interrupt that will be
|
||||||
|
// Called by the microcontroller every 2 milliseconds
|
||||||
|
volatile uint8_t counter = 0;
|
||||||
|
SIGNAL(TIMER0_COMPA_vect) {
|
||||||
|
// this gets called every 2 milliseconds
|
||||||
|
counter += 2;
|
||||||
|
// every 20 milliseconds, refresh the servos!
|
||||||
|
if (counter >= 20) {
|
||||||
|
counter = 0;
|
||||||
|
myServo1.refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
19
Laser_Dog_Goggles/Laser_Dog_Goggles.py
Normal file
19
Laser_Dog_Goggles/Laser_Dog_Goggles.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Trinket Gemma Servo Control
|
||||||
|
# for Adafruit M0 boards
|
||||||
|
|
||||||
|
import board
|
||||||
|
import pulseio
|
||||||
|
from adafruit_motor import servo
|
||||||
|
|
||||||
|
# servo pin for the M0 boards:
|
||||||
|
pwm = pulseio.PWMOut(board.A2, duty_cycle=2 ** 15, frequency=50)
|
||||||
|
my_servo = servo.Servo(pwm)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
for angle in range(0,100,5)
|
||||||
|
print(angle)
|
||||||
|
my_servo.angle = angle
|
||||||
|
|
||||||
|
for angle in range(100,0,-5)
|
||||||
|
print(angle)
|
||||||
|
my_servo.angle = angle
|
||||||
4
Laser_Dog_Goggles/README.md
Normal file
4
Laser_Dog_Goggles/README.md
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Laser_Dog_Goggles
|
||||||
|
|
||||||
|
Code to accompany this Adafruit tutorial:
|
||||||
|
https://learn.adafruit.com/laser-dog-goggles
|
||||||
Loading…
Reference in a new issue