2/4 WD TANK - mcworkshop

MC        WORKSHOP
Vai ai contenuti

Menu principale:

2/4 WD TANK

Projects
2WD TANK / 4WD TANK


2WD

4WD
// 2WD by M.C. mcworkshop
// This example code is in the public domain.
// August 2019 V1.1 14/08/2019  V1.3 01/09/2019 ore 10:00
#include <SoftwareSerial.h>//Richiama la libreria seriale
#define bluetooth Serial//Richiama la libreria bluetooth
SoftwareSerial mySerial(0, 1);//RX=>1 TX=>0
const int motorA1  = 3;//in1
const int motorA2  = 5;//in2
const int motorB1  = 6;//in3
const int motorB2  = 9;//in4
int vSpeed = 255;//da 0 a 255
int luci = 12;
//servo
#include <Servo.h>
Servo myservo;
int pos = 90; //servo pin 11
void setup() {
 pinMode(motorA1, OUTPUT);
 pinMode(motorA2, OUTPUT);
 pinMode(motorB1, OUTPUT);
 pinMode(motorB2, OUTPUT);
 pinMode (luci, OUTPUT);
 Serial.begin(9600);
 bluetooth.begin(9600);
 mySerial.begin(9600);
 delay (500);
 //servo
 myservo.attach(11);
}
void loop() {
 while (bluetooth.available())
 {
   char dato = bluetooth.read();
   switch (dato)
     //sinistra
   {
     case 'a': {
         analogWrite(motorA1, vSpeed); //A1 motori destri  avanti
         analogWrite(motorA2, 0);
         analogWrite(motorB1, 0);
         analogWrite(motorB2, vSpeed);
         break;
       }
     //destra
     case 'b': {
         analogWrite(motorA1, 0);
         analogWrite(motorA2, vSpeed);
         analogWrite(motorB1, vSpeed); //B1 motori sinistri avanti
         analogWrite(motorB2, 0);
         break;
       }
     //avanti
     case 'c': {
         analogWrite(motorA1,vSpeed);
         analogWrite(motorA2, 0);
         analogWrite(motorB1, vSpeed);
         analogWrite(motorB2, 0);
         break;
       }
     //indietro
     case'd': {
         analogWrite(motorA1, 0);
         analogWrite(motorA2, vSpeed);
         analogWrite(motorB1, 0);
         analogWrite(motorB2, vSpeed);
         break;
       }
     //stop
     case 'e': {
         analogWrite(motorA1, 0);
         analogWrite(motorA2, 0);
         analogWrite(motorB1, 0);
         analogWrite(motorB2, 0);
         break;
       }
     //luci
     case 'f': {
         digitalWrite (12, HIGH);
         break;
       }
     case 'i': {
         digitalWrite (12, LOW);
         break;
       //servo
       case 'g': {
           myservo.write (170);
           break;
         }
       case 'h': {
           myservo.write (0);
           break;
         }
       }
   }
 }
}

sinistra = a
destra = b
avanti = c
indietro = d
stop = e
luci = f / i
servo 170° = g
servo 0° = h
APP Arduino bluetooth controller

 
Copyright 2015. All rights reserved.
Torna ai contenuti | Torna al menu