Skip to content

Commit d1d6686

Browse files
committed
- initial commit
0 parents  commit d1d6686

File tree

370 files changed

+47147
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

370 files changed

+47147
-0
lines changed

AFMotor/AFMotor.cpp

+697
Large diffs are not rendered by default.

AFMotor/AFMotor.h

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Adafruit Motor shield library
2+
// copyright Adafruit Industries LLC, 2009
3+
// this code is public domain, enjoy!
4+
5+
#ifndef _AFMotor_h_
6+
#define _AFMotor_h_
7+
8+
#include <inttypes.h>
9+
#include <avr/io.h>
10+
11+
// comment out this line to remove microstepping support
12+
// for smaller library. Be sure to delete the old library objects!
13+
#define MICROSTEPPING 1
14+
15+
#ifdef MICROSTEPPING
16+
#define MICROSTEP 8
17+
#endif
18+
19+
#define MOTOR12_64KHZ _BV(CS20) // no prescale
20+
#define MOTOR12_8KHZ _BV(CS21) // divide by 8
21+
#define MOTOR12_2KHZ _BV(CS21) | _BV(CS20) // divide by 32
22+
#define MOTOR12_1KHZ _BV(CS22) // divide by 64
23+
24+
#define MOTOR34_64KHZ _BV(CS00) // no prescale
25+
#define MOTOR34_8KHZ _BV(CS01) // divide by 8
26+
#define MOTOR34_1KHZ _BV(CS01) | _BV(CS00) // divide by 64
27+
28+
#define MOTOR1_A 2
29+
#define MOTOR1_B 3
30+
#define MOTOR2_A 1
31+
#define MOTOR2_B 4
32+
#define MOTOR4_A 0
33+
#define MOTOR4_B 6
34+
#define MOTOR3_A 5
35+
#define MOTOR3_B 7
36+
37+
#define FORWARD 1
38+
#define BACKWARD 2
39+
#define BRAKE 3
40+
#define RELEASE 4
41+
42+
#define SINGLE 1
43+
#define DOUBLE 2
44+
#define INTERLEAVE 3
45+
46+
47+
/*
48+
#define LATCH 4
49+
#define LATCH_DDR DDRB
50+
#define LATCH_PORT PORTB
51+
52+
#define CLK_PORT PORTD
53+
#define CLK_DDR DDRD
54+
#define CLK 4
55+
56+
#define ENABLE_PORT PORTD
57+
#define ENABLE_DDR DDRD
58+
#define ENABLE 7
59+
60+
#define SER 0
61+
#define SER_DDR DDRB
62+
#define SER_PORT PORTB
63+
*/
64+
65+
// Arduino pin names
66+
#define MOTORLATCH 12
67+
#define MOTORCLK 4
68+
#define MOTORENABLE 7
69+
#define MOTORDATA 8
70+
71+
class AFMotorController
72+
{
73+
public:
74+
AFMotorController(void);
75+
void enable(void);
76+
friend class AF_DCMotor;
77+
void latch_tx(void);
78+
};
79+
80+
class AF_DCMotor
81+
{
82+
public:
83+
AF_DCMotor(uint8_t motornum, uint8_t freq = MOTOR34_8KHZ);
84+
void run(uint8_t);
85+
void setSpeed(uint8_t);
86+
87+
private:
88+
uint8_t motornum, pwmfreq;
89+
};
90+
91+
class AF_Stepper {
92+
public:
93+
AF_Stepper(uint16_t, uint8_t);
94+
void step(uint16_t steps, uint8_t dir, uint8_t style = SINGLE);
95+
void setSpeed(uint16_t);
96+
uint8_t onestep(uint8_t dir, uint8_t style);
97+
void release(void);
98+
uint16_t revsteps; // # steps per revolution
99+
uint8_t steppernum;
100+
uint32_t usperstep, steppingcounter;
101+
private:
102+
};
103+
104+
uint8_t getlatchstate(void);
105+
106+
#endif
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Adafruit Motor shield library
2+
// copyright Adafruit Industries LLC, 2009
3+
// this code is public domain, enjoy!
4+
5+
#include <AFMotor.h>
6+
#include <ServoTimer1.h>
7+
8+
// DC motor on M2
9+
AF_DCMotor motor(2);
10+
// DC hobby servo
11+
ServoTimer1 servo1;
12+
// Stepper motor on M3+M4 48 steps per revolution
13+
AF_Stepper stepper(48, 2);
14+
15+
void setup() {
16+
Serial.begin(9600); // set up Serial library at 9600 bps
17+
Serial.println("Motor party!");
18+
19+
// turn on servo
20+
servo1.attach(9);
21+
22+
// turn on motor #2
23+
motor.setSpeed(200);
24+
motor.run(RELEASE);
25+
}
26+
27+
int i;
28+
29+
// Test the DC motor, stepper and servo ALL AT ONCE!
30+
void loop() {
31+
motor.run(FORWARD);
32+
for (i=0; i<255; i++) {
33+
servo1.write(i);
34+
motor.setSpeed(i);
35+
stepper.step(1, FORWARD, INTERLEAVE);
36+
delay(3);
37+
}
38+
39+
for (i=255; i!=0; i--) {
40+
servo1.write(i-255);
41+
motor.setSpeed(i);
42+
stepper.step(1, BACKWARD, INTERLEAVE);
43+
delay(3);
44+
}
45+
46+
motor.run(BACKWARD);
47+
for (i=0; i<255; i++) {
48+
servo1.write(i);
49+
motor.setSpeed(i);
50+
delay(3);
51+
stepper.step(1, FORWARD, DOUBLE);
52+
}
53+
54+
for (i=255; i!=0; i--) {
55+
servo1.write(i-255);
56+
motor.setSpeed(i);
57+
stepper.step(1, BACKWARD, DOUBLE);
58+
delay(3);
59+
}
60+
}
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Adafruit Motor shield library
2+
// copyright Adafruit Industries LLC, 2009
3+
// this code is public domain, enjoy!
4+
5+
#include <AFMotor.h>
6+
7+
AF_DCMotor motor(4);
8+
9+
void setup() {
10+
Serial.begin(9600); // set up Serial library at 9600 bps
11+
Serial.println("Motor test!");
12+
13+
// turn on motor
14+
motor.setSpeed(200);
15+
16+
motor.run(RELEASE);
17+
}
18+
19+
void loop() {
20+
uint8_t i;
21+
22+
Serial.print("tick");
23+
24+
motor.run(FORWARD);
25+
for (i=0; i<255; i++) {
26+
motor.setSpeed(i);
27+
delay(10);
28+
}
29+
30+
for (i=255; i!=0; i--) {
31+
motor.setSpeed(i);
32+
delay(10);
33+
}
34+
35+
Serial.print("tock");
36+
37+
motor.run(BACKWARD);
38+
for (i=0; i<255; i++) {
39+
motor.setSpeed(i);
40+
delay(10);
41+
}
42+
43+
for (i=255; i!=0; i--) {
44+
motor.setSpeed(i);
45+
delay(10);
46+
}
47+
48+
49+
Serial.print("tech");
50+
motor.run(RELEASE);
51+
delay(1000);
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Adafruit Motor shield library
2+
// copyright Adafruit Industries LLC, 2009
3+
// this code is public domain, enjoy!
4+
5+
#include <AFMotor.h>
6+
7+
AF_Stepper motor(48, 2);
8+
9+
void setup() {
10+
Serial.begin(9600); // set up Serial library at 9600 bps
11+
Serial.println("Stepper test!");
12+
13+
motor.setSpeed(10); // 10 rpm
14+
}
15+
16+
void loop() {
17+
Serial.println("Single coil steps");
18+
motor.step(100, FORWARD, SINGLE);
19+
motor.step(100, BACKWARD, SINGLE);
20+
21+
Serial.println("Double coil steps");
22+
motor.step(100, FORWARD, DOUBLE);
23+
motor.step(100, BACKWARD, DOUBLE);
24+
25+
Serial.println("Interleave coil steps");
26+
motor.step(100, FORWARD, INTERLEAVE);
27+
motor.step(100, BACKWARD, INTERLEAVE);
28+
29+
#ifdef MICROSTEPPING
30+
Serial.println("Micrsostep steps");
31+
motor.step(100, FORWARD, MICROSTEP);
32+
motor.step(100, BACKWARD, MICROSTEP);
33+
#endif
34+
}

AFMotor/keywords.txt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#######################################
2+
# Syntax Coloring Map for AFMotor
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
AF_DCMotor KEYWORD1
10+
AF_Stepper KEYWORD1
11+
12+
#######################################
13+
# Methods and Functions (KEYWORD2)
14+
#######################################
15+
16+
enable KEYWORD2
17+
run KEYWORD2
18+
setSpeed KEYWORD2
19+
step KEYWORD2
20+
onestep KEYWORD2
21+
release KEYWORD2
22+
23+
#######################################
24+
# Constants (LITERAL1)
25+
#######################################
26+
27+
MICROSTEPPING LITERAL1
28+
FORWARD LITERAL1
29+
BACKWARD LITERAL1
30+
BRAKE LITERAL1
31+
RELEASE LITERAL1
32+
SINGLE LITERAL1
33+
DOUBLE LITERAL1
34+
INTERLEAVE LITERAL1
35+
MICROSTEP LITERAL1

DS1307RTC/DS1307RTC.cpp

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* DS1307RTC.h - library for DS1307 RTC
3+
4+
Copyright (c) Michael Margolis 2009
5+
This library is intended to be uses with Arduino Time.h library functions
6+
7+
The library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
21+
30 Dec 2009 - Initial release
22+
*/
23+
24+
#include <Wire.h>
25+
#include "DS1307RTC.h"
26+
27+
#define DS1307_CTRL_ID 0x68
28+
29+
DS1307RTC::DS1307RTC()
30+
{
31+
Wire.begin();
32+
}
33+
34+
// PUBLIC FUNCTIONS
35+
time_t DS1307RTC::get() // Aquire data from buffer and convert to time_t
36+
{
37+
tmElements_t tm;
38+
read(tm);
39+
return(makeTime(tm));
40+
}
41+
42+
void DS1307RTC::set(time_t t)
43+
{
44+
tmElements_t tm;
45+
breakTime(t, tm);
46+
tm.Second |= 0x80; // stop the clock
47+
write(tm);
48+
tm.Second &= 0x7f; // start the clock
49+
write(tm);
50+
}
51+
52+
// Aquire data from the RTC chip in BCD format
53+
void DS1307RTC::read( tmElements_t &tm)
54+
{
55+
Wire.beginTransmission(DS1307_CTRL_ID);
56+
Wire.send(0x00);
57+
Wire.endTransmission();
58+
59+
// request the 7 data fields (secs, min, hr, dow, date, mth, yr)
60+
Wire.requestFrom(DS1307_CTRL_ID, tmNbrFields);
61+
62+
tm.Second = bcd2dec(Wire.receive() & 0x7f);
63+
tm.Minute = bcd2dec(Wire.receive() );
64+
tm.Hour = bcd2dec(Wire.receive() & 0x3f); // mask assumes 24hr clock
65+
tm.Wday = bcd2dec(Wire.receive() );
66+
tm.Day = bcd2dec(Wire.receive() );
67+
tm.Month = bcd2dec(Wire.receive() );
68+
tm.Year = y2kYearToTm((bcd2dec(Wire.receive())));
69+
}
70+
71+
void DS1307RTC::write(tmElements_t &tm)
72+
{
73+
Wire.beginTransmission(DS1307_CTRL_ID);
74+
Wire.send(0x00); // reset register pointer
75+
76+
Wire.send(dec2bcd(tm.Second)) ;
77+
Wire.send(dec2bcd(tm.Minute));
78+
Wire.send(dec2bcd(tm.Hour)); // sets 24 hour format
79+
Wire.send(dec2bcd(tm.Wday));
80+
Wire.send(dec2bcd(tm.Day));
81+
Wire.send(dec2bcd(tm.Month));
82+
Wire.send(dec2bcd(tmYearToY2k(tm.Year)));
83+
84+
Wire.endTransmission();
85+
}
86+
// PRIVATE FUNCTIONS
87+
88+
// Convert Decimal to Binary Coded Decimal (BCD)
89+
uint8_t DS1307RTC::dec2bcd(uint8_t num)
90+
{
91+
return ((num/10 * 16) + (num % 10));
92+
}
93+
94+
// Convert Binary Coded Decimal (BCD) to Decimal
95+
uint8_t DS1307RTC::bcd2dec(uint8_t num)
96+
{
97+
return ((num/16 * 10) + (num % 16));
98+
}
99+
100+
DS1307RTC RTC = DS1307RTC(); // create an instance for the user
101+

0 commit comments

Comments
 (0)