Есть задание.
меняю на телефон https://www.avito.ru/sochi/telefony/prodayu_nokiya_s_6-01_b._u_498195842
Нужно изменить скетч.
В этом скетче прописаны шаговые моторы и серво моторы, нужно заменить на моторы постоянно тока 7шт. и три светодиода.
Приложение тоже изменить если нужно что то заменить, поменять.
скачать можно тут
http://file.sampo.ru/t8vwj7/
http://ai2.appinventor.mit.edu
меняю на телефон https://www.avito.ru/sochi/telefony/prodayu_nokiya_s_6-01_b._u_498195842
Нужно изменить скетч.
В этом скетче прописаны шаговые моторы и серво моторы, нужно заменить на моторы постоянно тока 7шт. и три светодиода.
Приложение тоже изменить если нужно что то заменить, поменять.
скачать можно тут
http://file.sampo.ru/t8vwj7/
http://ai2.appinventor.mit.edu
C++:
#include <SoftwareSerial.h>
#include <AccelStepper.h>
#include <Servo.h>
Servo servo01;
Servo servo02;
Servo servo03;
Servo servo04;
Servo servo05;
Servo servo06;
Servo servo07;
SoftwareSerial Bluetooth(2, 3); // Arduino(RX, TX) - HC-05 Bluetooth (TX, RX)
// Define the stepper motors and the pins the will use
AccelStepper LeftBackWheel(1, 42, 43); // (Type:driver, STEP, DIR) - Stepper1
AccelStepper LeftFrontWheel(1, 40, 41); // Stepper2
AccelStepper RightBackWheel(1, 44, 45); // Stepper3
AccelStepper RightFrontWheel(1, 46, 47); // Stepper4
#define led 13
int wheelSpeed = 1500;
int lbw[50], lfw[50], rbw[50], rfw[50]; // arrays for storing positions/steps
int servo1Pos, servo2Pos, servo3Pos, servo4Pos, servo5Pos, servo6Pos,servo7Pos; // current position
int servo1PPos, servo2PPos, servo3PPos, servo4PPos, servo5PPos, servo6PPos,servo7PPos; // previous position
int servo01SP[50], servo02SP[50], servo03SP[50], servo04SP[50], servo05SP[50], servo06SP[50],servo07SP[50]; // for storing positions/steps
int speedDelay = 20;
int index = 0;
int dataIn;
int m = 0;
void setup() {
// Set initial seed values for the steppers
LeftFrontWheel.setMaxSpeed(3000);
LeftBackWheel.setMaxSpeed(3000);
RightFrontWheel.setMaxSpeed(3000);
RightBackWheel.setMaxSpeed(3000);
pinMode(led, OUTPUT);
servo01.attach(5);
servo02.attach(6);
servo03.attach(7);
servo04.attach(8);
servo05.attach(9);
servo06.attach(10);
servo07.attach(11);
Bluetooth.begin(9600); // Default baud rate of the Bluetooth module
Bluetooth.setTimeout(5);
delay(20);
Serial.begin(9600);
// Move robot arm to initial position
servo1PPos = 90;
servo01.write(servo1PPos);
servo2PPos = 100;
servo02.write(servo2PPos);
servo3PPos = 120;
servo03.write(servo3PPos);
servo4PPos = 95;
servo04.write(servo4PPos);
servo5PPos = 60;
servo05.write(servo5PPos);
servo6PPos = 110;
servo06.write(servo6PPos);
servo7PPos = 110;
servo07.write(servo7PPos);
}
void loop() {
// Check for incoming data
if (Bluetooth.available() > 0) {
dataIn = Bluetooth.read(); // Read the data
if (dataIn == 0) {
m = 0;
}
if (dataIn == 1) {
m = 1;
}
if (dataIn == 2) {
m = 2;
}
if (dataIn == 3) {
m = 3;
}
if (dataIn == 4) {
m = 4;
}
if (dataIn == 5) {
m = 5;
}
if (dataIn == 6) {
m = 6;
}
if (dataIn == 7) {
m = 7;
}
if (dataIn == 8) {
m = 8;
}
if (dataIn == 9) {
m = 9;
}
if (dataIn == 10) {
m = 10;
}
if (dataIn == 11) {
m = 11;
}
if (dataIn == 12) {
m = 12;
}
if (dataIn == 14) {
m = 14;
}
if (dataIn == 16) {
m = 16;
}
if (dataIn == 17) {
m = 17;
}
if (dataIn == 18) {
m = 18;
}
if (dataIn == 19) {
m = 19;
}
if (dataIn == 20) {
m = 20;
}
if (dataIn == 21) {
m = 21;
}
if (dataIn == 22) {
m = 22;
}
if (dataIn == 23) {
m = 23;
}
if (dataIn == 24) {
m = 24;
}
if (dataIn == 25) {
m = 25;
}
if (dataIn == 26) {
m = 26;
}
if (dataIn == 27) {
m = 27;
}
if (dataIn == 28) {
m = 28;
}
if (dataIn == 29) {
m = 29;
}
// Move the Mecanum wheels platform
if (m == 4) {
moveSidewaysLeft();
}
if (m == 5) {
moveSidewaysRight();
}
if (m == 2) {
moveForward();
}
if (m == 7) {
moveBackward();
}
if (m == 3) {
moveRightForward();
}
if (m == 1) {
moveLeftForward();
}
if (m == 8) {
moveRightBackward();
}
if (m == 6) {
moveLeftBackward();
}
if (m == 9) {
rotateLeft();
}
if (m == 10) {
rotateRight();
}
if (m == 0) {
stopMoving();
}
// Mecanum wheels speed
if (dataIn > 30 & dataIn < 100) {
wheelSpeed = dataIn * 20;
}
// Move robot arm
// Move servo 1 in positive direction
while (m == 16) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo01.write(servo1PPos);
servo1PPos++;
delay(speedDelay);
}
// Move servo 1 in negative direction
while (m == 17) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo01.write(servo1PPos);
servo1PPos--;
delay(speedDelay);
}
// Move servo 2
while (m == 19) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo02.write(servo2PPos);
servo2PPos++;
delay(speedDelay);
}
while (m == 18) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo02.write(servo2PPos);
servo2PPos--;
delay(speedDelay);
}
// Move servo 3
while (m == 20) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo03.write(servo3PPos);
servo3PPos++;
delay(speedDelay);
}
while (m == 21) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo03.write(servo3PPos);
servo3PPos--;
delay(speedDelay);
}
// Move servo 4
while (m == 23) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo04.write(servo4PPos);
servo4PPos++;
delay(speedDelay);
}
while (m == 22) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo04.write(servo4PPos);
servo4PPos--;
delay(speedDelay);
}
// Move servo 5
while (m == 25) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo05.write(servo5PPos);
servo5PPos++;
delay(speedDelay);
}
while (m == 24) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo05.write(servo5PPos);
servo5PPos--;
delay(speedDelay);
}
// Move servo 6
while (m == 26) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo06.write(servo6PPos);
servo6PPos++;
delay(speedDelay);
}
while (m == 27) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo06.write(servo6PPos);
servo6PPos--;
delay(speedDelay);
}
// Move servo 7
while (m == 28) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo07.write(servo7PPos);
servo7PPos++;
delay(speedDelay);
}
while (m == 29) {
if (Bluetooth.available() > 0) {
m = Bluetooth.read();
}
servo07.write(servo7PPos);
servo7PPos--;
delay(speedDelay);
}
// If arm speed slider is changed
if (dataIn > 101 & dataIn < 250) {
speedDelay = dataIn / 10; // Change servo speed (delay time)
}
// If button "SAVE" is pressed
if (m == 12) {
//if it's initial save, set the steppers position to 0
if (index == 0) {
LeftBackWheel.setCurrentPosition(0);
LeftFrontWheel.setCurrentPosition(0);
RightBackWheel.setCurrentPosition(0);
RightFrontWheel.setCurrentPosition(0);
}
lbw[index] = LeftBackWheel.currentPosition(); // save position into the array
lfw[index] = LeftFrontWheel.currentPosition();
rbw[index] = RightBackWheel.currentPosition();
rfw[index] = RightFrontWheel.currentPosition();
servo01SP[index] = servo1PPos; // save position into the array
servo02SP[index] = servo2PPos;
servo03SP[index] = servo3PPos;
servo04SP[index] = servo4PPos;
servo05SP[index] = servo5PPos;
servo06SP[index] = servo6PPos;
servo07SP[index] = servo7PPos;
index++; // Increase the array index
m = 0;
}
// If button "RUN" is pressed
if (m == 14) {
runSteps();
// If button "RESET" is pressed
if (dataIn != 14) {
stopMoving();
memset(lbw, 0, sizeof(lbw)); // Clear the array data to 0
memset(lfw, 0, sizeof(lfw));
memset(rbw, 0, sizeof(rbw));
memset(rfw, 0, sizeof(rfw));
memset(servo01SP, 0, sizeof(servo01SP)); // Clear the array data to 0
memset(servo02SP, 0, sizeof(servo02SP));
memset(servo03SP, 0, sizeof(servo03SP));
memset(servo04SP, 0, sizeof(servo04SP));
memset(servo05SP, 0, sizeof(servo05SP));
memset(servo06SP, 0, sizeof(servo06SP));
memset(servo07SP, 0, sizeof(servo07SP));
index = 0; // Index to 0
}
}
}
LeftFrontWheel.runSpeed();
LeftBackWheel.runSpeed();
RightFrontWheel.runSpeed();
RightBackWheel.runSpeed();
// Monitor the battery voltage
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.00) * 3; // Convert the reading values from 5v to suitable 12V i
//Serial.println(voltage);
// If voltage is below 11V turn on the LED
if (voltage < 11) {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led, LOW);
}
}
void moveForward() {
LeftFrontWheel.setSpeed(wheelSpeed);
LeftBackWheel.setSpeed(wheelSpeed);
RightFrontWheel.setSpeed(wheelSpeed);
RightBackWheel.setSpeed(wheelSpeed);
}
void moveBackward() {
LeftFrontWheel.setSpeed(-wheelSpeed);
LeftBackWheel.setSpeed(-wheelSpeed);
RightFrontWheel.setSpeed(-wheelSpeed);
RightBackWheel.setSpeed(-wheelSpeed);
}
void moveSidewaysRight() {
LeftFrontWheel.setSpeed(wheelSpeed);
LeftBackWheel.setSpeed(-wheelSpeed);
RightFrontWheel.setSpeed(-wheelSpeed);
RightBackWheel.setSpeed(wheelSpeed);
}
void moveSidewaysLeft() {
LeftFrontWheel.setSpeed(-wheelSpeed);
LeftBackWheel.setSpeed(wheelSpeed);
RightFrontWheel.setSpeed(wheelSpeed);
RightBackWheel.setSpeed(-wheelSpeed);
}
void rotateLeft() {
LeftFrontWheel.setSpeed(-wheelSpeed);
LeftBackWheel.setSpeed(-wheelSpeed);
RightFrontWheel.setSpeed(wheelSpeed);
RightBackWheel.setSpeed(wheelSpeed);
}
void rotateRight() {
LeftFrontWheel.setSpeed(wheelSpeed);
LeftBackWheel.setSpeed(wheelSpeed);
RightFrontWheel.setSpeed(-wheelSpeed);
RightBackWheel.setSpeed(-wheelSpeed);
}
void moveRightForward() {
LeftFrontWheel.setSpeed(wheelSpeed);
LeftBackWheel.setSpeed(0);
RightFrontWheel.setSpeed(0);
RightBackWheel.setSpeed(wheelSpeed);
}
void moveRightBackward() {
LeftFrontWheel.setSpeed(0);
LeftBackWheel.setSpeed(-wheelSpeed);
RightFrontWheel.setSpeed(-wheelSpeed);
RightBackWheel.setSpeed(0);
}
void moveLeftForward() {
LeftFrontWheel.setSpeed(0);
LeftBackWheel.setSpeed(wheelSpeed);
RightFrontWheel.setSpeed(wheelSpeed);
RightBackWheel.setSpeed(0);
}
void moveLeftBackward() {
LeftFrontWheel.setSpeed(-wheelSpeed);
LeftBackWheel.setSpeed(0);
RightFrontWheel.setSpeed(0);
RightBackWheel.setSpeed(-wheelSpeed);
}
void stopMoving() {
LeftFrontWheel.setSpeed(0);
LeftBackWheel.setSpeed(0);
RightFrontWheel.setSpeed(0);
RightBackWheel.setSpeed(0);
}
// Automatic mode custom function - run the saved steps
void runSteps() {
while (dataIn != 13) { // Run the steps over and over again until "RESET" button is pressed
for (int i = 0; i <= index - 2; i++) { // Run through all steps(index)
if (Bluetooth.available() > 0) { // Check for incomding data
dataIn = Bluetooth.read();
if ( dataIn == 15) { // If button "PAUSE" is pressed
while (dataIn != 14) { // Wait until "RUN" is pressed again
if (Bluetooth.available() > 0) {
dataIn = Bluetooth.read();
if ( dataIn == 13) {
break;
}
}
}
}
// If speed slider is changed
if (dataIn > 100 & dataIn < 150) {
speedDelay = dataIn / 10; // Change servo speed (delay time)
}
// Mecanum wheels speed
if (dataIn > 30 & dataIn < 100) {
wheelSpeed = dataIn * 10;
dataIn = 14;
}
}
LeftFrontWheel.moveTo(lfw);
LeftFrontWheel.setSpeed(wheelSpeed);
LeftBackWheel.moveTo(lbw);
LeftBackWheel.setSpeed(wheelSpeed);
RightFrontWheel.moveTo(rfw);
RightFrontWheel.setSpeed(wheelSpeed);
RightBackWheel.moveTo(rbw);
RightBackWheel.setSpeed(wheelSpeed);
while (LeftBackWheel.currentPosition() != lbw & LeftFrontWheel.currentPosition() != lfw & RightFrontWheel.currentPosition() != rfw & RightBackWheel.currentPosition() != rbw) {
LeftFrontWheel.runSpeedToPosition();
LeftBackWheel.runSpeedToPosition();
RightFrontWheel.runSpeedToPosition();
RightBackWheel.runSpeedToPosition();
}
// Servo 1
if (servo01SP == servo01SP[i + 1]) {
}
if (servo01SP > servo01SP[i + 1]) {
for ( int j = servo01SP; j >= servo01SP[i + 1]; j--) {
servo01.write(j);
delay(speedDelay);
}
}
if (servo01SP < servo01SP[i + 1]) {
for ( int j = servo01SP; j <= servo01SP[i + 1]; j++) {
servo01.write(j);
delay(speedDelay);
}
}
// Servo 2
if (servo02SP == servo02SP[i + 1]) {
}
if (servo02SP > servo02SP[i + 1]) {
for ( int j = servo02SP; j >= servo02SP[i + 1]; j--) {
servo02.write(j);
delay(speedDelay);
}
}
if (servo02SP < servo02SP[i + 1]) {
for ( int j = servo02SP; j <= servo02SP[i + 1]; j++) {
servo02.write(j);
delay(speedDelay);
}
}
// Servo 3
if (servo03SP == servo03SP[i + 1]) {
}
if (servo03SP > servo03SP[i + 1]) {
for ( int j = servo03SP; j >= servo03SP[i + 1]; j--) {
servo03.write(j);
delay(speedDelay);
}
}
if (servo03SP < servo03SP[i + 1]) {
for ( int j = servo03SP; j <= servo03SP[i + 1]; j++) {
servo03.write(j);
delay(speedDelay);
}
}
// Servo 4
if (servo04SP == servo04SP[i + 1]) {
}
if (servo04SP > servo04SP[i + 1]) {
for ( int j = servo04SP; j >= servo04SP[i + 1]; j--) {
servo04.write(j);
delay(speedDelay);
}
}
if (servo04SP < servo04SP[i + 1]) {
for ( int j = servo04SP; j <= servo04SP[i + 1]; j++) {
servo04.write(j);
delay(speedDelay);
}
}
// Servo 5
if (servo05SP == servo05SP[i + 1]) {
}
if (servo05SP > servo05SP[i + 1]) {
for ( int j = servo05SP; j >= servo05SP[i + 1]; j--) {
servo05.write(j);
delay(speedDelay);
}
}
if (servo05SP < servo05SP[i + 1]) {
for ( int j = servo05SP; j <= servo05SP[i + 1]; j++) {
servo05.write(j);
delay(speedDelay);
}
}
// Servo 6
if (servo06SP == servo06SP[i + 1]) {
}
if (servo06SP > servo06SP[i + 1]) {
for ( int j = servo06SP; j >= servo06SP[i + 1]; j--) {
servo06.write(j);
delay(speedDelay);
}
}
if (servo06SP < servo06SP[i + 1]) {
for ( int j = servo06SP; j <= servo06SP[i + 1]; j++) {
servo06.write(j);
delay(speedDelay);
}
}
// Servo 7
if (servo07SP == servo07SP[i + 1]) {
}
if (servo07SP > servo07SP[i + 1]) {
for ( int j = servo07SP; j >= servo07SP[i + 1]; j--) {
servo07.write(j);
delay(speedDelay);
}
}
if (servo07SP < servo07SP[i + 1]) {
for ( int j = servo07SP; j <= servo07SP[i + 1]; j++) {
servo07.write(j);
delay(speedDelay);
}
}
}
}
}
Изменено: