-
Notifications
You must be signed in to change notification settings - Fork 67
/
TrinketProCode
49 lines (43 loc) · 1.81 KB
/
TrinketProCode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
SimplePulse (simple way)
Using the Hackaday Trinket Pro.
Creates two contiguous pulses one after the other, then sleeps till the next time.
This example code is in the public domain. Inspired from Blink.
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 60; // variable to store the servo position
void setup()
{
myservo.attach(5); // attaches the servo on pin 5 to the servo object
DDRB = B11111111; // set PORTB (digital 13~8) to outputs
}
void loop()
{
for(pos = 60; pos < 120; pos += 1) // goes from 60 degrees to 120 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(40); // waits 12ms for the servo to reach the position
PORTB = B00001000; // Pin 11
delayMicroseconds(pos); // microsecondes
PORTB = B00010000; // Pin 12 = pulse positif
__asm__("nop\n\t");
PORTB = B00100000; // Pin 13 = pulse negatif
delayMicroseconds(1);
//__asm__("nop\n\t""nop\n\t");
PORTB = B00000000;
delayMicroseconds(1000); // microsecondes
PORTB = B00001000; // Pin 11
delayMicroseconds(pos); // microsecondes
PORTB = B00010000; // Pin 12 = pulse positif
__asm__("nop\n\t");
PORTB = B00100000; // Pin 13 = pulse negatif
delayMicroseconds(1);
//__asm__("nop\n\t""nop\n\t");
PORTB = B00000000;
delay(10);
}
myservo.write(60); // tell servo to go to position in variable 'pos'
delay(1000); // waits 1000ms for the servo to reach the position
}