-
Notifications
You must be signed in to change notification settings - Fork 2
/
interruptRegards
48 lines (38 loc) · 1.22 KB
/
interruptRegards
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
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *myMotor1 = AFMS.getMotor(2);// port M1
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(1);// port M2
int motorSpeed[] = {120, 120};
int motorDirection[] = {FORWARD, BACKWARD};
const byte sensor0 = 5;
const byte sensor1 = 7;
const byte sensor2 = 6;
void setup() {
pinMode(sensor0, INPUT_PULLUP);
pinMode(sensor1, INPUT_PULLUP);
pinMode(sensor2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(sensor0), moveMotors, RISING);
attachInterrupt(digitalPinToInterrupt(sensor1), stopM1, RISING);
attachInterrupt(digitalPinToInterrupt(sensor2), stopM2, RISING);
//initial motor speed
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
// Set the speed to start, from 0 (off) to 255 (max speed)
myMotor1->setSpeed(motorSpeed[0]);
myMotor2->setSpeed(motorSpeed[1]);
}
void loop() {
//digitalWrite(ledPin, state);
}
void moveMotors() {
myMotor1->run(FORWARD);
myMotor2->run(FORWARD);
}
void stopM1() {
myMotor1->run(RELEASE);
}
void stopM2() {
myMotor2->run(RELEASE);
}