├── README.md ├── HC05-master ├── .gitignore ├── Recovery.fzz ├── Recovery_bb.png ├── HardwarSerial.fzz ├── LibDevelopment.fzz ├── Recommended_bb.png ├── SoftwareSerial.fzz ├── ImprovedPowerCtrl.fzz ├── LibDevelopment_bb.png ├── ImprovedPowerCtrl_bb.png ├── keywords.txt ├── Examples │ ├── echo │ │ └── echo.ino │ ├── hc05_test │ │ └── hc05_test.ino │ ├── recover │ │ └── recover.ino │ ├── findBaudTest │ │ └── findBaudTest.ino │ └── changeName │ │ └── changeName.ino ├── LICENSE ├── HC05.h ├── README.md └── HC05.cpp ├── .gitattributes ├── JoystickControl ├── JoystickControl ├── Basic_Motor.h ├── def.h ├── JoystickControl.ino ├── Basic_Motor.cpp ├── joystick.h ├── hidjoystickrptparser.h ├── DCmotor.h ├── USBHIDJoystick.ino ├── hidjoystickrptparser.cpp ├── joystick.cpp └── DCmotor.cpp ├── auto_2 ├── Relay.h ├── Relay.cpp └── auto_2.ino ├── autonomous_Secondary ├── Relay.h ├── autonomous_Secondary.ino └── Relay.cpp ├── Test_Program ├── Basic_Motor.h ├── Sensor1.h ├── def.h ├── Basic_Motor.cpp ├── joystick.h.bat ├── hidjoystickrptparser.h.bat ├── USBHIDJoystick.ino ├── USBHIDJoystick.ino.bat ├── DCmotor.h ├── Sensor1.cpp ├── Encoder_Test_program.ino ├── joystick.cpp.bat ├── hidjoystickrptparser.cpp ├── hidjoystickrptparser.cpp.bat └── Test_Program.ino ├── Final1.2 └── Test_Program │ ├── Basic_Motor.h │ ├── Sensor1.h │ ├── def.h │ ├── Basic_Motor.cpp │ ├── joystick.h.bat │ ├── hidjoystickrptparser.h.bat │ ├── USBHIDJoystick.ino │ ├── USBHIDJoystick.ino.bat │ ├── DCmotor.h │ ├── Sensor1.cpp │ ├── Encoder_Test_program.ino │ ├── joystick.cpp.bat │ ├── hidjoystickrptparser.cpp │ ├── hidjoystickrptparser.cpp.bat │ └── Test_Program.ino ├── Test equipments ├── Test_Program │ ├── Basic_Motor.h │ ├── def.h │ ├── Basic_Motor.cpp │ ├── DCmotor.h │ ├── Test_Program.ino │ └── DCmotor.cpp └── gripper │ └── gripper.ino ├── Test Program └── Test_Program │ ├── Basic_Motor.h │ ├── Sensor1.h │ ├── def.h │ ├── Basic_Motor.cpp │ ├── joystick.h.bat │ ├── hidjoystickrptparser.h.bat │ ├── USBHIDJoystick.ino │ ├── USBHIDJoystick.ino.bat │ ├── DCmotor.h │ ├── Encoder_Test_program.ino │ ├── Sensor1.cpp │ ├── joystick.cpp.bat │ ├── hidjoystickrptparser.cpp │ └── hidjoystickrptparser.cpp.bat ├── Temporary └── Test_Program │ └── Encoder_Test_program │ └── Encoder_Test_program.ino ├── test ├── database.xml ├── home.html ├── style.css ├── addentry.php ├── login.html └── register.html ├── Manual Robot ├── hidjoystickrptparser.h └── hidjoystickrptparser.cpp ├── Stepper_Manual_ajin └── Stepper_Manual_ajin.ino └── imageprocessingpython └── opencvdetect.py /README.md: -------------------------------------------------------------------------------- 1 | # ABURobocon_Manual_Autonomous_robot_Codes 2 | -------------------------------------------------------------------------------- /HC05-master/.gitignore: -------------------------------------------------------------------------------- 1 | # Files git should ignore 2 | *.swp 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /HC05-master/Recovery.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishsalunkhe/ABURobocon_Manual_Autonomous_robot_Codes/master/HC05-master/Recovery.fzz -------------------------------------------------------------------------------- /HC05-master/Recovery_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishsalunkhe/ABURobocon_Manual_Autonomous_robot_Codes/master/HC05-master/Recovery_bb.png -------------------------------------------------------------------------------- /HC05-master/HardwarSerial.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishsalunkhe/ABURobocon_Manual_Autonomous_robot_Codes/master/HC05-master/HardwarSerial.fzz -------------------------------------------------------------------------------- /HC05-master/LibDevelopment.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishsalunkhe/ABURobocon_Manual_Autonomous_robot_Codes/master/HC05-master/LibDevelopment.fzz -------------------------------------------------------------------------------- /HC05-master/Recommended_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishsalunkhe/ABURobocon_Manual_Autonomous_robot_Codes/master/HC05-master/Recommended_bb.png -------------------------------------------------------------------------------- /HC05-master/SoftwareSerial.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishsalunkhe/ABURobocon_Manual_Autonomous_robot_Codes/master/HC05-master/SoftwareSerial.fzz -------------------------------------------------------------------------------- /HC05-master/ImprovedPowerCtrl.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishsalunkhe/ABURobocon_Manual_Autonomous_robot_Codes/master/HC05-master/ImprovedPowerCtrl.fzz -------------------------------------------------------------------------------- /HC05-master/LibDevelopment_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishsalunkhe/ABURobocon_Manual_Autonomous_robot_Codes/master/HC05-master/LibDevelopment_bb.png -------------------------------------------------------------------------------- /HC05-master/ImprovedPowerCtrl_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashishsalunkhe/ABURobocon_Manual_Autonomous_robot_Codes/master/HC05-master/ImprovedPowerCtrl_bb.png -------------------------------------------------------------------------------- /JoystickControl/JoystickControl: -------------------------------------------------------------------------------- 1 | 2 | #include "def.h" 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | void setup() { 11 | 12 | Motions.init(); 13 | 14 | 15 | } 16 | 17 | 18 | void loop() 19 | { 20 | Motions.joy(); 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /auto_2/Relay.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _relay_h 3 | #define _relay_h 4 | #include "arduino.h" 5 | 6 | extern uint8_t R11; 7 | extern uint8_t R21; 8 | extern uint8_t R31; 9 | extern uint8_t R41; 10 | 11 | 12 | class Relay{ 13 | public: 14 | void relay(uint8_t ch); 15 | void reinit(); 16 | }; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /autonomous_Secondary/Relay.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _relay_h 3 | #define _relay_h 4 | #include "arduino.h" 5 | 6 | extern uint8_t R11; 7 | extern uint8_t R21; 8 | extern uint8_t R31; 9 | extern uint8_t R41; 10 | extern uint8_t R51; 11 | 12 | class Relay{ 13 | public: 14 | void relay(uint8_t ch); 15 | void reinit(); 16 | }; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /JoystickControl/Basic_Motor.h: -------------------------------------------------------------------------------- 1 | #ifndef _Basic_Motor_H 2 | #define _Basic_Motor_H 3 | #include "Arduino.h" 4 | 5 | class Basic_Motor{ 6 | public: 7 | void frontlt_CW(); 8 | void frontlt_CCW(); 9 | 10 | void frontrt_CW(); 11 | void frontrt_CCW(); 12 | 13 | void backlt_CW(); 14 | void backlt_CCW(); 15 | 16 | void backrt_CW(); 17 | void backrt_CCW(); 18 | }; 19 | #endif -------------------------------------------------------------------------------- /Test_Program/Basic_Motor.h: -------------------------------------------------------------------------------- 1 | #ifndef _Basic_Motor_H 2 | #define _Basic_Motor_H 3 | #include "Arduino.h" 4 | 5 | class Basic_Motor{ 6 | public: 7 | void frontlt_CW(); 8 | void frontlt_CCW(); 9 | 10 | void frontrt_CW(); 11 | void frontrt_CCW(); 12 | 13 | void backlt_CW(); 14 | void backlt_CCW(); 15 | 16 | void backrt_CW(); 17 | void backrt_CCW(); 18 | }; 19 | #endif 20 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/Basic_Motor.h: -------------------------------------------------------------------------------- 1 | #ifndef _Basic_Motor_H 2 | #define _Basic_Motor_H 3 | #include "Arduino.h" 4 | 5 | class Basic_Motor{ 6 | public: 7 | void frontlt_CW(); 8 | void frontlt_CCW(); 9 | 10 | void frontrt_CW(); 11 | void frontrt_CCW(); 12 | 13 | void backlt_CW(); 14 | void backlt_CCW(); 15 | 16 | void backrt_CW(); 17 | void backrt_CCW(); 18 | }; 19 | #endif 20 | -------------------------------------------------------------------------------- /Test equipments/Test_Program/Basic_Motor.h: -------------------------------------------------------------------------------- 1 | #ifndef _Basic_Motor_H 2 | #define _Basic_Motor_H 3 | #include "Arduino.h" 4 | 5 | class Basic_Motor{ 6 | public: 7 | void frontlt_CW(); 8 | void frontlt_CCW(); 9 | 10 | void frontrt_CW(); 11 | void frontrt_CCW(); 12 | 13 | void backlt_CW(); 14 | void backlt_CCW(); 15 | 16 | void backrt_CW(); 17 | void backrt_CCW(); 18 | }; 19 | #endif -------------------------------------------------------------------------------- /Test Program/Test_Program/Basic_Motor.h: -------------------------------------------------------------------------------- 1 | #ifndef _Basic_Motor_H 2 | #define _Basic_Motor_H 3 | #include "Arduino.h" 4 | 5 | class Basic_Motor{ 6 | public: 7 | void frontlt_CW(); 8 | void frontlt_CCW(); 9 | 10 | void frontrt_CW(); 11 | void frontrt_CCW(); 12 | 13 | void backlt_CW(); 14 | void backlt_CCW(); 15 | 16 | void backrt_CW(); 17 | void backrt_CCW(); 18 | }; 19 | #endif 20 | -------------------------------------------------------------------------------- /JoystickControl/def.h: -------------------------------------------------------------------------------- 1 | #ifndef _def_H 2 | #define _def_H 3 | 4 | #include "joystick.h" 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | uint8_t pwm1 = 4; 13 | uint8_t pwm2 = 5; 14 | uint8_t pwm3 = 6; 15 | uint8_t pwm4 = 7; 16 | 17 | uint8_t dir1 = 22; // 8 18 | uint8_t dir2 = 24; //9 19 | uint8_t dir3 = 26; //10 20 | uint8_t dir4 = 28; //11 21 | uint16_t PPR = 442; 22 | 23 | 24 | 25 | Motion Motions; 26 | 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Test equipments/Test_Program/def.h: -------------------------------------------------------------------------------- 1 | #ifndef _def_H 2 | #define _def_H 3 | #include "DCmotor.h" 4 | 5 | 6 | 7 | 8 | 9 | 10 | uint8_t pwm1 = 4; 11 | uint8_t pwm2 = 5; 12 | uint8_t pwm3 = 6; 13 | uint8_t pwm4 = 7; 14 | 15 | uint8_t dir1 = 8; 16 | uint8_t dir2 = 9; 17 | uint8_t dir3 = 10; 18 | uint8_t dir4 = 11; 19 | uint16_t PPR = 537; 20 | 21 | 22 | DCMotor mymotor; 23 | //Motion Motions; 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /HC05-master/keywords.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Syntax coloring for HC05 Library 3 | # 4 | 5 | # Datatypes (Classes) 6 | HC05 KEYWORD1 7 | 8 | # Methods and functions 9 | cmd KEYWORD2 10 | findBaud KEYWORD2 11 | setBaud KEYWORD2 12 | connected KEYWORD2 13 | available KEYWORD2 14 | peek KEYWORD2 15 | read KEYWORD2 16 | flush KEYWORD2 17 | write KEYWORD2 18 | 19 | # Constants (Macros in this case) 20 | DEBUG_HC05 LITERAL1 21 | HC05_SOFTWARE_SERIAL LITERAL1 22 | -------------------------------------------------------------------------------- /Test_Program/Sensor1.h: -------------------------------------------------------------------------------- 1 | #ifndef __linesensor_h 2 | #define __linesensor_h 3 | #include "Arduino.h" 4 | 5 | 6 | class linesensor 7 | { 8 | public: 9 | uint8_t l1; 10 | uint8_t l2; 11 | uint8_t l3; 12 | uint8_t l4; 13 | uint8_t l5; 14 | uint8_t l6; 15 | uint8_t l7; 16 | uint8_t l8; 17 | linesensor(uint8_t a1 , uint8_t a2 , uint8_t a3 , uint8_t a4 , uint8_t a5 , uint8_t a6 , uint8_t a7 , uint8_t a8); 18 | uint8_t readsensor(); 19 | }; 20 | 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/Sensor1.h: -------------------------------------------------------------------------------- 1 | #ifndef __linesensor_h 2 | #define __linesensor_h 3 | #include "Arduino.h" 4 | 5 | 6 | class linesensor 7 | { 8 | public: 9 | uint8_t l1; 10 | uint8_t l2; 11 | uint8_t l3; 12 | uint8_t l4; 13 | uint8_t l5; 14 | uint8_t l6; 15 | uint8_t l7; 16 | uint8_t l8; 17 | linesensor(uint8_t a1 , uint8_t a2 , uint8_t a3 , uint8_t a4 , uint8_t a5 , uint8_t a6 , uint8_t a7 , uint8_t a8); 18 | uint8_t readsensor(); 19 | }; 20 | 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Test Program/Test_Program/Sensor1.h: -------------------------------------------------------------------------------- 1 | #ifndef __linesensor_h 2 | #define __linesensor_h 3 | #include "Arduino.h" 4 | 5 | 6 | class linesensor 7 | { 8 | public: 9 | uint8_t l1; 10 | uint8_t l2; 11 | uint8_t l3; 12 | uint8_t l4; 13 | uint8_t l5; 14 | uint8_t l6; 15 | uint8_t l7; 16 | uint8_t l8; 17 | linesensor(uint8_t a1 , uint8_t a2 , uint8_t a3 , uint8_t a4 , uint8_t a5 , uint8_t a6 , uint8_t a7 , uint8_t a8); 18 | uint8_t readsensor(); 19 | }; 20 | 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Temporary/Test_Program/Encoder_Test_program/Encoder_Test_program.ino: -------------------------------------------------------------------------------- 1 | 2 | int count = 0; 3 | //int speed = 0; 4 | //int flag = 0; 5 | 6 | 7 | volatile int lastEncoded = 0; 8 | volatile long encoderValue = 0; 9 | 10 | 11 | 12 | 13 | 14 | void encoder() 15 | { 16 | count++; 17 | } 18 | 19 | void setup() { 20 | Serial.begin(115200); 21 | pinMode(2,INPUT); 22 | pinMode(3,INPUT); 23 | 24 | attachInterrupt(digitalPinToInterrupt(2),encoder, CHANGE); 25 | } 26 | 27 | void loop() { 28 | Serial.print("count = "); 29 | Serial.println(count); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /autonomous_Secondary/autonomous_Secondary.ino: -------------------------------------------------------------------------------- 1 | #include "Relay.h" 2 | 3 | uint8_t R11 = A8; //Retraction 4 | uint8_t R21 = A9; //Expansion 5 | uint8_t R31 = A10; //led Panel 6 | uint8_t R41 = A11; 7 | uint8_t R51 = A12; 8 | 9 | uint8_t reed1 = 23; 10 | uint8_t reed2 = 25; 11 | uint8_t reed3 = 27; 12 | 13 | 14 | Relay relay; 15 | char receivedCharacter; 16 | 17 | void setup() { 18 | Serial.begin(115200); //Serial Communication for rasberry pi 19 | Serial1.begin(115200); // Serial Communication for Main Arduino 20 | relay.reinit(); 21 | } 22 | 23 | void loop() { 24 | while 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Test equipments/gripper/gripper.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | Servo myservo; // create servo object to control a servo 4 | 5 | 6 | 7 | void setup() { 8 | pinMode (8,INPUT); 9 | myservo.attach(9,500,2400);// attaches the servo on pin 9 to the servo object 10 | Serial.begin(115200); 11 | myservo.write(90);} 12 | 13 | void loop() { 14 | 15 | delay(500); 16 | uint8_t a = digitalRead(8); 17 | Serial.println(a); 18 | if(a == 0 ) 19 | { myservo.write(30); 20 | if(a == 1) 21 | myservo.write(90); 22 | } 23 | else if(a == 1) 24 | {myservo.write(90);} 25 | 26 | 27 | } 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /test/database.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | nilesh 6 | nilesh 7 | nil 8 | 89898989898 9 | nil 10 | 11 | 12 | aq 13 | aq 14 | aq 15 | aq 16 | aq 17 | 18 | 19 | nn 20 | nn 21 | nn 22 | nn 23 | nn 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Test_Program/def.h: -------------------------------------------------------------------------------- 1 | #ifndef _def_H 2 | #define _def_H 3 | #include "DCmotor.h" 4 | #include "Sensor1.h" 5 | //#include "joystick.h" 6 | 7 | 8 | 9 | uint8_t pwm1 = 6;//4 FL 10 | uint8_t pwm2 = 7;//5 FR 11 | uint8_t pwm3 = 4;//6 BL 12 | uint8_t pwm4 = 12;//7 BR 13 | 14 | uint8_t dir1 = 10;//8 15 | uint8_t dir2 =11;//9 16 | uint8_t dir3 = 8;//10 17 | uint8_t dir4 = 9;//11 18 | uint16_t PPR = 537; 19 | 20 | 21 | linesensor LineF(22,24,26,28,30,32,34,36); 22 | linesensor LineB(23,25,27,29,31,33,35,37); 23 | linesensor LineR(39,41,43,45,47,49,51,53); 24 | linesensor LineL(38,40,42,44,46,48,50,52); 25 | 26 | 27 | DCMotor mymotor; 28 | //Motion Motions; 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/def.h: -------------------------------------------------------------------------------- 1 | #ifndef _def_H 2 | #define _def_H 3 | #include "DCmotor.h" 4 | #include "Sensor1.h" 5 | //#include "joystick.h" 6 | 7 | 8 | 9 | uint8_t pwm1 = 6;//4 FL 10 | uint8_t pwm2 = 7;//5 FR 11 | uint8_t pwm3 = 4;//6 BL 12 | uint8_t pwm4 = 12;//7 BR 13 | 14 | uint8_t dir1 = 10;//8 15 | uint8_t dir2 =11;//9 16 | uint8_t dir3 = 8;//10 17 | uint8_t dir4 = 9;//11 18 | uint16_t PPR = 537; 19 | 20 | 21 | linesensor LineF(22,24,26,28,30,32,34,36); 22 | linesensor LineB(23,25,27,29,31,33,35,37); 23 | linesensor LineR(39,41,43,45,47,49,51,53); 24 | linesensor LineL(38,40,42,44,46,48,50,52); 25 | 26 | 27 | DCMotor mymotor; 28 | //Motion Motions; 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Test Program/Test_Program/def.h: -------------------------------------------------------------------------------- 1 | #ifndef _def_H 2 | #define _def_H 3 | #include "DCmotor.h" 4 | #include "Sensor1.h" 5 | //#include "joystick.h" 6 | 7 | 8 | 9 | uint8_t pwm1 = 6;//4 FL 10 | uint8_t pwm2 = 7;//5 FR 11 | uint8_t pwm3 = 4;//6 BL 12 | uint8_t pwm4 = 12;//7 BR 13 | 14 | uint8_t dir1 = 10;//8 15 | uint8_t dir2 =11;//9 16 | uint8_t dir3 = 8;//10 17 | uint8_t dir4 = 9;//11 18 | uint16_t PPR = 537; 19 | 20 | 21 | linesensor LineF(22,24,26,28,30,32,34,36); 22 | linesensor LineB(23,25,27,29,31,33,35,37); 23 | linesensor LineR(39,41,43,45,47,49,51,53); 24 | linesensor LineL(38,40,42,44,46,48,50,52); 25 | 26 | 27 | DCMotor mymotor; 28 | //Motion Motions; 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /JoystickControl/JoystickControl.ino: -------------------------------------------------------------------------------- 1 | 2 | #include "def.h" 3 | 4 | //DCMotor mymotor; 5 | 6 | 7 | 8 | 9 | 10 | void setup() { 11 | 12 | Motions.init(); 13 | Serial.begin(115200); 14 | Serial2.begin(115200); 15 | } 16 | 17 | 18 | 19 | void loop() 20 | { 21 | Motions.joy(); 22 | 23 | 24 | 25 | /* while ((Serial.available()) > 0) 26 | { 27 | // b = (char)Serial.read(); 28 | //Serial.println(b); 29 | //a[i] += b; 30 | //i++; 31 | speed1 = Serial.parseInt(); 32 | } 33 | //a[i] = '\0'; 34 | Serial.println(speed2); 35 | 36 | if (speed1 > 0) 37 | { 38 | speed2 = speed1; 39 | analogWrite(2,speed2); 40 | } 41 | // delay(1000); 42 | } 43 | 44 | */ 45 | } 46 | -------------------------------------------------------------------------------- /test/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Welcome to Course Consultation Website

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 |
QualificationIntrestCourse Suggestion
12thProgrammingC,C++
12thWeb DesignHTML,CSS,JavaScript
12thCar DesignAutoCAD, CATIA
12thRoboticsArtificial Intelligence and Robotics
32 |
33 | 34 | 35 | -------------------------------------------------------------------------------- /JoystickControl/Basic_Motor.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "Basic_Motor.h" 3 | 4 | extern uint8_t dir1; 5 | extern uint8_t dir2; 6 | extern uint8_t dir3; 7 | extern uint8_t dir4; 8 | 9 | 10 | void Basic_Motor::frontlt_CW() { digitalWrite(dir1,HIGH) ; } 11 | void Basic_Motor::frontlt_CCW() { digitalWrite(dir1,LOW) ; } 12 | 13 | void Basic_Motor::frontrt_CW() { digitalWrite(dir2,HIGH) ; } 14 | void Basic_Motor::frontrt_CCW() { digitalWrite(dir2,LOW) ; } 15 | 16 | void Basic_Motor::backlt_CW() { digitalWrite(dir3,LOW) ; } 17 | void Basic_Motor::backlt_CCW() { digitalWrite(dir3,HIGH) ; } 18 | 19 | void Basic_Motor::backrt_CW() { digitalWrite(dir4,LOW) ; } 20 | void Basic_Motor::backrt_CCW() { digitalWrite(dir4,HIGH) ; } 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Test_Program/Basic_Motor.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "Basic_Motor.h" 3 | 4 | extern uint8_t dir1; 5 | extern uint8_t dir2; 6 | extern uint8_t dir3; 7 | extern uint8_t dir4; 8 | 9 | 10 | void Basic_Motor::frontlt_CW() { digitalWrite(dir1,HIGH) ; } 11 | void Basic_Motor::frontlt_CCW() { digitalWrite(dir1,LOW) ; } 12 | 13 | void Basic_Motor::frontrt_CW() { digitalWrite(dir2,HIGH) ; } 14 | void Basic_Motor::frontrt_CCW() { digitalWrite(dir2,LOW) ; } 15 | 16 | void Basic_Motor::backlt_CW() { digitalWrite(dir3,LOW) ; } 17 | void Basic_Motor::backlt_CCW() { digitalWrite(dir3,HIGH) ; } 18 | 19 | void Basic_Motor::backrt_CW() { digitalWrite(dir4,LOW) ; } 20 | void Basic_Motor::backrt_CCW() { digitalWrite(dir4,HIGH) ; } 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/Basic_Motor.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "Basic_Motor.h" 3 | 4 | extern uint8_t dir1; 5 | extern uint8_t dir2; 6 | extern uint8_t dir3; 7 | extern uint8_t dir4; 8 | 9 | 10 | void Basic_Motor::frontlt_CW() { digitalWrite(dir1,HIGH) ; } 11 | void Basic_Motor::frontlt_CCW() { digitalWrite(dir1,LOW) ; } 12 | 13 | void Basic_Motor::frontrt_CW() { digitalWrite(dir2,HIGH) ; } 14 | void Basic_Motor::frontrt_CCW() { digitalWrite(dir2,LOW) ; } 15 | 16 | void Basic_Motor::backlt_CW() { digitalWrite(dir3,LOW) ; } 17 | void Basic_Motor::backlt_CCW() { digitalWrite(dir3,HIGH) ; } 18 | 19 | void Basic_Motor::backrt_CW() { digitalWrite(dir4,LOW) ; } 20 | void Basic_Motor::backrt_CCW() { digitalWrite(dir4,HIGH) ; } 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Test Program/Test_Program/Basic_Motor.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "Basic_Motor.h" 3 | 4 | extern uint8_t dir1; 5 | extern uint8_t dir2; 6 | extern uint8_t dir3; 7 | extern uint8_t dir4; 8 | 9 | 10 | void Basic_Motor::frontlt_CW() { digitalWrite(dir1,HIGH) ; } 11 | void Basic_Motor::frontlt_CCW() { digitalWrite(dir1,LOW) ; } 12 | 13 | void Basic_Motor::frontrt_CW() { digitalWrite(dir2,HIGH) ; } 14 | void Basic_Motor::frontrt_CCW() { digitalWrite(dir2,LOW) ; } 15 | 16 | void Basic_Motor::backlt_CW() { digitalWrite(dir3,LOW) ; } 17 | void Basic_Motor::backlt_CCW() { digitalWrite(dir3,HIGH) ; } 18 | 19 | void Basic_Motor::backrt_CW() { digitalWrite(dir4,LOW) ; } 20 | void Basic_Motor::backrt_CCW() { digitalWrite(dir4,HIGH) ; } 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Test equipments/Test_Program/Basic_Motor.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "Basic_Motor.h" 3 | 4 | extern uint8_t dir1; 5 | extern uint8_t dir2; 6 | extern uint8_t dir3; 7 | extern uint8_t dir4; 8 | 9 | 10 | void Basic_Motor::frontlt_CW() { digitalWrite(dir1,HIGH) ; } 11 | void Basic_Motor::frontlt_CCW() { digitalWrite(dir1,LOW) ; } 12 | 13 | void Basic_Motor::frontrt_CW() { digitalWrite(dir2,HIGH) ; } 14 | void Basic_Motor::frontrt_CCW() { digitalWrite(dir2,LOW) ; } 15 | 16 | void Basic_Motor::backlt_CW() { digitalWrite(dir3,LOW) ; } 17 | void Basic_Motor::backlt_CCW() { digitalWrite(dir3,HIGH) ; } 18 | 19 | void Basic_Motor::backrt_CW() { digitalWrite(dir4,LOW) ; } 20 | void Basic_Motor::backrt_CCW() { digitalWrite(dir4,HIGH) ; } 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Test_Program/joystick.h.bat: -------------------------------------------------------------------------------- 1 | #ifndef _JOYSTICK_H 2 | #define _JOYSTICK_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Arduino.h" 10 | #include "DCmotor.h" 11 | #include "hidjoystickrptparser.h" 12 | 13 | // Satisfy IDE, which only needs to see the include statment in the ino. 14 | #ifdef dobogusinclude 15 | #include 16 | #endif 17 | #include 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | class Motion:public JoystickEvents,public DCMotor { 34 | public: 35 | 36 | uint8_t X1; 37 | uint8_t Y1; 38 | uint8_t X2; 39 | uint8_t X3; 40 | uint8_t Y2; 41 | uint8_t avg; 42 | 43 | void joy(); 44 | void init(); 45 | 46 | }; 47 | 48 | #endif 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/joystick.h.bat: -------------------------------------------------------------------------------- 1 | #ifndef _JOYSTICK_H 2 | #define _JOYSTICK_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Arduino.h" 10 | #include "DCmotor.h" 11 | #include "hidjoystickrptparser.h" 12 | 13 | // Satisfy IDE, which only needs to see the include statment in the ino. 14 | #ifdef dobogusinclude 15 | #include 16 | #endif 17 | #include 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | class Motion:public JoystickEvents,public DCMotor { 34 | public: 35 | 36 | uint8_t X1; 37 | uint8_t Y1; 38 | uint8_t X2; 39 | uint8_t X3; 40 | uint8_t Y2; 41 | uint8_t avg; 42 | 43 | void joy(); 44 | void init(); 45 | 46 | }; 47 | 48 | #endif 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Test Program/Test_Program/joystick.h.bat: -------------------------------------------------------------------------------- 1 | #ifndef _JOYSTICK_H 2 | #define _JOYSTICK_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Arduino.h" 10 | #include "DCmotor.h" 11 | #include "hidjoystickrptparser.h" 12 | 13 | // Satisfy IDE, which only needs to see the include statment in the ino. 14 | #ifdef dobogusinclude 15 | #include 16 | #endif 17 | #include 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | class Motion:public JoystickEvents,public DCMotor { 34 | public: 35 | 36 | uint8_t X1; 37 | uint8_t Y1; 38 | uint8_t X2; 39 | uint8_t X3; 40 | uint8_t Y2; 41 | uint8_t avg; 42 | 43 | void joy(); 44 | void init(); 45 | 46 | }; 47 | 48 | #endif 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /HC05-master/Examples/echo/echo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * echo - echo characters back to bluetooth device 3 | * 4 | * Waits for a connection and then echos each charater received. 5 | * 6 | * Debugging is enabled, so if you open the 'Serial Monitor' you can see 7 | * the search for the HC05 baud and the wait for the BT connection. 8 | */ 9 | #include 10 | #include "HC05.h" 11 | 12 | #ifdef HC05_SOFTWARE_SERIAL 13 | #include 14 | HC05 btSerial = HC05(A2, A5, A3, A4); // cmd, state, rx, tx 15 | #else 16 | HC05 btSerial = HC05(3, 2); // cmd, state 17 | #endif 18 | 19 | void setup() 20 | { 21 | DEBUG_BEGIN(57600); 22 | btSerial.findBaud(); 23 | } 24 | 25 | void loop() 26 | { 27 | btSerial.println("Echo Server- type something"); 28 | 29 | while (btSerial.connected()) 30 | { 31 | if (btSerial.available()) 32 | { 33 | btSerial.write(btSerial.read()); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /autonomous_Secondary/Relay.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "relay.h" 3 | 4 | 5 | void Relay::reinit() 6 | { 7 | pinMode(R11,OUTPUT); 8 | pinMode(R21,OUTPUT); 9 | pinMode(R31,OUTPUT); 10 | pinMode(R41,OUTPUT); 11 | pinMode(R51,OUTPUT); 12 | 13 | 14 | digitalWrite(R11,HIGH); 15 | digitalWrite(R21,HIGH); 16 | digitalWrite(R31,HIGH); 17 | digitalWrite(R41,HIGH); 18 | digitalWrite(R51,HIGH); 19 | 20 | } 21 | 22 | 23 | void Relay::relay(uint8_t ch) 24 | { 25 | switch(ch) 26 | { 27 | case 10 : digitalWrite(R11,HIGH); break; 28 | case 11 : digitalWrite(R11,LOW); break; 29 | case 20 : digitalWrite(R21,HIGH); break; 30 | case 21 : digitalWrite(R21,LOW); break; 31 | case 30 : digitalWrite(R31,HIGH); break; 32 | case 31 : digitalWrite(R31,LOW); break; 33 | case 40 : digitalWrite(R41,HIGH); break; 34 | case 41 : digitalWrite(R41,LOW); break; 35 | case 50 : digitalWrite(R51,HIGH); break; 36 | case 51 : digitalWrite(R51,LOW); break; 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /JoystickControl/joystick.h: -------------------------------------------------------------------------------- 1 | #ifndef _JOYSTICK_H 2 | #define _JOYSTICK_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Arduino.h" 10 | #include "DCmotor.h" 11 | #include "hidjoystickrptparser.h" 12 | 13 | // Satisfy IDE, which only needs to see the include statment in the ino. 14 | #ifdef dobogusinclude 15 | #include 16 | #endif 17 | #include 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | class Motion:public JoystickEvents,public DCMotor { 35 | 36 | 37 | 38 | public: 39 | uint8_t X1; 40 | uint8_t Y1; 41 | uint8_t X2; 42 | uint8_t X3; 43 | uint8_t Y2; 44 | uint8_t threshold; 45 | uint8_t avg; 46 | uint16_t button_read; 47 | uint8_t hat_read; 48 | uint8_t state =0; 49 | 50 | float speed_divisor = 4.0; 51 | 52 | void joy(); 53 | void init(); 54 | void motor_rotation(); 55 | 56 | }; 57 | 58 | #endif 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /HC05-master/Examples/hc05_test/hc05_test.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * hc05_test - Test the disconnect command 3 | * 4 | * When the main loop detects that a bluetooth device is connected it 5 | * disconnects the device. 6 | * 7 | * Montor the progress using the debug port. 8 | */ 9 | #include 10 | #include "HC05.h" 11 | 12 | #ifdef HC05_SOFTWARE_SERIAL 13 | #include 14 | HC05 btSerial = HC05(A2, A5, A3, A4); // cmd, state, rx, tx 15 | #else 16 | HC05 btSerial = HC05(3, 2); // cmd, state 17 | #endif 18 | 19 | #ifdef DEBUG_HC05 20 | #ifdef DEBUG_SW_PORT 21 | extern SoftwareSerial DEBUG_PORT; 22 | #endif 23 | #endif 24 | 25 | void setup() 26 | { 27 | DEBUG_BEGIN(57600); 28 | DEBUG_PRINTLN("Setup"); 29 | delay(3000); // this delay is for debugging convenience only 30 | DEBUG_PRINTLN("DelayComplete"); 31 | btSerial.println(btSerial.findBaud()); 32 | 33 | } 34 | 35 | void loop() 36 | { 37 | if (btSerial.connected()){ 38 | DEBUG_PRINTLN("Connected"); 39 | btSerial.cmd("AT+DISC", 1000); 40 | } 41 | else 42 | { 43 | DEBUG_PRINTLN("Disconnected"); 44 | } 45 | delay(1000); 46 | } 47 | -------------------------------------------------------------------------------- /Test_Program/hidjoystickrptparser.h.bat: -------------------------------------------------------------------------------- 1 | #if !defined(__HIDJOYSTICKRPTPARSER_H__) 2 | #define __HIDJOYSTICKRPTPARSER_H__ 3 | 4 | #include 5 | 6 | struct GamePadEventData { 7 | uint8_t X, Y, Z1, Z2, Rz; 8 | }; 9 | 10 | class JoystickEvents { 11 | public: 12 | virtual void OnGamePadChanged(const GamePadEventData *evt); 13 | virtual void OnHatSwitch(uint8_t hat); 14 | virtual void OnButtonUp(uint8_t but_id); 15 | virtual void OnButtonDn(uint8_t but_id); 16 | 17 | 18 | 19 | uint8_t X1; 20 | uint8_t Y1; 21 | uint8_t X2; 22 | uint8_t X3; 23 | uint8_t Y2; 24 | 25 | }; 26 | 27 | #define RPT_GEMEPAD_LEN 5 28 | 29 | class JoystickReportParser : public HIDReportParser { 30 | JoystickEvents *joyEvents; 31 | 32 | uint8_t oldPad[RPT_GEMEPAD_LEN]; 33 | uint8_t oldHat; 34 | uint16_t oldButtons; 35 | 36 | public: 37 | JoystickReportParser(JoystickEvents *evt); 38 | 39 | virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); 40 | }; 41 | 42 | #endif // __HIDJOYSTICKRPTPARSER_H__ 43 | -------------------------------------------------------------------------------- /HC05-master/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 J.Dunmire 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/hidjoystickrptparser.h.bat: -------------------------------------------------------------------------------- 1 | #if !defined(__HIDJOYSTICKRPTPARSER_H__) 2 | #define __HIDJOYSTICKRPTPARSER_H__ 3 | 4 | #include 5 | 6 | struct GamePadEventData { 7 | uint8_t X, Y, Z1, Z2, Rz; 8 | }; 9 | 10 | class JoystickEvents { 11 | public: 12 | virtual void OnGamePadChanged(const GamePadEventData *evt); 13 | virtual void OnHatSwitch(uint8_t hat); 14 | virtual void OnButtonUp(uint8_t but_id); 15 | virtual void OnButtonDn(uint8_t but_id); 16 | 17 | 18 | 19 | uint8_t X1; 20 | uint8_t Y1; 21 | uint8_t X2; 22 | uint8_t X3; 23 | uint8_t Y2; 24 | 25 | }; 26 | 27 | #define RPT_GEMEPAD_LEN 5 28 | 29 | class JoystickReportParser : public HIDReportParser { 30 | JoystickEvents *joyEvents; 31 | 32 | uint8_t oldPad[RPT_GEMEPAD_LEN]; 33 | uint8_t oldHat; 34 | uint16_t oldButtons; 35 | 36 | public: 37 | JoystickReportParser(JoystickEvents *evt); 38 | 39 | virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); 40 | }; 41 | 42 | #endif // __HIDJOYSTICKRPTPARSER_H__ 43 | -------------------------------------------------------------------------------- /Test Program/Test_Program/hidjoystickrptparser.h.bat: -------------------------------------------------------------------------------- 1 | #if !defined(__HIDJOYSTICKRPTPARSER_H__) 2 | #define __HIDJOYSTICKRPTPARSER_H__ 3 | 4 | #include 5 | 6 | struct GamePadEventData { 7 | uint8_t X, Y, Z1, Z2, Rz; 8 | }; 9 | 10 | class JoystickEvents { 11 | public: 12 | virtual void OnGamePadChanged(const GamePadEventData *evt); 13 | virtual void OnHatSwitch(uint8_t hat); 14 | virtual void OnButtonUp(uint8_t but_id); 15 | virtual void OnButtonDn(uint8_t but_id); 16 | 17 | 18 | 19 | uint8_t X1; 20 | uint8_t Y1; 21 | uint8_t X2; 22 | uint8_t X3; 23 | uint8_t Y2; 24 | 25 | }; 26 | 27 | #define RPT_GEMEPAD_LEN 5 28 | 29 | class JoystickReportParser : public HIDReportParser { 30 | JoystickEvents *joyEvents; 31 | 32 | uint8_t oldPad[RPT_GEMEPAD_LEN]; 33 | uint8_t oldHat; 34 | uint16_t oldButtons; 35 | 36 | public: 37 | JoystickReportParser(JoystickEvents *evt); 38 | 39 | virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); 40 | }; 41 | 42 | #endif // __HIDJOYSTICKRPTPARSER_H__ 43 | -------------------------------------------------------------------------------- /Manual Robot/hidjoystickrptparser.h: -------------------------------------------------------------------------------- 1 | #if !defined(__HIDJOYSTICKRPTPARSER_H__) 2 | #define __HIDJOYSTICKRPTPARSER_H__ 3 | 4 | #include 5 | 6 | struct GamePadEventData { 7 | uint8_t X, Y, Z1, Z2, Rz; 8 | }; 9 | 10 | class JoystickEvents { 11 | public: 12 | virtual void OnGamePadChanged(const GamePadEventData *evt); 13 | virtual void OnHatSwitch(uint8_t hat); 14 | virtual void OnButtonUp(uint8_t but_id); 15 | virtual void OnButtonDn(uint8_t but_id); 16 | 17 | uint16_t button_read = 0; //tejas 18 | uint8_t hat_read = 0; //tejas 19 | 20 | uint8_t X1; 21 | uint8_t Y1; 22 | uint8_t X2; 23 | uint8_t X3; 24 | uint8_t Y2; 25 | 26 | }; 27 | 28 | #define RPT_GEMEPAD_LEN 5 29 | 30 | class JoystickReportParser : public HIDReportParser { 31 | JoystickEvents *joyEvents; 32 | 33 | uint8_t oldPad[RPT_GEMEPAD_LEN]; 34 | uint8_t oldHat; 35 | uint16_t oldButtons; 36 | 37 | public: 38 | JoystickReportParser(JoystickEvents *evt); 39 | 40 | virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); 41 | }; 42 | 43 | #endif // __HIDJOYSTICKRPTPARSER_H__ 44 | -------------------------------------------------------------------------------- /JoystickControl/hidjoystickrptparser.h: -------------------------------------------------------------------------------- 1 | #if !defined(__HIDJOYSTICKRPTPARSER_H__) 2 | #define __HIDJOYSTICKRPTPARSER_H__ 3 | 4 | #include 5 | 6 | struct GamePadEventData { 7 | uint8_t X, Y, Z1, Z2, Rz; 8 | }; 9 | 10 | class JoystickEvents { 11 | public: 12 | virtual void OnGamePadChanged(const GamePadEventData *evt); 13 | virtual void OnHatSwitch(uint8_t hat); 14 | virtual void OnButtonUp(uint8_t but_id); 15 | virtual void OnButtonDn(uint8_t but_id); 16 | 17 | uint16_t button_read = 0; //tejas 18 | uint8_t hat_read = 0; //tejas 19 | 20 | uint8_t X1; 21 | uint8_t Y1; 22 | uint8_t X2; 23 | uint8_t X3; 24 | uint8_t Y2; 25 | 26 | }; 27 | 28 | #define RPT_GEMEPAD_LEN 5 29 | 30 | class JoystickReportParser : public HIDReportParser { 31 | JoystickEvents *joyEvents; 32 | 33 | uint8_t oldPad[RPT_GEMEPAD_LEN]; 34 | uint8_t oldHat; 35 | uint16_t oldButtons; 36 | 37 | public: 38 | JoystickReportParser(JoystickEvents *evt); 39 | 40 | virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); 41 | }; 42 | 43 | #endif // __HIDJOYSTICKRPTPARSER_H__ 44 | -------------------------------------------------------------------------------- /auto_2/Relay.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "relay.h" 3 | 4 | 5 | void Relay::reinit() 6 | { 7 | pinMode(R11,OUTPUT); 8 | pinMode(R21,OUTPUT); 9 | pinMode(R31,OUTPUT); 10 | pinMode(R41,OUTPUT); 11 | 12 | digitalWrite(R11,LOW); 13 | digitalWrite(R21,LOW); 14 | digitalWrite(R31,LOW); 15 | digitalWrite(R41,LOW); 16 | } 17 | 18 | 19 | void Relay::relay(uint8_t ch) 20 | { 21 | switch(ch) 22 | { 23 | case 10 : digitalWrite(R11,HIGH); 24 | Serial.println("relay one low"); 25 | break; 26 | 27 | case 11 : digitalWrite(R11,LOW); 28 | Serial.println("relay one high"); 29 | break; 30 | 31 | case 20 : digitalWrite(R21,HIGH); 32 | Serial.println("relay two low"); 33 | break; 34 | 35 | case 21 : digitalWrite(R21,LOW); 36 | Serial.println("relay two high"); 37 | break; 38 | 39 | case 30 : digitalWrite(R31,HIGH); 40 | Serial.println("relay three low"); 41 | break; 42 | 43 | case 31 :digitalWrite(R31,LOW); 44 | Serial.println("relay three high"); 45 | break; 46 | 47 | case 40 :digitalWrite(R41,HIGH); 48 | Serial.println("relay four low"); 49 | break; 50 | 51 | case 41 :digitalWrite(R41,LOW); 52 | Serial.println("relay four high"); 53 | break; 54 | 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /test/style.css: -------------------------------------------------------------------------------- 1 | body 2 | { 3 | background-image: url("img.jpeg"); 4 | background-repeat: no-repeat; 5 | background-size: cover; 6 | } 7 | 8 | a 9 | { 10 | margin: 100px 0 0 36px; 11 | } 12 | .login 13 | { 14 | 15 | border: 2px solid; 16 | border-radius: 5px; 17 | height: 200px; 18 | margin: 150px 0 auto 400px; 19 | width: 310px; 20 | border-color:#3498DB; 21 | padding-top: 20px; 22 | } 23 | .register 24 | { 25 | 26 | border: 2px solid; 27 | border-radius: 5px; 28 | height: 350px; 29 | margin: 150px 0 auto 400px; 30 | width: 310px; 31 | border-color:#3498DB; 32 | padding-top: 20px; 33 | } 34 | 35 | input[type="password"], input[type="text"] 36 | { 37 | border:1px solid; 38 | background-color:rgba(0,0,0,0.0); 39 | height: 33px; 40 | width:240px; 41 | margin: 2px 0 0 36px; 42 | padding-left: 10px; 43 | 44 | 45 | } 46 | 47 | input[type="submit"] 48 | { 49 | background-color: #4CAF50; 50 | color: white; 51 | height: 42px; 52 | margin: 10px 0 0 36px; 53 | width: 250px; 54 | padding-left: 10px; 55 | } 56 | input[type="submit"]:hover 57 | { 58 | background-image: linear-gradient(#4ec7c0,#31aba3) 59 | } 60 | input[type="submit"]:active 61 | { 62 | background-image: linear-gradient(#319d91, #3db0a6); 63 | padding: 0; 64 | } 65 | -------------------------------------------------------------------------------- /auto_2/auto_2.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "relay.h" 3 | 4 | uint8_t R11 = A8; 5 | uint8_t R21 = A9; 6 | uint8_t R31 = A10; 7 | uint8_t R41 = A11; 8 | 9 | 10 | Relay relay; 11 | Servo myservo; 12 | 13 | void setup() { 14 | Serial.begin(115200); 15 | myservo.attach(10); 16 | 17 | relay.reinit(); 18 | } 19 | 20 | void servoclose() 21 | { 22 | myservo.write(115); 23 | } 24 | 25 | void servoopen() 26 | { 27 | myservo.write(70); 28 | } 29 | 30 | void grab() 31 | { 32 | int a = 0; 33 | while(a == 0) 34 | { 35 | if(digitalRead(8) == LOW || digitalRead(9) == LOW) 36 | { 37 | servoclose(); 38 | a = 1; 39 | } 40 | } 41 | } 42 | 43 | void servorelease() 44 | { 45 | myservo.write(70); 46 | } 47 | 48 | char receivedCharacter; 49 | 50 | void loop() { 51 | 52 | if (Serial.available() > 0) 53 | { 54 | receivedCharacter = Serial.read(); 55 | } 56 | 57 | if (receivedCharacter == 'a') 58 | { 59 | Serial.println("GRAB"); 60 | grab(); 61 | 62 | } 63 | 64 | else if(receivedCharacter == 'b') 65 | { 66 | servorelease(); 67 | Serial.println("RELEASE"); 68 | } 69 | 70 | else if(receivedCharacter == 'c') 71 | { 72 | relay.relay(10); 73 | } 74 | 75 | else if(receivedCharacter == 'd') 76 | { 77 | relay.relay(11); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /JoystickControl/DCmotor.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _DCMOTOR_H 3 | #define _DCMOTOR_H 4 | #include "Arduino.h" 5 | #include "Basic_Motor.h" 6 | 7 | #define k 2 8 | #define d 12 9 | #define ds 90 10 | 11 | 12 | 13 | class encoder{ 14 | public: 15 | volatile uint16_t steps; 16 | volatile float s; 17 | volatile int steps_taken; 18 | int lastencoded = 0; 19 | volatile int encoderValue = 0; 20 | 21 | int step(int a); 22 | int E1(); 23 | }; 24 | 25 | class DCMotor : public Basic_Motor,public encoder { 26 | public: 27 | 28 | 29 | 30 | //decision funtion 31 | uint8_t ssfl, ssfr, ssbl, ssbr,max; 32 | 33 | void motorinit(); 34 | void dcforward(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 35 | void dcreverse(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 36 | void dcleft(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 37 | void dcright(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 38 | void diagonal_flt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 39 | void diagonal_frt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 40 | void diagonal_blt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 41 | void diagonal_brt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 42 | void left_rotation(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 43 | void right_rotation(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 44 | void stopp(); 45 | void rotate(unsigned char direction, uint8_t angle); 46 | }; 47 | 48 | #endif 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /JoystickControl/USBHIDJoystick.ino: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | #include 4 | #include 5 | 6 | // Satisfy IDE, which only needs to see the include statment in the ino. 7 | #ifdef dobogusinclude 8 | #include 9 | #endif 10 | #include 11 | 12 | #include "hidjoystickrptparser.h" 13 | 14 | USB Usb; 15 | USBHub Hub(&Usb); 16 | HIDUniversal Hid(&Usb); 17 | JoystickEvents JoyEvents; 18 | JoystickReportParser Joy(&JoyEvents); 19 | 20 | 21 | 22 | 23 | void setup() { 24 | Serial.begin(115200); 25 | #if !defined(__MIPSEL__) 26 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 27 | #endif 28 | Serial.println("Start"); 29 | 30 | if (Usb.Init() == -1) 31 | Serial.println("OSC did not start."); 32 | 33 | delay(200); 34 | 35 | if (!Hid.SetReportParser(0, &Joy)) 36 | ErrorMessage (PSTR("SetReportParser"), 1); 37 | } 38 | 39 | void loop() { 40 | Usb.Task(); 41 | Serial.print(JoyEvents.X1); 42 | Serial.print("\t"); 43 | Serial.print(JoyEvents.Y1); 44 | Serial.print("\t"); 45 | Serial.print(JoyEvents.X2); 46 | Serial.print("\t"); 47 | Serial.print(JoyEvents.Y2); 48 | Serial.print("\t"); 49 | Serial.print(JoyEvents.X3); 50 | Serial.println(""); 51 | delay(250); 52 | 53 | 54 | Serial.println(""); 55 | 56 | } 57 | */ 58 | -------------------------------------------------------------------------------- /Test_Program/USBHIDJoystick.ino: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | #include 4 | #include 5 | 6 | // Satisfy IDE, which only needs to see the include statment in the ino. 7 | #ifdef dobogusinclude 8 | #include 9 | #endif 10 | #include 11 | 12 | #include "hidjoystickrptparser.h" 13 | 14 | USB Usb; 15 | USBHub Hub(&Usb); 16 | HIDUniversal Hid(&Usb); 17 | JoystickEvents JoyEvents; 18 | JoystickReportParser Joy(&JoyEvents); 19 | 20 | 21 | 22 | 23 | void setup() { 24 | Serial.begin(115200); 25 | #if !defined(__MIPSEL__) 26 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 27 | #endif 28 | Serial.println("Start"); 29 | 30 | if (Usb.Init() == -1) 31 | Serial.println("OSC did not start."); 32 | 33 | delay(200); 34 | 35 | if (!Hid.SetReportParser(0, &Joy)) 36 | ErrorMessage (PSTR("SetReportParser"), 1); 37 | } 38 | 39 | void loop() { 40 | Usb.Task(); 41 | Serial.print(JoyEvents.X1); 42 | Serial.print("\t"); 43 | Serial.print(JoyEvents.Y1); 44 | Serial.print("\t"); 45 | Serial.print(JoyEvents.X2); 46 | Serial.print("\t"); 47 | Serial.print(JoyEvents.Y2); 48 | Serial.print("\t"); 49 | Serial.print(JoyEvents.X3); 50 | Serial.println(""); 51 | delay(250); 52 | 53 | 54 | Serial.println(""); 55 | 56 | } 57 | */ 58 | -------------------------------------------------------------------------------- /Test_Program/USBHIDJoystick.ino.bat: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | #include 4 | #include 5 | 6 | // Satisfy IDE, which only needs to see the include statment in the ino. 7 | #ifdef dobogusinclude 8 | #include 9 | #endif 10 | #include 11 | 12 | #include "hidjoystickrptparser.h" 13 | 14 | USB Usb; 15 | USBHub Hub(&Usb); 16 | HIDUniversal Hid(&Usb); 17 | JoystickEvents JoyEvents; 18 | JoystickReportParser Joy(&JoyEvents); 19 | 20 | 21 | 22 | 23 | void setup() { 24 | Serial.begin(115200); 25 | #if !defined(__MIPSEL__) 26 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 27 | #endif 28 | Serial.println("Start"); 29 | 30 | if (Usb.Init() == -1) 31 | Serial.println("OSC did not start."); 32 | 33 | delay(200); 34 | 35 | if (!Hid.SetReportParser(0, &Joy)) 36 | ErrorMessage (PSTR("SetReportParser"), 1); 37 | } 38 | 39 | void loop() { 40 | Usb.Task(); 41 | Serial.print(JoyEvents.X1); 42 | Serial.print("\t"); 43 | Serial.print(JoyEvents.Y1); 44 | Serial.print("\t"); 45 | Serial.print(JoyEvents.X2); 46 | Serial.print("\t"); 47 | Serial.print(JoyEvents.Y2); 48 | Serial.print("\t"); 49 | Serial.print(JoyEvents.X3); 50 | Serial.println(""); 51 | delay(250); 52 | 53 | 54 | Serial.println(""); 55 | 56 | } 57 | */ 58 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/USBHIDJoystick.ino: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | #include 4 | #include 5 | 6 | // Satisfy IDE, which only needs to see the include statment in the ino. 7 | #ifdef dobogusinclude 8 | #include 9 | #endif 10 | #include 11 | 12 | #include "hidjoystickrptparser.h" 13 | 14 | USB Usb; 15 | USBHub Hub(&Usb); 16 | HIDUniversal Hid(&Usb); 17 | JoystickEvents JoyEvents; 18 | JoystickReportParser Joy(&JoyEvents); 19 | 20 | 21 | 22 | 23 | void setup() { 24 | Serial.begin(115200); 25 | #if !defined(__MIPSEL__) 26 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 27 | #endif 28 | Serial.println("Start"); 29 | 30 | if (Usb.Init() == -1) 31 | Serial.println("OSC did not start."); 32 | 33 | delay(200); 34 | 35 | if (!Hid.SetReportParser(0, &Joy)) 36 | ErrorMessage (PSTR("SetReportParser"), 1); 37 | } 38 | 39 | void loop() { 40 | Usb.Task(); 41 | Serial.print(JoyEvents.X1); 42 | Serial.print("\t"); 43 | Serial.print(JoyEvents.Y1); 44 | Serial.print("\t"); 45 | Serial.print(JoyEvents.X2); 46 | Serial.print("\t"); 47 | Serial.print(JoyEvents.Y2); 48 | Serial.print("\t"); 49 | Serial.print(JoyEvents.X3); 50 | Serial.println(""); 51 | delay(250); 52 | 53 | 54 | Serial.println(""); 55 | 56 | } 57 | */ 58 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/USBHIDJoystick.ino.bat: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | #include 4 | #include 5 | 6 | // Satisfy IDE, which only needs to see the include statment in the ino. 7 | #ifdef dobogusinclude 8 | #include 9 | #endif 10 | #include 11 | 12 | #include "hidjoystickrptparser.h" 13 | 14 | USB Usb; 15 | USBHub Hub(&Usb); 16 | HIDUniversal Hid(&Usb); 17 | JoystickEvents JoyEvents; 18 | JoystickReportParser Joy(&JoyEvents); 19 | 20 | 21 | 22 | 23 | void setup() { 24 | Serial.begin(115200); 25 | #if !defined(__MIPSEL__) 26 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 27 | #endif 28 | Serial.println("Start"); 29 | 30 | if (Usb.Init() == -1) 31 | Serial.println("OSC did not start."); 32 | 33 | delay(200); 34 | 35 | if (!Hid.SetReportParser(0, &Joy)) 36 | ErrorMessage (PSTR("SetReportParser"), 1); 37 | } 38 | 39 | void loop() { 40 | Usb.Task(); 41 | Serial.print(JoyEvents.X1); 42 | Serial.print("\t"); 43 | Serial.print(JoyEvents.Y1); 44 | Serial.print("\t"); 45 | Serial.print(JoyEvents.X2); 46 | Serial.print("\t"); 47 | Serial.print(JoyEvents.Y2); 48 | Serial.print("\t"); 49 | Serial.print(JoyEvents.X3); 50 | Serial.println(""); 51 | delay(250); 52 | 53 | 54 | Serial.println(""); 55 | 56 | } 57 | */ 58 | -------------------------------------------------------------------------------- /Test Program/Test_Program/USBHIDJoystick.ino: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | #include 4 | #include 5 | 6 | // Satisfy IDE, which only needs to see the include statment in the ino. 7 | #ifdef dobogusinclude 8 | #include 9 | #endif 10 | #include 11 | 12 | #include "hidjoystickrptparser.h" 13 | 14 | USB Usb; 15 | USBHub Hub(&Usb); 16 | HIDUniversal Hid(&Usb); 17 | JoystickEvents JoyEvents; 18 | JoystickReportParser Joy(&JoyEvents); 19 | 20 | 21 | 22 | 23 | void setup() { 24 | Serial.begin(115200); 25 | #if !defined(__MIPSEL__) 26 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 27 | #endif 28 | Serial.println("Start"); 29 | 30 | if (Usb.Init() == -1) 31 | Serial.println("OSC did not start."); 32 | 33 | delay(200); 34 | 35 | if (!Hid.SetReportParser(0, &Joy)) 36 | ErrorMessage (PSTR("SetReportParser"), 1); 37 | } 38 | 39 | void loop() { 40 | Usb.Task(); 41 | Serial.print(JoyEvents.X1); 42 | Serial.print("\t"); 43 | Serial.print(JoyEvents.Y1); 44 | Serial.print("\t"); 45 | Serial.print(JoyEvents.X2); 46 | Serial.print("\t"); 47 | Serial.print(JoyEvents.Y2); 48 | Serial.print("\t"); 49 | Serial.print(JoyEvents.X3); 50 | Serial.println(""); 51 | delay(250); 52 | 53 | 54 | Serial.println(""); 55 | 56 | } 57 | */ 58 | -------------------------------------------------------------------------------- /Test Program/Test_Program/USBHIDJoystick.ino.bat: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | #include 4 | #include 5 | 6 | // Satisfy IDE, which only needs to see the include statment in the ino. 7 | #ifdef dobogusinclude 8 | #include 9 | #endif 10 | #include 11 | 12 | #include "hidjoystickrptparser.h" 13 | 14 | USB Usb; 15 | USBHub Hub(&Usb); 16 | HIDUniversal Hid(&Usb); 17 | JoystickEvents JoyEvents; 18 | JoystickReportParser Joy(&JoyEvents); 19 | 20 | 21 | 22 | 23 | void setup() { 24 | Serial.begin(115200); 25 | #if !defined(__MIPSEL__) 26 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 27 | #endif 28 | Serial.println("Start"); 29 | 30 | if (Usb.Init() == -1) 31 | Serial.println("OSC did not start."); 32 | 33 | delay(200); 34 | 35 | if (!Hid.SetReportParser(0, &Joy)) 36 | ErrorMessage (PSTR("SetReportParser"), 1); 37 | } 38 | 39 | void loop() { 40 | Usb.Task(); 41 | Serial.print(JoyEvents.X1); 42 | Serial.print("\t"); 43 | Serial.print(JoyEvents.Y1); 44 | Serial.print("\t"); 45 | Serial.print(JoyEvents.X2); 46 | Serial.print("\t"); 47 | Serial.print(JoyEvents.Y2); 48 | Serial.print("\t"); 49 | Serial.print(JoyEvents.X3); 50 | Serial.println(""); 51 | delay(250); 52 | 53 | 54 | Serial.println(""); 55 | 56 | } 57 | */ 58 | -------------------------------------------------------------------------------- /Test equipments/Test_Program/DCmotor.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _DCMOTOR_H 3 | #define _DCMOTOR_H 4 | #include "Arduino.h" 5 | #include "Basic_Motor.h" 6 | 7 | #define k 2 8 | #define d 12 9 | #define ds 90 10 | 11 | 12 | 13 | class encoder{ 14 | public: 15 | volatile uint16_t steps; 16 | volatile float s; 17 | volatile int steps_taken; 18 | int lastencoded = 0; 19 | volatile int encoderValue = 0; 20 | 21 | int step(int a); 22 | int E1(); 23 | }; 24 | 25 | class DCMotor : public Basic_Motor,public encoder { 26 | public: 27 | 28 | 29 | 30 | //decision funtion 31 | uint8_t ssfl, ssfr, ssbl, ssbr,max; 32 | 33 | void motorinit(); 34 | void dcforward(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 35 | void dcreverse(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 36 | void dcleft(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 37 | void dcright(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 38 | void diagonal_flt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 39 | void diagonal_frt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 40 | void diagonal_blt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 41 | void diagonal_brt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 42 | void left_rotation(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 43 | void right_rotation(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 44 | void stop(); 45 | void stop1(); 46 | void rotate(unsigned char direction, uint8_t angle); 47 | void rotate1(unsigned char direction, uint16_t steps); 48 | }; 49 | 50 | #endif 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Test_Program/DCmotor.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _DCMOTOR_H 3 | #define _DCMOTOR_H 4 | #include "Arduino.h" 5 | #include "Basic_Motor.h" 6 | 7 | #define k 1 8 | #define d 20 9 | #define ds 15 10 | #define d1 30 11 | 12 | 13 | 14 | class encoder{ 15 | public: 16 | volatile uint16_t steps; 17 | volatile float s; 18 | volatile int steps_taken; 19 | int lastencoded = 0; 20 | volatile int encoderValue = 0; 21 | 22 | int step(int a); 23 | int E1(); 24 | 25 | 26 | 27 | /*volatile int count = 0;//new Encodder test program 28 | int speed = 0;//new Encodder test program 29 | int flag = 0;//new Encodder test program 30 | 31 | 32 | volatile int lastEncoded = 0;//new Encodder test program 33 | volatile long encoderValue = 0;//new Encodder test program*/ 34 | }; 35 | 36 | class DCMotor : public Basic_Motor,public encoder { 37 | public: 38 | 39 | 40 | 41 | //decision funtion 42 | uint8_t ssfl, ssfr, ssbl, ssbr,max; 43 | 44 | void motorinit(); 45 | void dcforward(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 46 | void dcreverse(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 47 | void dcleft(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 48 | void dcright(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 49 | void diagonal_flt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 50 | void diagonal_frt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 51 | void diagonal_blt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 52 | void diagonal_brt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 53 | void right_rotation(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 54 | void left_rotation(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 55 | void stop(); 56 | void stop1(); 57 | void rotate(unsigned char direction, uint8_t angle); 58 | void rotate1(unsigned char direction, uint16_t steps); 59 | void Left_Rot_sensor(uint8_t dir , uint8_t sfl , uint8_t sbl); // Omkar 60 | }; 61 | 62 | #endif 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/DCmotor.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _DCMOTOR_H 3 | #define _DCMOTOR_H 4 | #include "Arduino.h" 5 | #include "Basic_Motor.h" 6 | 7 | #define k 1 8 | #define d 20 9 | #define ds 15 10 | #define d1 30 11 | 12 | 13 | 14 | class encoder{ 15 | public: 16 | volatile uint16_t steps; 17 | volatile float s; 18 | volatile int steps_taken; 19 | int lastencoded = 0; 20 | volatile int encoderValue = 0; 21 | 22 | int step(int a); 23 | int E1(); 24 | 25 | 26 | 27 | /*volatile int count = 0;//new Encodder test program 28 | int speed = 0;//new Encodder test program 29 | int flag = 0;//new Encodder test program 30 | 31 | 32 | volatile int lastEncoded = 0;//new Encodder test program 33 | volatile long encoderValue = 0;//new Encodder test program*/ 34 | }; 35 | 36 | class DCMotor : public Basic_Motor,public encoder { 37 | public: 38 | 39 | 40 | 41 | //decision funtion 42 | uint8_t ssfl, ssfr, ssbl, ssbr,max; 43 | 44 | void motorinit(); 45 | void dcforward(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 46 | void dcreverse(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 47 | void dcleft(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 48 | void dcright(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 49 | void diagonal_flt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 50 | void diagonal_frt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 51 | void diagonal_blt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 52 | void diagonal_brt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 53 | void right_rotation(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 54 | void left_rotation(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 55 | void stop(); 56 | void stop1(); 57 | void rotate(unsigned char direction, uint8_t angle); 58 | void rotate1(unsigned char direction, uint16_t steps); 59 | void Left_Rot_sensor(uint8_t dir , uint8_t sfl , uint8_t sbl); // Omkar 60 | }; 61 | 62 | #endif 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Test Program/Test_Program/DCmotor.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _DCMOTOR_H 3 | #define _DCMOTOR_H 4 | #include "Arduino.h" 5 | #include "Basic_Motor.h" 6 | 7 | #define k 1 8 | #define d 20 9 | #define ds 15 10 | #define d1 30 11 | 12 | 13 | 14 | class encoder{ 15 | public: 16 | volatile uint16_t steps; 17 | volatile float s; 18 | volatile int steps_taken; 19 | int lastencoded = 0; 20 | volatile int encoderValue = 0; 21 | 22 | int step(int a); 23 | int E1(); 24 | 25 | 26 | 27 | /*volatile int count = 0;//new Encodder test program 28 | int speed = 0;//new Encodder test program 29 | int flag = 0;//new Encodder test program 30 | 31 | 32 | volatile int lastEncoded = 0;//new Encodder test program 33 | volatile long encoderValue = 0;//new Encodder test program*/ 34 | }; 35 | 36 | class DCMotor : public Basic_Motor,public encoder { 37 | public: 38 | 39 | 40 | 41 | //decision funtion 42 | uint8_t ssfl, ssfr, ssbl, ssbr,max; 43 | 44 | void motorinit(); 45 | void dcforward(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 46 | void dcreverse(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 47 | void dcleft(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 48 | void dcright(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 49 | void diagonal_flt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 50 | void diagonal_frt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 51 | void diagonal_blt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 52 | void diagonal_brt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 53 | void right_rotation(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 54 | void left_rotation(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr); 55 | void stop(); 56 | void stop1(); 57 | void rotate(unsigned char direction, uint8_t angle); 58 | void rotate1(unsigned char direction, uint16_t steps); 59 | void Left_Rot_sensor(uint8_t dir , uint8_t sfl , uint8_t sbl); // Omkar 60 | }; 61 | 62 | #endif 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Test_Program/Sensor1.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "arduino.h" 3 | #include "Sensor1.h" 4 | 5 | 6 | 7 | linesensor::linesensor(uint8_t a1 , uint8_t a2 , uint8_t a3 , uint8_t a4 , uint8_t a5 , uint8_t a6 , uint8_t a7 , uint8_t a8) 8 | { 9 | l1=a1; l2=a2; l3=a3; l4=a4; l5=a5; l6=a6; l7=a7; l8=a8; 10 | 11 | pinMode(a1,INPUT); 12 | pinMode(a2,INPUT); 13 | pinMode(a3,INPUT); 14 | pinMode(a4,INPUT); 15 | pinMode(a5,INPUT); 16 | pinMode(a6,INPUT); 17 | pinMode(a7,INPUT); 18 | pinMode(a8,INPUT); 19 | } 20 | 21 | uint8_t linesensor::readsensor() 22 | { 23 | uint8_t read = 0; 24 | if(digitalRead(l1) == HIGH) 25 | { 26 | read |= (1<<0); 27 | Serial.println("L1 HIGH"); 28 | } 29 | else 30 | { 31 | read &= ~(1<<0); 32 | } 33 | 34 | if(digitalRead(l2)==HIGH) 35 | { 36 | read |= (1<<1); 37 | Serial.println("L2 HIGH"); 38 | } 39 | else 40 | { 41 | read &= ~(1<<1); 42 | } 43 | 44 | if(digitalRead(l3)==HIGH) 45 | { 46 | read |= (1<<2); 47 | Serial.println("L3 HIGH"); 48 | } 49 | else 50 | { 51 | read &= ~(1<<2); 52 | } 53 | 54 | if(digitalRead(l4)==HIGH) 55 | { 56 | read |= (1<<3); 57 | Serial.println("L4 HIGH"); 58 | } 59 | else 60 | { 61 | read &= ~(1<<3); 62 | } 63 | 64 | if(digitalRead(l5)==HIGH) 65 | { 66 | read |= (1<<4); 67 | Serial.println("L5 HIGH"); 68 | } 69 | else 70 | { 71 | read &= ~(1<<4); 72 | } 73 | 74 | if(digitalRead(l6)==HIGH) 75 | { 76 | read |= (1<<5); 77 | Serial.println("L6 HIGH"); 78 | } 79 | else 80 | { 81 | read &= ~(1<<5); 82 | } 83 | 84 | if(digitalRead(l7)== HIGH) 85 | { 86 | read |= (1<<6); 87 | Serial.println("L7 HIGH"); 88 | } 89 | else 90 | { 91 | read &= ~(1<<6); 92 | } 93 | 94 | if(digitalRead(l8)== HIGH) 95 | { 96 | read |= (1<<7); 97 | Serial.println("L8 HIGH"); 98 | } 99 | else 100 | { 101 | read &= ~(1<<7); 102 | } 103 | 104 | 105 | return (read); 106 | } 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /Test_Program/Encoder_Test_program.ino: -------------------------------------------------------------------------------- 1 | 2 | /*volatile int count = 0; 3 | int speed = 0; 4 | int flag = 0; 5 | 6 | 7 | volatile int lastEncoded = 0; 8 | volatile long encoderValue = 0; 9 | 10 | 11 | void updateEncoder(){ 12 | int MSB = digitalRead(2); //MSB = most significant bit 13 | int LSB = digitalRead(3); //LSB = least significant bit 14 | 15 | int encoded = (MSB << 1) |LSB; //converting the 2 pin value to single number 16 | int sum = (lastEncoded << 2) | encoded; //adding it to the previous encoded value 17 | 18 | if(sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) count ++; 19 | if(sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) count --; 20 | 21 | lastEncoded = encoded; //store this value for next time 22 | } 23 | 24 | 25 | void encoder() 26 | { 27 | 28 | updateEncoder(); 29 | } 30 | void setup() { 31 | Serial.begin(115200); 32 | pinMode(5,OUTPUT); 33 | digitalWrite(5,LOW); 34 | pinMode(2,INPUT); 35 | pinMode(3,INPUT); 36 | 37 | digitalWrite(2, HIGH); //turn pullup resistor on 38 | digitalWrite(3, HIGH); //turn pullup resistor on 39 | 40 | attachInterrupt(digitalPinToInterrupt(2),encoder, LOW); 41 | } 42 | 43 | void loop() { 44 | Serial.print("count = "); 45 | Serial.println(count); 46 | if (Serial.available()) 47 | { 48 | char a = Serial.read(); 49 | switch(a) 50 | { 51 | case 'a': 52 | speed+=5; 53 | analogWrite(4,speed); 54 | Serial.println(speed); 55 | break; 56 | 57 | case 's': 58 | speed-=5; 59 | analogWrite(4,speed); 60 | Serial.println(speed); 61 | break; 62 | 63 | case 'z': 64 | count = 0; 65 | break; 66 | 67 | case 't': 68 | //analogWrite(4,0); 69 | flag = 0; 70 | digitalWrite(5,LOW); 71 | break; 72 | 73 | case 'g': 74 | //analogWrite(4,0); 75 | flag = 1; 76 | digitalWrite(5,HIGH); 77 | break; 78 | } 79 | } 80 | 81 | delay(100); 82 | }*/ 83 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/Sensor1.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "arduino.h" 3 | #include "Sensor1.h" 4 | 5 | 6 | 7 | linesensor::linesensor(uint8_t a1 , uint8_t a2 , uint8_t a3 , uint8_t a4 , uint8_t a5 , uint8_t a6 , uint8_t a7 , uint8_t a8) 8 | { 9 | l1=a1; l2=a2; l3=a3; l4=a4; l5=a5; l6=a6; l7=a7; l8=a8; 10 | 11 | pinMode(a1,INPUT); 12 | pinMode(a2,INPUT); 13 | pinMode(a3,INPUT); 14 | pinMode(a4,INPUT); 15 | pinMode(a5,INPUT); 16 | pinMode(a6,INPUT); 17 | pinMode(a7,INPUT); 18 | pinMode(a8,INPUT); 19 | } 20 | 21 | uint8_t linesensor::readsensor() 22 | { 23 | uint8_t read = 0; 24 | if(digitalRead(l1) == HIGH) 25 | { 26 | read |= (1<<0); 27 | Serial.println("L1 HIGH"); 28 | } 29 | else 30 | { 31 | read &= ~(1<<0); 32 | } 33 | 34 | if(digitalRead(l2)==HIGH) 35 | { 36 | read |= (1<<1); 37 | Serial.println("L2 HIGH"); 38 | } 39 | else 40 | { 41 | read &= ~(1<<1); 42 | } 43 | 44 | if(digitalRead(l3)==HIGH) 45 | { 46 | read |= (1<<2); 47 | Serial.println("L3 HIGH"); 48 | } 49 | else 50 | { 51 | read &= ~(1<<2); 52 | } 53 | 54 | if(digitalRead(l4)==HIGH) 55 | { 56 | read |= (1<<3); 57 | Serial.println("L4 HIGH"); 58 | } 59 | else 60 | { 61 | read &= ~(1<<3); 62 | } 63 | 64 | if(digitalRead(l5)==HIGH) 65 | { 66 | read |= (1<<4); 67 | Serial.println("L5 HIGH"); 68 | } 69 | else 70 | { 71 | read &= ~(1<<4); 72 | } 73 | 74 | if(digitalRead(l6)==HIGH) 75 | { 76 | read |= (1<<5); 77 | Serial.println("L6 HIGH"); 78 | } 79 | else 80 | { 81 | read &= ~(1<<5); 82 | } 83 | 84 | if(digitalRead(l7)== HIGH) 85 | { 86 | read |= (1<<6); 87 | Serial.println("L7 HIGH"); 88 | } 89 | else 90 | { 91 | read &= ~(1<<6); 92 | } 93 | 94 | if(digitalRead(l8)== HIGH) 95 | { 96 | read |= (1<<7); 97 | Serial.println("L8 HIGH"); 98 | } 99 | else 100 | { 101 | read &= ~(1<<7); 102 | } 103 | 104 | 105 | return (read); 106 | } 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/Encoder_Test_program.ino: -------------------------------------------------------------------------------- 1 | 2 | /*volatile int count = 0; 3 | int speed = 0; 4 | int flag = 0; 5 | 6 | 7 | volatile int lastEncoded = 0; 8 | volatile long encoderValue = 0; 9 | 10 | 11 | void updateEncoder(){ 12 | int MSB = digitalRead(2); //MSB = most significant bit 13 | int LSB = digitalRead(3); //LSB = least significant bit 14 | 15 | int encoded = (MSB << 1) |LSB; //converting the 2 pin value to single number 16 | int sum = (lastEncoded << 2) | encoded; //adding it to the previous encoded value 17 | 18 | if(sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) count ++; 19 | if(sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) count --; 20 | 21 | lastEncoded = encoded; //store this value for next time 22 | } 23 | 24 | 25 | void encoder() 26 | { 27 | 28 | updateEncoder(); 29 | } 30 | void setup() { 31 | Serial.begin(115200); 32 | pinMode(5,OUTPUT); 33 | digitalWrite(5,LOW); 34 | pinMode(2,INPUT); 35 | pinMode(3,INPUT); 36 | 37 | digitalWrite(2, HIGH); //turn pullup resistor on 38 | digitalWrite(3, HIGH); //turn pullup resistor on 39 | 40 | attachInterrupt(digitalPinToInterrupt(2),encoder, LOW); 41 | } 42 | 43 | void loop() { 44 | Serial.print("count = "); 45 | Serial.println(count); 46 | if (Serial.available()) 47 | { 48 | char a = Serial.read(); 49 | switch(a) 50 | { 51 | case 'a': 52 | speed+=5; 53 | analogWrite(4,speed); 54 | Serial.println(speed); 55 | break; 56 | 57 | case 's': 58 | speed-=5; 59 | analogWrite(4,speed); 60 | Serial.println(speed); 61 | break; 62 | 63 | case 'z': 64 | count = 0; 65 | break; 66 | 67 | case 't': 68 | //analogWrite(4,0); 69 | flag = 0; 70 | digitalWrite(5,LOW); 71 | break; 72 | 73 | case 'g': 74 | //analogWrite(4,0); 75 | flag = 1; 76 | digitalWrite(5,HIGH); 77 | break; 78 | } 79 | } 80 | 81 | delay(100); 82 | }*/ 83 | -------------------------------------------------------------------------------- /Test Program/Test_Program/Encoder_Test_program.ino: -------------------------------------------------------------------------------- 1 | 2 | /*volatile int count = 0; 3 | int speed = 0; 4 | int flag = 0; 5 | 6 | 7 | volatile int lastEncoded = 0; 8 | volatile long encoderValue = 0; 9 | 10 | 11 | void updateEncoder(){ 12 | int MSB = digitalRead(2); //MSB = most significant bit 13 | int LSB = digitalRead(3); //LSB = least significant bit 14 | 15 | int encoded = (MSB << 1) |LSB; //converting the 2 pin value to single number 16 | int sum = (lastEncoded << 2) | encoded; //adding it to the previous encoded value 17 | 18 | if(sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) count ++; 19 | if(sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) count --; 20 | 21 | lastEncoded = encoded; //store this value for next time 22 | } 23 | 24 | 25 | void encoder() 26 | { 27 | 28 | updateEncoder(); 29 | } 30 | void setup() { 31 | Serial.begin(115200); 32 | pinMode(5,OUTPUT); 33 | digitalWrite(5,LOW); 34 | pinMode(2,INPUT); 35 | pinMode(3,INPUT); 36 | 37 | digitalWrite(2, HIGH); //turn pullup resistor on 38 | digitalWrite(3, HIGH); //turn pullup resistor on 39 | 40 | attachInterrupt(digitalPinToInterrupt(2),encoder, LOW); 41 | } 42 | 43 | void loop() { 44 | Serial.print("count = "); 45 | Serial.println(count); 46 | if (Serial.available()) 47 | { 48 | char a = Serial.read(); 49 | switch(a) 50 | { 51 | case 'a': 52 | speed+=5; 53 | analogWrite(4,speed); 54 | Serial.println(speed); 55 | break; 56 | 57 | case 's': 58 | speed-=5; 59 | analogWrite(4,speed); 60 | Serial.println(speed); 61 | break; 62 | 63 | case 'z': 64 | count = 0; 65 | break; 66 | 67 | case 't': 68 | //analogWrite(4,0); 69 | flag = 0; 70 | digitalWrite(5,LOW); 71 | break; 72 | 73 | case 'g': 74 | //analogWrite(4,0); 75 | flag = 1; 76 | digitalWrite(5,HIGH); 77 | break; 78 | } 79 | } 80 | 81 | delay(100); 82 | }*/ 83 | -------------------------------------------------------------------------------- /Test Program/Test_Program/Sensor1.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "arduino.h" 3 | #include "Sensor1.h" 4 | 5 | 6 | 7 | linesensor::linesensor(uint8_t a1 , uint8_t a2 , uint8_t a3 , uint8_t a4 , uint8_t a5 , uint8_t a6 , uint8_t a7 , uint8_t a8) 8 | { 9 | l1=a1; l2=a2; l3=a3; l4=a4; l5=a5; l6=a6; l7=a7; l8=a8; 10 | 11 | pinMode(a1,INPUT); 12 | pinMode(a2,INPUT); 13 | pinMode(a3,INPUT); 14 | pinMode(a4,INPUT); 15 | pinMode(a5,INPUT); 16 | pinMode(a6,INPUT); 17 | pinMode(a7,INPUT); 18 | pinMode(a8,INPUT); 19 | } 20 | 21 | uint8_t linesensor::readsensor() 22 | { 23 | uint8_t read = 0; 24 | if(digitalRead(l1) == HIGH) 25 | { 26 | read |= (1<<0); 27 | Serial.println("L1 HIGH"); 28 | } 29 | else 30 | { 31 | read &= ~(1<<0); 32 | } 33 | 34 | if(digitalRead(l2)==HIGH) 35 | { 36 | read |= (1<<1); 37 | Serial.println("L2 HIGH"); 38 | } 39 | else 40 | { 41 | read &= ~(1<<1); 42 | } 43 | 44 | if(digitalRead(l3)==HIGH) 45 | { 46 | read |= (1<<2); 47 | Serial.println("L3 HIGH"); 48 | } 49 | else 50 | { 51 | read &= ~(1<<2); 52 | } 53 | 54 | if(digitalRead(l4)==HIGH) 55 | { 56 | read |= (1<<3); 57 | Serial.println("L4 HIGH"); 58 | } 59 | else 60 | { 61 | read &= ~(1<<3); 62 | } 63 | 64 | if(digitalRead(l5)==HIGH) 65 | { 66 | read |= (1<<4); 67 | Serial.println("L5 HIGH"); 68 | } 69 | else 70 | { 71 | read &= ~(1<<4); 72 | } 73 | 74 | if(digitalRead(l6)==HIGH) 75 | { 76 | read |= (1<<5); 77 | Serial.println("L6 HIGH"); 78 | } 79 | else 80 | { 81 | read &= ~(1<<5); 82 | } 83 | 84 | if(digitalRead(l7)== HIGH) 85 | { 86 | read |= (1<<6); 87 | Serial.println("L7 HIGH"); 88 | } 89 | else 90 | { 91 | read &= ~(1<<6); 92 | } 93 | 94 | if(digitalRead(l8)== HIGH) 95 | { 96 | read |= (1<<7); 97 | Serial.println("L8 HIGH"); 98 | } 99 | else 100 | { 101 | read &= ~(1<<7); 102 | } 103 | 104 | 105 | return (read); 106 | } 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /Test equipments/Test_Program/Test_Program.ino: -------------------------------------------------------------------------------- 1 | 2 | #include "def.h" 3 | #include "DCmotor.h" 4 | 5 | char data = 0; 6 | 7 | void setup() 8 | { 9 | mymotor.motorinit(); // Motor initalization 10 | Serial.begin(115200); 11 | } 12 | 13 | 14 | void loop() 15 | { 16 | 17 | //char data = 0; 18 | if(Serial.available() > 0) // Send data only when you receive data: 19 | { 20 | data = Serial.read(); //Read the incoming data & store into data 21 | Serial1.println(data); //Print Value inside data in Serial monitor 22 | Serial.println(data); 23 | switch(data) 24 | { 25 | case '1':mymotor.dcforward(70,70,70,70); // 26 | Serial1.println("Moving Forward"); 27 | Serial.println("Moving Forward"); 28 | break; 29 | case '2': mymotor.dcreverse(70,70,70,70); // 30 | Serial1.println("Moving Reverse"); 31 | Serial.println("Moving Reverse"); 32 | break; 33 | case '3': mymotor.left_rotation(70,70,70,70); // 34 | Serial1.println("Left rotation"); 35 | Serial.println("Left rotation"); 36 | break; 37 | case '4': mymotor.right_rotation(70,70,70,70); // 38 | Serial1.println("Right Rotation"); 39 | Serial.println("Right Rotation"); 40 | break; 41 | case '5': mymotor.dcleft(70,70,70,70); // 42 | Serial1.println("Moving left"); 43 | Serial.println("Moving left"); 44 | break; 45 | case '6': mymotor.dcright(70,70,70,70); // 46 | Serial1.println(" Moving Right"); 47 | Serial.println(" Moving Right"); 48 | break; 49 | } 50 | } 51 | 52 | 53 | delay(2000); 54 | mymotor.stop(); 55 | 56 | } 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /HC05-master/Examples/recover/recover.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * recover - recover from forgotten serial settings 3 | * 4 | * Uses cmdMode2 to set the HC05 to 19200 baud, no parity, ones stop bit 5 | * (19200N1). 19200N1 is supported by both the hardware and software 6 | * serial ports on the Arduino. 7 | * 8 | * Debugging is enabled, so if you open the 'Serial Monitor' you can see 9 | * the process. Note that if you don't get the 'Serial Monitor' open 10 | * before the 'AT+UART=' command is issued, you will not really see the 11 | * old settings. There is a three second delay at the beginning to give 12 | * you a chance to get the serial monitor running. 13 | * 14 | * The `Serial Monitor` should be set to 57600 baud. 15 | * 16 | */ 17 | #include 18 | #include "HC05.h" 19 | 20 | #ifdef HC05_SOFTWARE_SERIAL 21 | #include 22 | HC05 btSerial = HC05(A2, A5, A3, A4); // cmd, state, rx, tx 23 | #else 24 | HC05 btSerial = HC05(3, 2); // cmd, state 25 | #endif 26 | 27 | int powerPin = 7; 28 | 29 | void setup() 30 | { 31 | DEBUG_BEGIN(57600); 32 | DEBUG_PRINTLN("Starting recovery in 3 seconds."); 33 | btSerial.cmdMode2Start(powerPin); 34 | 35 | // Provide some time for the user to start the serial monitor 36 | delay(3000); 37 | 38 | // For curiosity's sake, ask for the old settings 39 | btSerial.cmd("AT+UART?"); 40 | 41 | // Now set the baud to 19200N1 42 | btSerial.cmd("AT+UART=19200,0,0"); 43 | 44 | // Exit command mode and switch to the new baud setting 45 | btSerial.cmd("AT+RESET"); 46 | btSerial.cmdMode2End(); 47 | } 48 | 49 | 50 | void loop() 51 | { 52 | int c; 53 | unsigned long rate; 54 | rate = btSerial.findBaud(); 55 | 56 | DEBUG_PRINTLN(""); 57 | 58 | if (rate == 19200) 59 | { 60 | DEBUG_PRINTLN("Recovery successful. HC05 serial settings = 19200N1"); 61 | } 62 | else 63 | { 64 | DEBUG_PRINT("Recovery failed. Did you connect HC05 power to pin "); 65 | DEBUG_PRINT(powerPin); 66 | DEBUG_PRINTLN("?"); 67 | } 68 | while (true) 69 | { 70 | ; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /test/addentry.php: -------------------------------------------------------------------------------- 1 | preserveWhiteSpace = false; 4 | $xmldoc->formatOutput = true; 5 | 6 | $name = $_POST['username']; 7 | $pass = $_POST['password']; 8 | $mobile = $_POST['mobile']; 9 | $email = $_POST['email']; 10 | $age = $_POST['age']; 11 | 12 | if( $xml = file_get_contents( 'database.xml') ) { 13 | $xmldoc->loadXML( $xml, LIBXML_NOBLANKS ); 14 | 15 | // find the headercontent tag 16 | $root = $xmldoc->getElementsByTagName('profile')->item(0); 17 | 18 | // create the tag 19 | $account = $xmldoc->createElement('account'); 20 | 21 | 22 | // add the product tag before the first element in the tag 23 | $root->insertBefore( $account, $root->lastChild ); 24 | 25 | // create other elements and add it to the tag. 26 | $nameElement = $xmldoc->createElement('name'); 27 | $account->appendChild($nameElement); 28 | $nameText = $xmldoc->createTextNode($name); 29 | $nameElement->appendChild($nameText); 30 | 31 | $passElement = $xmldoc->createElement('pass'); 32 | $account->appendChild($passElement); 33 | $passText = $xmldoc->createTextNode($pass); 34 | $passElement->appendChild($passText); 35 | 36 | $emailElement = $xmldoc->createElement('email'); 37 | $account->appendChild($emailElement); 38 | $emailText = $xmldoc->createTextNode($email); 39 | $emailElement->appendChild($emailText); 40 | 41 | $mobileElement = $xmldoc->createElement('mobile'); 42 | $account->appendChild($mobileElement); 43 | $mobileText = $xmldoc->createTextNode($mobile); 44 | $mobileElement->appendChild($mobileText); 45 | 46 | $ageElement = $xmldoc->createElement('age'); 47 | $account->appendChild($ageElement); 48 | $ageText = $xmldoc->createTextNode($age); 49 | $ageElement->appendChild($ageText); 50 | 51 | 52 | $xmldoc->save('database.xml'); 53 | } 54 | ?> 55 | 56 | 57 | 58 |

You are Successfully Register pleasego to Login page

59 | 60 | -------------------------------------------------------------------------------- /test/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /HC05-master/Examples/findBaudTest/findBaudTest.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * findBaudTest - Test all supported baud settings 3 | * 4 | * The progress and results are printed to Serial, so open the 'Serial 5 | * Montitor'. 6 | * 7 | * The progress and results will be easier to read if you disable the 8 | * debugging (comment out or delete the "#define DEBUG_HC05" line in 9 | * HC05.h. 10 | */ 11 | #include 12 | #include "HC05.h" 13 | 14 | #ifdef HC05_SOFTWARE_SERIAL 15 | #include 16 | HC05 btSerial = HC05(A2, A5, A3, A4); // cmd, state, rx, tx 17 | #else 18 | HC05 btSerial = HC05(3, 2); // cmd, state 19 | #endif 20 | 21 | void setup() 22 | { 23 | DEBUG_BEGIN(57600); 24 | Serial.begin(57600); 25 | Serial.println("---------- Setup ----------"); 26 | btSerial.findBaud(); 27 | btSerial.setBaud(4800); 28 | Serial.println("---------- Starting test ----------"); 29 | } 30 | 31 | void loop() 32 | { 33 | int numTests = 0; 34 | int failed = 0; 35 | unsigned long rate = 0; 36 | unsigned long rates[] = {4800,9600,19200,38400,57600,115200}; 37 | 38 | for (int i = 0; i < 6; i++) 39 | { 40 | for (int j = 0; j < 6; j++) 41 | { 42 | numTests++; 43 | Serial.print(rates[i]); 44 | btSerial.setBaud(rates[i]); 45 | rate = btSerial.findBaud(); 46 | if (rate != rates[i]) 47 | { 48 | Serial.print(" FAILED: found rate "); 49 | Serial.println(rate); 50 | failed++; 51 | } 52 | else 53 | { 54 | Serial.print("->"); 55 | Serial.print(rates[j]); 56 | btSerial.setBaud(rates[j]); 57 | rate = btSerial.findBaud(); 58 | if (rate != rates[j]) 59 | { 60 | Serial.print("FAILED: found rate "); 61 | Serial.println(rate); 62 | failed++; 63 | } 64 | else 65 | { 66 | Serial.println(" PASSED"); 67 | } 68 | } 69 | } 70 | } 71 | 72 | Serial.println("--------- Tests Complete ----------"); 73 | Serial.print("Results: "); 74 | Serial.print(failed); 75 | Serial.print(" of "); 76 | Serial.print(numTests); 77 | Serial.println(" tests failed."); 78 | 79 | while (true) 80 | { 81 | ; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /test/register.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 45 | 46 | 47 | 48 |
49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /Stepper_Manual_ajin/Stepper_Manual_ajin.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int rs = A0, en = A1, d4 = A2, d5 = A3, d6 = A4, d7 = A5; 5 | LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 6 | 7 | AccelStepper stepperA(1,A9,A8); 8 | AccelStepper stepperB(1,A11,A10); 9 | 10 | void setup() { 11 | Serial3.begin(115200); 12 | Serial.begin(115200); 13 | stepperA.setMaxSpeed(450); 14 | stepperA.setAcceleration(225); 15 | stepperB.setMaxSpeed(450); 16 | stepperB.setAcceleration(225); 17 | 18 | lcd.begin(16, 2); 19 | } 20 | 21 | int stepper_speed = 0,steps = 0; 22 | 23 | void loop() { 24 | char stepper,dir; 25 | while(Serial3.available()>0) 26 | { 27 | stepper = Serial3.read(); 28 | 29 | if (stepper == 'a' || stepper == 'b'){ 30 | while(Serial3.available() == 0); 31 | dir = Serial3.read(); 32 | Serial.println(stepper); 33 | Serial.println(dir); 34 | } 35 | 36 | else if(stepper == 'c') {stepper_speed += 10; stepperA.setMaxSpeed(450+stepper_speed); stepperB.setMaxSpeed(450+stepper_speed);} 37 | 38 | else if(stepper == 'd') 39 | { 40 | if (stepper_speed != 0) { stepper_speed -= 10; stepperA.setMaxSpeed(450+stepper_speed); stepperB.setMaxSpeed(450+stepper_speed); } 41 | } 42 | 43 | else if(stepper == 'e') {steps += 500; } 44 | 45 | else if(stepper == 'f') 46 | { 47 | if (steps != 0) { steps -= 500; } 48 | } 49 | } 50 | 51 | if(stepper == 'a') 52 | { 53 | if (dir == '0') 54 | { 55 | stepperA.moveTo(1000+steps); 56 | } 57 | 58 | else if(dir == '1') 59 | { 60 | stepperA.moveTo(-1000-steps); 61 | } 62 | } 63 | 64 | if (stepper == 'b') 65 | { 66 | if (dir == '0') 67 | { 68 | stepperB.moveTo(1000+steps); 69 | } 70 | 71 | else if(dir == '1') 72 | { 73 | stepperB.moveTo(-1000-steps); 74 | 75 | } 76 | 77 | } 78 | 79 | stepperA.run(); 80 | stepperB.run(); 81 | 82 | if(stepperA.distanceToGo() == 0) 83 | { 84 | stepperA.setCurrentPosition(0); 85 | } 86 | if(stepperB.distanceToGo() == 0) 87 | { 88 | stepperB.setCurrentPosition( 0 ); 89 | } 90 | 91 | lcd.setCursor(0, 1); 92 | lcd.print("speed "); 93 | lcd.print(stepper_speed); 94 | 95 | 96 | lcd.setCursor(1, 0); 97 | lcd.print("steps "); 98 | lcd.print(steps); 99 | 100 | } 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /HC05-master/Examples/changeName/changeName.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Change the BT device name 3 | * 4 | * This works with a Bluetooth terminal. The user is prompted for a new 5 | * name which is then written to HC-05. 6 | * 7 | */ 8 | #include 9 | #include "HC05.h" 10 | 11 | /* 12 | * Configure this sketch to work with either a software or a hardware 13 | * serial port, as configured in HC05.h 14 | */ 15 | #ifdef HC05_SOFTWARE_SERIAL 16 | #include 17 | HC05 btSerial = HC05(A2, A5, A3, A4); // cmd, state, rx, tx 18 | #else 19 | HC05 btSerial = HC05(3, 2); // cmd, state 20 | #endif 21 | 22 | /* 23 | * See the ITeadStudio HC-05 datasheet for a full list of commands. 24 | */ 25 | String NewNameCmd("AT+NAME="); 26 | 27 | 28 | void setup() 29 | { 30 | btSerial.findBaud(); 31 | } 32 | 33 | 34 | void loop(){ 35 | char buffer[32]; 36 | size_t recvd = 0; 37 | bool waiting = true; 38 | String newName; 39 | 40 | btSerial.println(""); 41 | btSerial.print("New name? "); 42 | 43 | // Use a timeout that will give reasonablly quick response to the user. 44 | btSerial.setTimeout(100); 45 | while (waiting) 46 | { 47 | if (btSerial.available()) 48 | { 49 | recvd = btSerial.readBytes(buffer, 32); 50 | for (size_t i = 0; i < recvd; i++) 51 | { 52 | if (buffer[i] != '\n') 53 | { 54 | newName += buffer[i]; 55 | btSerial.print(buffer[i]); 56 | } 57 | else 58 | { 59 | btSerial.println(" "); 60 | waiting = false; 61 | break; 62 | } 63 | } 64 | } 65 | delay(100); 66 | } 67 | 68 | newName.toCharArray(buffer, 32); 69 | newName = NewNameCmd + newName; 70 | newName.toCharArray(buffer, 32); 71 | 72 | // make sure there is no pending output to interfere with commands 73 | btSerial.flush(); 74 | 75 | // The name change command takes extra time. 76 | // 1000ms is large enough, but arbitrary. 77 | if (btSerial.cmd(buffer,1000)) 78 | { 79 | btSerial.println("Name changed."); 80 | btSerial.println("Reconnect or rescan to see the result."); 81 | btSerial.println("Disconnecting..."); 82 | btSerial.flush(); 83 | btSerial.cmd("AT+DISC", 1000); 84 | } 85 | else 86 | { 87 | btSerial.println("Name NOT changed."); 88 | } 89 | 90 | // Send a count to the port just to indicate activity. 91 | // This will appear after the connection is re-established, or 92 | // immediately if the name change command fails. 93 | for (uint8_t i = 0; true; i++) 94 | { 95 | if (i == 0) 96 | { 97 | btSerial.println(""); 98 | } 99 | btSerial.print(i); 100 | btSerial.print('\r'); 101 | delay(1000); 102 | } 103 | } 104 | 105 | -------------------------------------------------------------------------------- /Test_Program/joystick.cpp.bat: -------------------------------------------------------------------------------- 1 | #include "joystick.h" 2 | 3 | USB Usb; 4 | USBHub Hub(&Usb); 5 | HIDUniversal Hid(&Usb); 6 | JoystickEvents JoyEvents; 7 | JoystickReportParser Joy(&JoyEvents); 8 | 9 | 10 | void Motion::joy() 11 | { 12 | Usb.Task(); 13 | if( JoyEvents.Y1 > 128 && JoyEvents.X2 > 128) 14 | { 15 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 255); 16 | X2 = map(JoyEvents.X2, 128, 255, 0, 255); 17 | avg = (Y1 + X2)/2; 18 | diagonal_brt(avg,avg,avg,avg); 19 | Serial.println("Diagonal backward-right motion"); 20 | 21 | } 22 | 23 | else if(JoyEvents.Y1>128 && JoyEvents.Y2<128) 24 | { 25 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 255); 26 | Y2 = map(JoyEvents.Y2, 0, 128, 0, 255); 27 | avg = (Y1 + Y2)/2; 28 | left_rotation(avg,avg,avg,avg); 29 | Serial.println("Left rotation"); 30 | } 31 | 32 | 33 | else if(JoyEvents.Y1<128 && JoyEvents.Y2>128) 34 | { 35 | Y1 = map(JoyEvents.Y1, 0, 128, 0, 255); 36 | Y2 = map(JoyEvents.Y2, 128, 255, 0, 255); 37 | avg = (Y1 + Y2)/2; 38 | right_rotation(avg,avg,avg,avg); 39 | Serial.println("Right rotation"); 40 | 41 | } 42 | 43 | else if( JoyEvents.Y1 < 128 && JoyEvents.X2 < 128) 44 | { 45 | Y1 = map(JoyEvents.Y1, 0, 128, 0, 255); 46 | X2 = map(JoyEvents.X2, 0, 128, 0, 255); 47 | avg = (Y1 + X2)/2; 48 | diagonal_flt(avg,avg,avg,avg); 49 | Serial.println("Diagonal forward-left motion"); 50 | } 51 | 52 | 53 | else if( JoyEvents.Y1 > 128 && JoyEvents.X2 < 128) 54 | { 55 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 255); 56 | X2 = map(JoyEvents.X2, 0, 128, 0, 255); 57 | avg = (Y1 + X2)/2; 58 | diagonal_blt(avg,avg,avg,avg); 59 | Serial.println("Diagonal backward-left motion"); 60 | } 61 | 62 | else if(JoyEvents.Y1<128) 63 | { 64 | Y1 = map(JoyEvents.Y1, 0, 128, 0, 255); 65 | dcforward(Y1,Y1,Y1,Y1); 66 | Serial.println("Forward motion"); 67 | } 68 | 69 | 70 | else if(JoyEvents.Y1>128) 71 | { 72 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 255); 73 | dcreverse(Y1,Y1,Y1,Y1); 74 | Serial.println("Reverse motion"); 75 | } 76 | 77 | 78 | else if(JoyEvents.X2 < 128) 79 | { 80 | X2 = map(JoyEvents.X2, 0, 128, 0, 255); 81 | dcleft(X2,X2,X2,X2); 82 | Serial.println("Left motion"); 83 | 84 | } 85 | 86 | 87 | else if(JoyEvents.X2 > 128) 88 | { 89 | X2 = map(JoyEvents.X2, 128, 255, 0, 255); 90 | dcright(X2,X2,X2,X2); 91 | Serial.println("Right motion"); 92 | } 93 | 94 | 95 | } 96 | 97 | 98 | 99 | 100 | void Motion::init() 101 | { 102 | Serial.begin(115200); 103 | #if !defined(__MIPSEL__) 104 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 105 | #endif 106 | Serial.println("Start"); 107 | 108 | if (Usb.Init() == -1) 109 | Serial.println("OSC did not start."); 110 | 111 | delay(200); 112 | 113 | if (!Hid.SetReportParser(0, &Joy)) 114 | ErrorMessage (PSTR("SetReportParser"), 1); 115 | } 116 | 117 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/joystick.cpp.bat: -------------------------------------------------------------------------------- 1 | #include "joystick.h" 2 | 3 | USB Usb; 4 | USBHub Hub(&Usb); 5 | HIDUniversal Hid(&Usb); 6 | JoystickEvents JoyEvents; 7 | JoystickReportParser Joy(&JoyEvents); 8 | 9 | 10 | void Motion::joy() 11 | { 12 | Usb.Task(); 13 | if( JoyEvents.Y1 > 128 && JoyEvents.X2 > 128) 14 | { 15 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 255); 16 | X2 = map(JoyEvents.X2, 128, 255, 0, 255); 17 | avg = (Y1 + X2)/2; 18 | diagonal_brt(avg,avg,avg,avg); 19 | Serial.println("Diagonal backward-right motion"); 20 | 21 | } 22 | 23 | else if(JoyEvents.Y1>128 && JoyEvents.Y2<128) 24 | { 25 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 255); 26 | Y2 = map(JoyEvents.Y2, 0, 128, 0, 255); 27 | avg = (Y1 + Y2)/2; 28 | left_rotation(avg,avg,avg,avg); 29 | Serial.println("Left rotation"); 30 | } 31 | 32 | 33 | else if(JoyEvents.Y1<128 && JoyEvents.Y2>128) 34 | { 35 | Y1 = map(JoyEvents.Y1, 0, 128, 0, 255); 36 | Y2 = map(JoyEvents.Y2, 128, 255, 0, 255); 37 | avg = (Y1 + Y2)/2; 38 | right_rotation(avg,avg,avg,avg); 39 | Serial.println("Right rotation"); 40 | 41 | } 42 | 43 | else if( JoyEvents.Y1 < 128 && JoyEvents.X2 < 128) 44 | { 45 | Y1 = map(JoyEvents.Y1, 0, 128, 0, 255); 46 | X2 = map(JoyEvents.X2, 0, 128, 0, 255); 47 | avg = (Y1 + X2)/2; 48 | diagonal_flt(avg,avg,avg,avg); 49 | Serial.println("Diagonal forward-left motion"); 50 | } 51 | 52 | 53 | else if( JoyEvents.Y1 > 128 && JoyEvents.X2 < 128) 54 | { 55 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 255); 56 | X2 = map(JoyEvents.X2, 0, 128, 0, 255); 57 | avg = (Y1 + X2)/2; 58 | diagonal_blt(avg,avg,avg,avg); 59 | Serial.println("Diagonal backward-left motion"); 60 | } 61 | 62 | else if(JoyEvents.Y1<128) 63 | { 64 | Y1 = map(JoyEvents.Y1, 0, 128, 0, 255); 65 | dcforward(Y1,Y1,Y1,Y1); 66 | Serial.println("Forward motion"); 67 | } 68 | 69 | 70 | else if(JoyEvents.Y1>128) 71 | { 72 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 255); 73 | dcreverse(Y1,Y1,Y1,Y1); 74 | Serial.println("Reverse motion"); 75 | } 76 | 77 | 78 | else if(JoyEvents.X2 < 128) 79 | { 80 | X2 = map(JoyEvents.X2, 0, 128, 0, 255); 81 | dcleft(X2,X2,X2,X2); 82 | Serial.println("Left motion"); 83 | 84 | } 85 | 86 | 87 | else if(JoyEvents.X2 > 128) 88 | { 89 | X2 = map(JoyEvents.X2, 128, 255, 0, 255); 90 | dcright(X2,X2,X2,X2); 91 | Serial.println("Right motion"); 92 | } 93 | 94 | 95 | } 96 | 97 | 98 | 99 | 100 | void Motion::init() 101 | { 102 | Serial.begin(115200); 103 | #if !defined(__MIPSEL__) 104 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 105 | #endif 106 | Serial.println("Start"); 107 | 108 | if (Usb.Init() == -1) 109 | Serial.println("OSC did not start."); 110 | 111 | delay(200); 112 | 113 | if (!Hid.SetReportParser(0, &Joy)) 114 | ErrorMessage (PSTR("SetReportParser"), 1); 115 | } 116 | 117 | -------------------------------------------------------------------------------- /Test Program/Test_Program/joystick.cpp.bat: -------------------------------------------------------------------------------- 1 | #include "joystick.h" 2 | 3 | USB Usb; 4 | USBHub Hub(&Usb); 5 | HIDUniversal Hid(&Usb); 6 | JoystickEvents JoyEvents; 7 | JoystickReportParser Joy(&JoyEvents); 8 | 9 | 10 | void Motion::joy() 11 | { 12 | Usb.Task(); 13 | if( JoyEvents.Y1 > 128 && JoyEvents.X2 > 128) 14 | { 15 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 255); 16 | X2 = map(JoyEvents.X2, 128, 255, 0, 255); 17 | avg = (Y1 + X2)/2; 18 | diagonal_brt(avg,avg,avg,avg); 19 | Serial.println("Diagonal backward-right motion"); 20 | 21 | } 22 | 23 | else if(JoyEvents.Y1>128 && JoyEvents.Y2<128) 24 | { 25 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 255); 26 | Y2 = map(JoyEvents.Y2, 0, 128, 0, 255); 27 | avg = (Y1 + Y2)/2; 28 | left_rotation(avg,avg,avg,avg); 29 | Serial.println("Left rotation"); 30 | } 31 | 32 | 33 | else if(JoyEvents.Y1<128 && JoyEvents.Y2>128) 34 | { 35 | Y1 = map(JoyEvents.Y1, 0, 128, 0, 255); 36 | Y2 = map(JoyEvents.Y2, 128, 255, 0, 255); 37 | avg = (Y1 + Y2)/2; 38 | right_rotation(avg,avg,avg,avg); 39 | Serial.println("Right rotation"); 40 | 41 | } 42 | 43 | else if( JoyEvents.Y1 < 128 && JoyEvents.X2 < 128) 44 | { 45 | Y1 = map(JoyEvents.Y1, 0, 128, 0, 255); 46 | X2 = map(JoyEvents.X2, 0, 128, 0, 255); 47 | avg = (Y1 + X2)/2; 48 | diagonal_flt(avg,avg,avg,avg); 49 | Serial.println("Diagonal forward-left motion"); 50 | } 51 | 52 | 53 | else if( JoyEvents.Y1 > 128 && JoyEvents.X2 < 128) 54 | { 55 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 255); 56 | X2 = map(JoyEvents.X2, 0, 128, 0, 255); 57 | avg = (Y1 + X2)/2; 58 | diagonal_blt(avg,avg,avg,avg); 59 | Serial.println("Diagonal backward-left motion"); 60 | } 61 | 62 | else if(JoyEvents.Y1<128) 63 | { 64 | Y1 = map(JoyEvents.Y1, 0, 128, 0, 255); 65 | dcforward(Y1,Y1,Y1,Y1); 66 | Serial.println("Forward motion"); 67 | } 68 | 69 | 70 | else if(JoyEvents.Y1>128) 71 | { 72 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 255); 73 | dcreverse(Y1,Y1,Y1,Y1); 74 | Serial.println("Reverse motion"); 75 | } 76 | 77 | 78 | else if(JoyEvents.X2 < 128) 79 | { 80 | X2 = map(JoyEvents.X2, 0, 128, 0, 255); 81 | dcleft(X2,X2,X2,X2); 82 | Serial.println("Left motion"); 83 | 84 | } 85 | 86 | 87 | else if(JoyEvents.X2 > 128) 88 | { 89 | X2 = map(JoyEvents.X2, 128, 255, 0, 255); 90 | dcright(X2,X2,X2,X2); 91 | Serial.println("Right motion"); 92 | } 93 | 94 | 95 | } 96 | 97 | 98 | 99 | 100 | void Motion::init() 101 | { 102 | Serial.begin(115200); 103 | #if !defined(__MIPSEL__) 104 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 105 | #endif 106 | Serial.println("Start"); 107 | 108 | if (Usb.Init() == -1) 109 | Serial.println("OSC did not start."); 110 | 111 | delay(200); 112 | 113 | if (!Hid.SetReportParser(0, &Joy)) 114 | ErrorMessage (PSTR("SetReportParser"), 1); 115 | } 116 | 117 | -------------------------------------------------------------------------------- /Test_Program/hidjoystickrptparser.cpp: -------------------------------------------------------------------------------- 1 | /*#include "hidjoystickrptparser.h" 2 | 3 | 4 | 5 | JoystickReportParser::JoystickReportParser(JoystickEvents *evt) : 6 | joyEvents(evt), 7 | oldHat(0xDE), 8 | oldButtons(0) { 9 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 10 | oldPad[i] = 0xD; 11 | } 12 | 13 | void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { 14 | bool match = true; 15 | 16 | // Checking if there are changes in report since the method was last called 17 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 18 | if (buf[i] != oldPad[i]) { 19 | match = false; 20 | break; 21 | } 22 | 23 | // Calling Game Pad event handler 24 | if (!match && joyEvents) { 25 | joyEvents->OnGamePadChanged((const GamePadEventData*)buf); 26 | 27 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) oldPad[i] = buf[i]; 28 | } 29 | 30 | uint8_t hat = (buf[5] & 0xF); 31 | 32 | // Calling Hat Switch event handler 33 | if (hat != oldHat && joyEvents) { 34 | joyEvents->OnHatSwitch(hat); 35 | oldHat = hat; 36 | } 37 | 38 | uint16_t buttons = (0x0000 | buf[6]); 39 | buttons <<= 4; 40 | buttons |= (buf[5] >> 4); 41 | uint16_t changes = (buttons ^ oldButtons); 42 | 43 | // Calling Button Event Handler for every button changed 44 | if (changes) { 45 | for (uint8_t i = 0; i < 0x0C; i++) { 46 | uint16_t mask = (0x0001 << i); 47 | 48 | if (((mask & changes) > 0) && joyEvents) { 49 | if ((buttons & mask) > 0) 50 | joyEvents->OnButtonDn(i + 1); 51 | else 52 | joyEvents->OnButtonUp(i + 1); 53 | } 54 | } 55 | oldButtons = buttons; 56 | } 57 | } 58 | 59 | void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) { 60 | /*Serial.print("X1: "); 61 | PrintHex (evt->X, 0x80); 62 | Serial.print("\tY1: "); 63 | PrintHex (evt->Y, 0x80); 64 | Serial.print("\tX2: "); 65 | PrintHex (evt->Z1, 0x80); 66 | Serial.print("\tY2: "); 67 | PrintHex (evt->Z2, 0x80); 68 | Serial.print("\tRz: "); 69 | PrintHex (evt->Rz, 0x80); 70 | Serial.println(""); 71 | 72 | X1 = evt->X; 73 | Y1 = evt->Y; 74 | X2 = evt->Z2; 75 | X3 = evt->Z1; 76 | Y2 = evt->Rz; 77 | } 78 | 79 | void JoystickEvents::OnHatSwitch(uint8_t hat) { 80 | Serial.print("Hat Switch: "); 81 | PrintHex (hat, 0x80); 82 | Serial.println(""); 83 | } 84 | 85 | void JoystickEvents::OnButtonUp(uint8_t but_id) { 86 | Serial.print("Up: "); 87 | Serial.println(but_id, DEC); 88 | } 89 | 90 | void JoystickEvents::OnButtonDn(uint8_t but_id) { 91 | Serial.print("Dn: "); 92 | Serial.println(but_id, DEC); 93 | } 94 | 95 | 96 | 97 | */ 98 | 99 | 100 | -------------------------------------------------------------------------------- /Test_Program/hidjoystickrptparser.cpp.bat: -------------------------------------------------------------------------------- 1 | #include "hidjoystickrptparser.h" 2 | 3 | 4 | 5 | JoystickReportParser::JoystickReportParser(JoystickEvents *evt) : 6 | joyEvents(evt), 7 | oldHat(0xDE), 8 | oldButtons(0) { 9 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 10 | oldPad[i] = 0xD; 11 | } 12 | 13 | void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { 14 | bool match = true; 15 | 16 | // Checking if there are changes in report since the method was last called 17 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 18 | if (buf[i] != oldPad[i]) { 19 | match = false; 20 | break; 21 | } 22 | 23 | // Calling Game Pad event handler 24 | if (!match && joyEvents) { 25 | joyEvents->OnGamePadChanged((const GamePadEventData*)buf); 26 | 27 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) oldPad[i] = buf[i]; 28 | } 29 | 30 | uint8_t hat = (buf[5] & 0xF); 31 | 32 | // Calling Hat Switch event handler 33 | if (hat != oldHat && joyEvents) { 34 | joyEvents->OnHatSwitch(hat); 35 | oldHat = hat; 36 | } 37 | 38 | uint16_t buttons = (0x0000 | buf[6]); 39 | buttons <<= 4; 40 | buttons |= (buf[5] >> 4); 41 | uint16_t changes = (buttons ^ oldButtons); 42 | 43 | // Calling Button Event Handler for every button changed 44 | if (changes) { 45 | for (uint8_t i = 0; i < 0x0C; i++) { 46 | uint16_t mask = (0x0001 << i); 47 | 48 | if (((mask & changes) > 0) && joyEvents) { 49 | if ((buttons & mask) > 0) 50 | joyEvents->OnButtonDn(i + 1); 51 | else 52 | joyEvents->OnButtonUp(i + 1); 53 | } 54 | } 55 | oldButtons = buttons; 56 | } 57 | } 58 | 59 | void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) { 60 | /*Serial.print("X1: "); 61 | PrintHex (evt->X, 0x80); 62 | Serial.print("\tY1: "); 63 | PrintHex (evt->Y, 0x80); 64 | Serial.print("\tX2: "); 65 | PrintHex (evt->Z1, 0x80); 66 | Serial.print("\tY2: "); 67 | PrintHex (evt->Z2, 0x80); 68 | Serial.print("\tRz: "); 69 | PrintHex (evt->Rz, 0x80); 70 | Serial.println("");*/ 71 | 72 | X1 = evt->X; 73 | Y1 = evt->Y; 74 | X2 = evt->Z2; 75 | X3 = evt->Z1; 76 | Y2 = evt->Rz; 77 | } 78 | 79 | void JoystickEvents::OnHatSwitch(uint8_t hat) { 80 | Serial.print("Hat Switch: "); 81 | PrintHex (hat, 0x80); 82 | Serial.println(""); 83 | } 84 | 85 | void JoystickEvents::OnButtonUp(uint8_t but_id) { 86 | Serial.print("Up: "); 87 | Serial.println(but_id, DEC); 88 | } 89 | 90 | void JoystickEvents::OnButtonDn(uint8_t but_id) { 91 | Serial.print("Dn: "); 92 | Serial.println(but_id, DEC); 93 | } 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/hidjoystickrptparser.cpp: -------------------------------------------------------------------------------- 1 | /*#include "hidjoystickrptparser.h" 2 | 3 | 4 | 5 | JoystickReportParser::JoystickReportParser(JoystickEvents *evt) : 6 | joyEvents(evt), 7 | oldHat(0xDE), 8 | oldButtons(0) { 9 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 10 | oldPad[i] = 0xD; 11 | } 12 | 13 | void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { 14 | bool match = true; 15 | 16 | // Checking if there are changes in report since the method was last called 17 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 18 | if (buf[i] != oldPad[i]) { 19 | match = false; 20 | break; 21 | } 22 | 23 | // Calling Game Pad event handler 24 | if (!match && joyEvents) { 25 | joyEvents->OnGamePadChanged((const GamePadEventData*)buf); 26 | 27 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) oldPad[i] = buf[i]; 28 | } 29 | 30 | uint8_t hat = (buf[5] & 0xF); 31 | 32 | // Calling Hat Switch event handler 33 | if (hat != oldHat && joyEvents) { 34 | joyEvents->OnHatSwitch(hat); 35 | oldHat = hat; 36 | } 37 | 38 | uint16_t buttons = (0x0000 | buf[6]); 39 | buttons <<= 4; 40 | buttons |= (buf[5] >> 4); 41 | uint16_t changes = (buttons ^ oldButtons); 42 | 43 | // Calling Button Event Handler for every button changed 44 | if (changes) { 45 | for (uint8_t i = 0; i < 0x0C; i++) { 46 | uint16_t mask = (0x0001 << i); 47 | 48 | if (((mask & changes) > 0) && joyEvents) { 49 | if ((buttons & mask) > 0) 50 | joyEvents->OnButtonDn(i + 1); 51 | else 52 | joyEvents->OnButtonUp(i + 1); 53 | } 54 | } 55 | oldButtons = buttons; 56 | } 57 | } 58 | 59 | void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) { 60 | /*Serial.print("X1: "); 61 | PrintHex (evt->X, 0x80); 62 | Serial.print("\tY1: "); 63 | PrintHex (evt->Y, 0x80); 64 | Serial.print("\tX2: "); 65 | PrintHex (evt->Z1, 0x80); 66 | Serial.print("\tY2: "); 67 | PrintHex (evt->Z2, 0x80); 68 | Serial.print("\tRz: "); 69 | PrintHex (evt->Rz, 0x80); 70 | Serial.println(""); 71 | 72 | X1 = evt->X; 73 | Y1 = evt->Y; 74 | X2 = evt->Z2; 75 | X3 = evt->Z1; 76 | Y2 = evt->Rz; 77 | } 78 | 79 | void JoystickEvents::OnHatSwitch(uint8_t hat) { 80 | Serial.print("Hat Switch: "); 81 | PrintHex (hat, 0x80); 82 | Serial.println(""); 83 | } 84 | 85 | void JoystickEvents::OnButtonUp(uint8_t but_id) { 86 | Serial.print("Up: "); 87 | Serial.println(but_id, DEC); 88 | } 89 | 90 | void JoystickEvents::OnButtonDn(uint8_t but_id) { 91 | Serial.print("Dn: "); 92 | Serial.println(but_id, DEC); 93 | } 94 | 95 | 96 | 97 | */ 98 | 99 | 100 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/hidjoystickrptparser.cpp.bat: -------------------------------------------------------------------------------- 1 | #include "hidjoystickrptparser.h" 2 | 3 | 4 | 5 | JoystickReportParser::JoystickReportParser(JoystickEvents *evt) : 6 | joyEvents(evt), 7 | oldHat(0xDE), 8 | oldButtons(0) { 9 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 10 | oldPad[i] = 0xD; 11 | } 12 | 13 | void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { 14 | bool match = true; 15 | 16 | // Checking if there are changes in report since the method was last called 17 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 18 | if (buf[i] != oldPad[i]) { 19 | match = false; 20 | break; 21 | } 22 | 23 | // Calling Game Pad event handler 24 | if (!match && joyEvents) { 25 | joyEvents->OnGamePadChanged((const GamePadEventData*)buf); 26 | 27 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) oldPad[i] = buf[i]; 28 | } 29 | 30 | uint8_t hat = (buf[5] & 0xF); 31 | 32 | // Calling Hat Switch event handler 33 | if (hat != oldHat && joyEvents) { 34 | joyEvents->OnHatSwitch(hat); 35 | oldHat = hat; 36 | } 37 | 38 | uint16_t buttons = (0x0000 | buf[6]); 39 | buttons <<= 4; 40 | buttons |= (buf[5] >> 4); 41 | uint16_t changes = (buttons ^ oldButtons); 42 | 43 | // Calling Button Event Handler for every button changed 44 | if (changes) { 45 | for (uint8_t i = 0; i < 0x0C; i++) { 46 | uint16_t mask = (0x0001 << i); 47 | 48 | if (((mask & changes) > 0) && joyEvents) { 49 | if ((buttons & mask) > 0) 50 | joyEvents->OnButtonDn(i + 1); 51 | else 52 | joyEvents->OnButtonUp(i + 1); 53 | } 54 | } 55 | oldButtons = buttons; 56 | } 57 | } 58 | 59 | void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) { 60 | /*Serial.print("X1: "); 61 | PrintHex (evt->X, 0x80); 62 | Serial.print("\tY1: "); 63 | PrintHex (evt->Y, 0x80); 64 | Serial.print("\tX2: "); 65 | PrintHex (evt->Z1, 0x80); 66 | Serial.print("\tY2: "); 67 | PrintHex (evt->Z2, 0x80); 68 | Serial.print("\tRz: "); 69 | PrintHex (evt->Rz, 0x80); 70 | Serial.println("");*/ 71 | 72 | X1 = evt->X; 73 | Y1 = evt->Y; 74 | X2 = evt->Z2; 75 | X3 = evt->Z1; 76 | Y2 = evt->Rz; 77 | } 78 | 79 | void JoystickEvents::OnHatSwitch(uint8_t hat) { 80 | Serial.print("Hat Switch: "); 81 | PrintHex (hat, 0x80); 82 | Serial.println(""); 83 | } 84 | 85 | void JoystickEvents::OnButtonUp(uint8_t but_id) { 86 | Serial.print("Up: "); 87 | Serial.println(but_id, DEC); 88 | } 89 | 90 | void JoystickEvents::OnButtonDn(uint8_t but_id) { 91 | Serial.print("Dn: "); 92 | Serial.println(but_id, DEC); 93 | } 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Test Program/Test_Program/hidjoystickrptparser.cpp: -------------------------------------------------------------------------------- 1 | /*#include "hidjoystickrptparser.h" 2 | 3 | 4 | 5 | JoystickReportParser::JoystickReportParser(JoystickEvents *evt) : 6 | joyEvents(evt), 7 | oldHat(0xDE), 8 | oldButtons(0) { 9 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 10 | oldPad[i] = 0xD; 11 | } 12 | 13 | void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { 14 | bool match = true; 15 | 16 | // Checking if there are changes in report since the method was last called 17 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 18 | if (buf[i] != oldPad[i]) { 19 | match = false; 20 | break; 21 | } 22 | 23 | // Calling Game Pad event handler 24 | if (!match && joyEvents) { 25 | joyEvents->OnGamePadChanged((const GamePadEventData*)buf); 26 | 27 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) oldPad[i] = buf[i]; 28 | } 29 | 30 | uint8_t hat = (buf[5] & 0xF); 31 | 32 | // Calling Hat Switch event handler 33 | if (hat != oldHat && joyEvents) { 34 | joyEvents->OnHatSwitch(hat); 35 | oldHat = hat; 36 | } 37 | 38 | uint16_t buttons = (0x0000 | buf[6]); 39 | buttons <<= 4; 40 | buttons |= (buf[5] >> 4); 41 | uint16_t changes = (buttons ^ oldButtons); 42 | 43 | // Calling Button Event Handler for every button changed 44 | if (changes) { 45 | for (uint8_t i = 0; i < 0x0C; i++) { 46 | uint16_t mask = (0x0001 << i); 47 | 48 | if (((mask & changes) > 0) && joyEvents) { 49 | if ((buttons & mask) > 0) 50 | joyEvents->OnButtonDn(i + 1); 51 | else 52 | joyEvents->OnButtonUp(i + 1); 53 | } 54 | } 55 | oldButtons = buttons; 56 | } 57 | } 58 | 59 | void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) { 60 | /*Serial.print("X1: "); 61 | PrintHex (evt->X, 0x80); 62 | Serial.print("\tY1: "); 63 | PrintHex (evt->Y, 0x80); 64 | Serial.print("\tX2: "); 65 | PrintHex (evt->Z1, 0x80); 66 | Serial.print("\tY2: "); 67 | PrintHex (evt->Z2, 0x80); 68 | Serial.print("\tRz: "); 69 | PrintHex (evt->Rz, 0x80); 70 | Serial.println(""); 71 | 72 | X1 = evt->X; 73 | Y1 = evt->Y; 74 | X2 = evt->Z2; 75 | X3 = evt->Z1; 76 | Y2 = evt->Rz; 77 | } 78 | 79 | void JoystickEvents::OnHatSwitch(uint8_t hat) { 80 | Serial.print("Hat Switch: "); 81 | PrintHex (hat, 0x80); 82 | Serial.println(""); 83 | } 84 | 85 | void JoystickEvents::OnButtonUp(uint8_t but_id) { 86 | Serial.print("Up: "); 87 | Serial.println(but_id, DEC); 88 | } 89 | 90 | void JoystickEvents::OnButtonDn(uint8_t but_id) { 91 | Serial.print("Dn: "); 92 | Serial.println(but_id, DEC); 93 | } 94 | 95 | 96 | 97 | */ 98 | 99 | 100 | -------------------------------------------------------------------------------- /Test Program/Test_Program/hidjoystickrptparser.cpp.bat: -------------------------------------------------------------------------------- 1 | #include "hidjoystickrptparser.h" 2 | 3 | 4 | 5 | JoystickReportParser::JoystickReportParser(JoystickEvents *evt) : 6 | joyEvents(evt), 7 | oldHat(0xDE), 8 | oldButtons(0) { 9 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 10 | oldPad[i] = 0xD; 11 | } 12 | 13 | void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { 14 | bool match = true; 15 | 16 | // Checking if there are changes in report since the method was last called 17 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 18 | if (buf[i] != oldPad[i]) { 19 | match = false; 20 | break; 21 | } 22 | 23 | // Calling Game Pad event handler 24 | if (!match && joyEvents) { 25 | joyEvents->OnGamePadChanged((const GamePadEventData*)buf); 26 | 27 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) oldPad[i] = buf[i]; 28 | } 29 | 30 | uint8_t hat = (buf[5] & 0xF); 31 | 32 | // Calling Hat Switch event handler 33 | if (hat != oldHat && joyEvents) { 34 | joyEvents->OnHatSwitch(hat); 35 | oldHat = hat; 36 | } 37 | 38 | uint16_t buttons = (0x0000 | buf[6]); 39 | buttons <<= 4; 40 | buttons |= (buf[5] >> 4); 41 | uint16_t changes = (buttons ^ oldButtons); 42 | 43 | // Calling Button Event Handler for every button changed 44 | if (changes) { 45 | for (uint8_t i = 0; i < 0x0C; i++) { 46 | uint16_t mask = (0x0001 << i); 47 | 48 | if (((mask & changes) > 0) && joyEvents) { 49 | if ((buttons & mask) > 0) 50 | joyEvents->OnButtonDn(i + 1); 51 | else 52 | joyEvents->OnButtonUp(i + 1); 53 | } 54 | } 55 | oldButtons = buttons; 56 | } 57 | } 58 | 59 | void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) { 60 | /*Serial.print("X1: "); 61 | PrintHex (evt->X, 0x80); 62 | Serial.print("\tY1: "); 63 | PrintHex (evt->Y, 0x80); 64 | Serial.print("\tX2: "); 65 | PrintHex (evt->Z1, 0x80); 66 | Serial.print("\tY2: "); 67 | PrintHex (evt->Z2, 0x80); 68 | Serial.print("\tRz: "); 69 | PrintHex (evt->Rz, 0x80); 70 | Serial.println("");*/ 71 | 72 | X1 = evt->X; 73 | Y1 = evt->Y; 74 | X2 = evt->Z2; 75 | X3 = evt->Z1; 76 | Y2 = evt->Rz; 77 | } 78 | 79 | void JoystickEvents::OnHatSwitch(uint8_t hat) { 80 | Serial.print("Hat Switch: "); 81 | PrintHex (hat, 0x80); 82 | Serial.println(""); 83 | } 84 | 85 | void JoystickEvents::OnButtonUp(uint8_t but_id) { 86 | Serial.print("Up: "); 87 | Serial.println(but_id, DEC); 88 | } 89 | 90 | void JoystickEvents::OnButtonDn(uint8_t but_id) { 91 | Serial.print("Dn: "); 92 | Serial.println(but_id, DEC); 93 | } 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /HC05-master/HC05.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HC05.h - interface definitions for the HC05 library 3 | * 4 | * Select hardware or software serial port: 5 | * Define HC05_SOFTWARE_SERIAL to select a SoftwareSerial port, then 6 | * initialize the HC05 class with either two arguments, for a hardware port, 7 | * or four arguments for a software serial port: 8 | * 9 | * HC05(cmdPin, statePin) 10 | * or 11 | * HC05(cmdPin, statePin, rxPin, txPin) 12 | * 13 | * Specify an alternate hardware serial port by changing the 14 | * HC05_HW_SERIAL_PORT define. 15 | * 16 | * Define DEBUG_HC05 to enable debugging messages and use the 17 | * DEBUG_BEGIN() macro in the sketch setup() function. 18 | * By default, debugging messages go to the harware serial port, Serial. 19 | * Change that by defining DEBUG_SW_PORT. 20 | * 21 | */ 22 | #ifndef HC05_h 23 | #define HC05_h 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | /* 30 | * Comment the following define line if you aren't using the State pin or 31 | * if your HC05 does not have such a pin. You still must specify a 32 | * statePin to initialize the HC05 class, but the pin will not be used. 33 | */ 34 | #define HC05_STATE_PIN 35 | 36 | /* 37 | * This macro must be defined even if you are using a software serial 38 | * port. You can change this to any serial port supported by your 39 | * Arduino (i.e, Serial1, Serial2, etc.) 40 | */ 41 | #define HC05_HW_SERIAL_PORT Serial 42 | 43 | 44 | /* 45 | * Optional macros, define as needed 46 | */ 47 | #define HC05_SOFTWARE_SERIAL 48 | #define DEBUG_HC05 49 | //#define DEBUG_SW_PORT swserial(4,5) 50 | 51 | #ifdef DEBUG_HC05 52 | #ifdef DEBUG_SW_PORT 53 | #define DEBUG_PORT swserial 54 | #else 55 | #define DEBUG_PORT Serial 56 | #endif 57 | 58 | #define DEBUG_BEGIN(baud) DEBUG_PORT.begin(baud) 59 | #define DEBUG_WRITE(...) DEBUG_PORT.write(__VA_ARGS__) 60 | #define DEBUG_PRINT(...) DEBUG_PORT.print(__VA_ARGS__) 61 | #define DEBUG_PRINTLN(...) DEBUG_PORT.println(__VA_ARGS__) 62 | 63 | #else 64 | #define DEBUG_BEGIN(baud) 65 | #define DEBUG_WRITE(...) 66 | #define DEBUG_PRINT(...) 67 | #define DEBUG_PRINTLN(...) 68 | 69 | #endif // DEBUG_HC05 70 | 71 | class HC05 : public Stream 72 | { 73 | public: 74 | HC05(int cmdPin, int statePin); 75 | HC05(int cmdPin, int statePin, uint8_t rx, uint8_t tx); 76 | unsigned long findBaud(); 77 | void setBaud(unsigned long baud); // always no parity, one stop bit 78 | void setBaud(unsigned long baud, unsigned long stopbits, unsigned long parity); 79 | 80 | // cmd(): 100ms default timeout covers simple commands, but commands 81 | // that manage the connection are likely to take much longer. 82 | int cmd(const char* cmd, unsigned long timeout=100); 83 | 84 | // HC05 cmdMode2 forces 38400, no parity, one stop bit 85 | // Entering cmdMode2 uses a pin to turn the HC05 power on and off 86 | // with the cmdPin high. cmdPin must remain high to stay in 87 | // cmdMode2, so use cmdMode2End() to exit. 88 | void cmdMode2Start(int pwrPin); 89 | void cmdMode2End(void); 90 | 91 | #ifdef HC05_STATE_PIN 92 | bool connected(void); 93 | #endif 94 | virtual int available(void); 95 | virtual void begin(unsigned long); 96 | #ifndef HC05_SOFTWARE_SERIAL 97 | virtual void begin(unsigned long, uint8_t); 98 | #endif 99 | virtual int peek(void); 100 | virtual int read(void); 101 | virtual void flush(void); 102 | virtual size_t write(uint8_t); 103 | using Print::write; 104 | #ifdef HC05_SOFTWARE_SERIAL 105 | SoftwareSerial _btSerial; 106 | #endif 107 | 108 | private: 109 | bool cmdMode; 110 | int _cmdPin; 111 | #ifdef HC05_STATE_PIN 112 | int _statePin; 113 | #endif 114 | int _bufsize; 115 | char _buffer[32]; 116 | void setCmdPin(bool state); 117 | }; 118 | 119 | extern HC05 btSerial; 120 | #endif // HC05_h 121 | -------------------------------------------------------------------------------- /JoystickControl/hidjoystickrptparser.cpp: -------------------------------------------------------------------------------- 1 | #include "hidjoystickrptparser.h" 2 | 3 | 4 | 5 | JoystickReportParser::JoystickReportParser(JoystickEvents *evt) : 6 | joyEvents(evt), 7 | oldHat(0xDE), 8 | oldButtons(0) { 9 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 10 | oldPad[i] = 0xD; 11 | } 12 | 13 | void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { 14 | bool match = true; 15 | 16 | // Checking if there are changes in report since the method was last called 17 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 18 | if (buf[i] != oldPad[i]) { 19 | match = false; 20 | break; 21 | } 22 | 23 | // Calling Game Pad event handler 24 | if (!match && joyEvents) { 25 | joyEvents->OnGamePadChanged((const GamePadEventData*)buf); 26 | 27 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) oldPad[i] = buf[i]; 28 | } 29 | 30 | uint8_t hat = (buf[5] & 0xF); 31 | 32 | 33 | 34 | // Calling Hat Switch event handler 35 | if (hat != oldHat && joyEvents) { 36 | joyEvents->OnHatSwitch(hat); 37 | oldHat = hat; 38 | 39 | if (hat != 0x0f) 40 | { 41 | joyEvents->hat_read |= (1 << hat); //tejas 42 | } 43 | 44 | else if(hat == 0x0f) 45 | { 46 | joyEvents->hat_read = 0; 47 | } 48 | } 49 | 50 | uint16_t buttons = (0x0000 | buf[6]); 51 | buttons <<= 4; 52 | buttons |= (buf[5] >> 4); 53 | uint16_t changes = (buttons ^ oldButtons); 54 | 55 | 56 | 57 | // Calling Button Event Handler for every button changed 58 | if (changes) { 59 | for (uint8_t i = 0; i < 0x0C; i++) { 60 | uint16_t mask = (0x0001 << i); 61 | 62 | if (((mask & changes) > 0) && joyEvents) { 63 | if ((buttons & mask) > 0) 64 | { 65 | joyEvents->OnButtonDn(i + 1); 66 | joyEvents -> button_read |= (1<<(i)); //tejas 67 | } 68 | else 69 | { 70 | joyEvents->OnButtonUp(i + 1); 71 | joyEvents -> button_read &= ~(1<<(i)); //tejas 72 | } 73 | } 74 | oldButtons = buttons; 75 | } 76 | } 77 | 78 | } 79 | 80 | void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) { 81 | /*Serial.print("X1: "); 82 | PrintHex (evt->X, 0x80); 83 | Serial.print("\tY1: "); 84 | PrintHex (evt->Y, 0x80); 85 | Serial.print("\tX2: "); 86 | PrintHex (evt->Z1, 0x80); 87 | Serial.print("\tY2: "); 88 | PrintHex (evt->Z2, 0x80); 89 | Serial.print("\tRz: "); 90 | PrintHex (evt->Rz, 0x80); 91 | Serial.println("");*/ 92 | 93 | X1 = evt->X; 94 | // Serial.print(" X1 is:"); 95 | // Serial.print(X1); 96 | Y1 = evt->Y; 97 | // Serial.print(" Y1 is:"); 98 | // Serial.print(Y1); 99 | X2 = evt->Z2; 100 | // Serial.print(" X2 is:"); 101 | // Serial.print(X2); 102 | X3 = evt->Z1; 103 | // Serial.print(" X3 is:"); 104 | // Serial.print(X3); 105 | Y2 = evt->Rz; 106 | //Serial.print(" Y2 is:"); 107 | //Serial.println(Y2); 108 | } 109 | 110 | void JoystickEvents::OnHatSwitch(uint8_t hat) { 111 | Serial.print("Hat Switch: "); 112 | PrintHex (hat, 0x80); 113 | Serial.println(""); 114 | } 115 | 116 | void JoystickEvents::OnButtonUp(uint8_t but_id) { 117 | Serial.print("Up: "); 118 | Serial.println(but_id, DEC); 119 | } 120 | 121 | void JoystickEvents::OnButtonDn(uint8_t but_id) 122 | { 123 | Serial.print("Dn: "); 124 | Serial.println(but_id, DEC); 125 | } 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /Manual Robot/hidjoystickrptparser.cpp: -------------------------------------------------------------------------------- 1 | #include "hidjoystickrptparser.h" 2 | 3 | 4 | 5 | JoystickReportParser::JoystickReportParser(JoystickEvents *evt) : 6 | joyEvents(evt), 7 | oldHat(0xDE), 8 | oldButtons(0) { 9 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 10 | oldPad[i] = 0xD; 11 | } 12 | 13 | void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { 14 | bool match = true; 15 | 16 | // Checking if there are changes in report since the method was last called 17 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) 18 | if (buf[i] != oldPad[i]) { 19 | match = false; 20 | break; 21 | } 22 | 23 | // Calling Game Pad event handler 24 | if (!match && joyEvents) { 25 | joyEvents->OnGamePadChanged((const GamePadEventData*)buf); 26 | 27 | for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) oldPad[i] = buf[i]; 28 | } 29 | 30 | uint8_t hat = (buf[5] & 0xF); 31 | 32 | 33 | 34 | // Calling Hat Switch event handler 35 | if (hat != oldHat && joyEvents) { 36 | joyEvents->OnHatSwitch(hat); 37 | oldHat = hat; 38 | 39 | if (hat != 0x0f) 40 | { 41 | joyEvents->hat_read |= (1 << hat); //tejas 42 | } 43 | 44 | else if(hat == 0x0f) 45 | { 46 | joyEvents->hat_read = 0; 47 | } 48 | } 49 | 50 | uint16_t buttons = (0x0000 | buf[6]); 51 | buttons <<= 4; 52 | buttons |= (buf[5] >> 4); 53 | uint16_t changes = (buttons ^ oldButtons); 54 | 55 | 56 | 57 | // Calling Button Event Handler for every button changed 58 | if (changes) { 59 | for (uint8_t i = 0; i < 0x0C; i++) { 60 | uint16_t mask = (0x0001 << i); 61 | 62 | if (((mask & changes) > 0) && joyEvents) { 63 | if ((buttons & mask) > 0) 64 | { 65 | joyEvents->OnButtonDn(i + 1); 66 | joyEvents -> button_read |= (1<<(i)); //tejas 67 | } 68 | else 69 | { 70 | joyEvents->OnButtonUp(i + 1); 71 | joyEvents -> button_read &= ~(1<<(i)); //tejas 72 | } 73 | } 74 | oldButtons = buttons; 75 | } 76 | } 77 | 78 | } 79 | 80 | void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) { 81 | /*Serial.print("X1: "); 82 | PrintHex (evt->X, 0x80); 83 | Serial.print("\tY1: "); 84 | PrintHex (evt->Y, 0x80); 85 | Serial.print("\tX2: "); 86 | PrintHex (evt->Z1, 0x80); 87 | Serial.print("\tY2: "); 88 | PrintHex (evt->Z2, 0x80); 89 | Serial.print("\tRz: "); 90 | PrintHex (evt->Rz, 0x80); 91 | Serial.println("");*/ 92 | 93 | X1 = evt->X; 94 | // Serial.print(" X1 is:"); 95 | // Serial.print(X1); 96 | Y1 = evt->Y; 97 | // Serial.print(" Y1 is:"); 98 | // Serial.print(Y1); 99 | X2 = evt->Z2; 100 | // Serial.print(" X2 is:"); 101 | // Serial.print(X2); 102 | X3 = evt->Z1; 103 | // Serial.print(" X3 is:"); 104 | // Serial.print(X3); 105 | Y2 = evt->Rz; 106 | //Serial.print(" Y2 is:"); 107 | //Serial.println(Y2); 108 | } 109 | 110 | void JoystickEvents::OnHatSwitch(uint8_t hat) { 111 | Serial.print("Hat Switch: "); 112 | PrintHex (hat, 0x80); 113 | Serial.println(""); 114 | } 115 | 116 | void JoystickEvents::OnButtonUp(uint8_t but_id) { 117 | Serial.print("Up: "); 118 | Serial.println(but_id, DEC); 119 | } 120 | 121 | void JoystickEvents::OnButtonDn(uint8_t but_id) 122 | { 123 | Serial.print("Dn: "); 124 | Serial.println(but_id, DEC); 125 | } 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /imageprocessingpython/opencvdetect.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # USAGE 4 | # python match.py --template cod_logo.png --images 5 | images 6 | # import the necessary packages 7 | import sys 8 | import numpy as np 9 | import argparse 10 | import imutils 11 | import glob 12 | import cv2 13 | import time 14 | import RPi.GPIO as GPIO 15 | intTz1 = 11 16 | Shuttle Cock Throwing Robots 17 | 74 18 | intTz2 = 13 19 | intTz3 = 15 20 | GPIO.setmode(GPIO.BOARD) 21 | GPIO.setwarnings(False) 22 | GPIO.setup(intTz1, GPIO.OUT, initial=GPIO.LOW) 23 | GPIO.setup(intTz2, GPIO.OUT, initial=GPIO.LOW) 24 | GPIO.setup(intTz3, GPIO.OUT, initial=GPIO.LOW) 25 | j = 0 26 | startX = 0 27 | startY = 0 28 | endX = 0 29 | endY = 0 30 | c = 100 31 | c1 = 400 32 | i = 0 33 | cap = cv2.VideoCapture(0) 34 | while(cap.isOpened() == False): 35 | cap.release() 36 | cap = cv2.VideoCapture(0) 37 | ret, imageCam = cap.read() 38 | while(True): 39 | 40 | if i == 0 : 41 | 42 | ret, imageCam = cap.read() 43 | if j == 0 : 44 | template = cv2.imread('image.png') 45 | template = cv2.cvtColor(template, 46 | cv2.COLOR_BGR2GRAY) 47 | template = cv2.Canny(template, 50, 200) 48 | (tH, tW) = template.shape[:2] 49 | #cv2.imshow('Template', template) 50 | image = imageCam 51 | gray = cv2.cvtColor(image, 52 | cv2.COLOR_BGR2GRAY) 53 | found = None 54 | 55 | for scale in np.linspace(0.2, 1.0, 20)[::-1]: 56 | # resize the image according to the scale, and 57 | keep track 58 | # of the ratio of the resizing 59 | resized = imutils.resize(gray, 60 | width=int(gray.shape[1] * scale)) 61 | r = gray.shape[1] / float(resized.shape[1]) 62 | # if the resized image is smaller than the 63 | template, then break 64 | # from the loop 65 | if resized.shape[0] < tH or resized.shape[1] < 66 | tW: 67 | break 68 | # detect edges 69 | 70 | max_area = 0 71 | best_cnt = 1 72 | 73 | for cnt in contours: 74 | area = cv2.contourArea(cnt) 75 | if area > max_area: 76 | max_area = area 77 | best_cnt = cnt 78 | M = cv2.moments(best_cnt) 79 | cx, cy = int(M['m10']/M['m00']), 80 | int(M['m01']/M['m00']) 81 | #cv2.circle(blur,(cx,cy),10,(0,0,255),-1) 82 | #cv2.imwrite("Frameblur.jpg", blur) 83 | if (cx != 0 and cy != 0) : 84 | if (cx+startX >= startX and cx+startX <= endX) 85 | and (cy+startY >= startY and cy+startY <= endY) : 86 | print("Loaded") 87 | 88 | imageuse = 89 | imageCam[cy+startY:cy+c1+startY, cxc+30+startX:cx+c+startX] 90 | #cv2.imwrite("roi.jpg", imageuse) 91 | blurS=cv2.blur(imageuse,(5,5)) 92 | blurS=cv2.cvtColor(blurS, 93 | cv2.COLOR_BGR2HSV) 94 | lowerB = np.array([105,179,110], 95 | dtype="uint8")#Blue Shuttlecock 96 | upperB = np.array([140,255,255], 97 | dtype="uint8") 98 | lowerBr = np.array([10,100,20], 99 | dtype="uint8")#brown Shuttlecock 100 | upperBr = np.array([20,255,200], 101 | dtype="uint8") 102 | lowerG = np.array([20,183,158], 103 | dtype="uint8")#Golden Shuttlecock 104 | upperG = np.array([35,255,255], 105 | dtype="uint8") 106 | 107 | threshB = cv2.inRange(blurS, lowerB, 108 | upperB) 109 | threshB2 = threshB.copy() 110 | #cv2.imshow("fram", threshB2) 111 | threshBr = cv2.inRange(blurS, lowerBr, 112 | upperBr) 113 | threshBr2 = threshBr.copy() 114 | threshG = cv2.inRange(blurS, lowerG, 115 | upperG) 116 | threshG2 = threshG.copy() 117 | 118 | image_B, contours_B, hierarchy_B = 119 | cv2.findContours(threshB, cv2.RETR_LIST, 120 | cv2.CHAIN_APPROX_SIMPLE) 121 | image_Br, contours_Br, hierarchy_Br = 122 | cv2.findContours(threshBr, cv2.RETR_LIST, 123 | cv2.CHAIN_APPROX_SIMPLE) 124 | image_G, contours_G, hierarchy_G = 125 | cv2.findContours(threshG, cv2.RETR_LIST, 126 | cv2.CHAIN_APPROX_SIMPLE) 127 | 128 | max_area_B = 0 129 | best_cnt_B = 1 130 | 131 | max_area_Br = 0 132 | best_cnt_Br = 1 133 | max_area_G = 0 134 | best_cnt_G = 1 135 | 136 | for cnt_B in contours_B: 137 | area_B = cv2.contourArea(cnt_B) 138 | if area_B > max_area_B: 139 | max_area_B = area_B 140 | best_cnt_B = cnt_B 141 | for cnt_Br in contours_Br: 142 | area_Br = cv2.contourArea(cnt_Br) 143 | if area_Br > max_area_Br: 144 | max_area_Br = area_Br 145 | best_cnt_Br = cnt_Br 146 | for cnt_G in contours_G: 147 | area_G = cv2.contourArea(cnt_G) 148 | if area_G > max_area_G: 149 | max_area_G = area_G 150 | best_cnt_G = cnt_G 151 | M_B = cv2.moments(best_cnt_B) 152 | cx_B, cy_B = int(M_B['m10']/M_B['m00']), 153 | int(M_B['m01']/M_B['m00']) 154 | 155 | M_Br = cv2.moments(best_cnt_Br) 156 | cx_Br, cy_Br = 157 | int(M_Br['m10']/M_Br['m00']), 158 | int(M_Br['m01']/M_Br['m00']) 159 | 160 | M_G = cv2.moments(best_cnt_G) 161 | cx_G, cy_G = int(M_G['m10']/M_G['m00']), 162 | int(M_G['m01']/M_G['m00']) 163 | if(cx_B != 0 and cy_B !=0 ): 164 | GPIO.output(intTz1, GPIO.HIGH) 165 | print("TZ1") 166 | 167 | sys.exit() 168 | '''if(cx_Br != 0 and cy_Br !=0 ): 169 | GPIO.output(intTz2, GPIO.HIGH) 170 | sys.exit()''' 171 | 172 | 173 | if(cx_G != 0 and cy_G !=0 ): 174 | GPIO.output(intTz3, GPIO.HIGH) 175 | print("TZ3") 176 | sys.exit() 177 | #cv2.waitKey(0) & 0xFF 178 | 179 | else : 180 | print("Unloaded") 181 | GPIO.output(intTz1, GPIO.LOW) 182 | GPIO.output(intTz2, GPIO.LOW) 183 | GPIO.output(intTz3, GPIO.LOW) 184 | 185 | #cv2.imwrite("final.jpg", imageCam) 186 | 187 | #if cv2.waitKey(1) & 0xFF == ord('q'): 188 | #break 189 | cap.release() 190 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /HC05-master/README.md: -------------------------------------------------------------------------------- 1 | HC05 2 | ==== 3 | An Arduino library for the HC-05 Bluetooth ITead Studio HC-05 Serial 4 | Port Module. 5 | 6 | See the `LICENSE` file for copyright and license information. 7 | 8 | The serial port can be configured as any supported Serial port or 9 | a SoftwareSerial port. 10 | 11 | Includes a demonstration program that can be uses to change the name 12 | reported by an HC-05 module. 13 | 14 | Additional information is available as an 15 | [exercise](http://rockingdlabs.dunmire.org/exercises-experiments/hc05-bluetooth) 16 | at [RockingD Labs](http://rockingdlabs.dunmire.org). 17 | 18 | 19 | Components 20 | ---------- 21 | `HC05` 22 | A class for controlling and communicating through an ITead Studio 23 | HC-05 Serial Port Module. This class inherits from the Stream class. 24 | 25 | 26 | ### Methods: 27 | The Stream class is extended with the following methods. 28 | 29 | ##### `findBaud()` 30 | 31 | Determine HC-05 communications speed. Make this call in setup() 32 | instead of `begin()`. `begin()` is still avaialble and can be used 33 | inplace of `findBaud()` if you know the HC-05 communications speed. 34 | 35 | ##### `setBaud(unsigned long rate)` 36 | Specify the HC-05 communications speed. The speed is non-volatile so 37 | call this only when the rate returned by findBaud() is not the one 38 | you require. 39 | 40 | ##### `setBaud(unsigned long rate, unsigned long parity, unsigned long stopbits)` 41 | Use this method when you need something besides the default no 42 | parity, one stop bit settings that are the default. 43 | __CAUTION!__ The HC-05 supports many serial configurations that are not 44 | compatible with an Arduino. For example, the Arduino software serial 45 | port port supports only no parity, one stop bit settings. 46 | 47 | ##### `cmd()` 48 | Send a command to the module. The 'key' (cmdPin) pin is activated to 49 | put the module in command mode where 'AT' commands are recognized. 50 | 51 | ##### `cmdMode2Start(int pwrPin)` 52 | This is an alternate command mode. This 2nd command mode has the 53 | advantage forcing the HC-05 into a know communications speed: 38400. 54 | However, entering this 2nd command mode requires switching the power 55 | to the HC-05. 56 | 57 | ##### `cmdMode2End()` 58 | Exits the alternate command mode, leaving the power to the HC-05 on. 59 | 60 | ##### `connected()` (Only if HC05_STATE_PIN is defined in `HC05.h`) 61 | Returns true when a BT connection has been established. 62 | 63 | ##### `write()` 64 | ##### `print*()` 65 | The `write()`, and `print*()`, methods block until there is a BT 66 | connection. 67 | 68 | Example Programs 69 | ---------------- 70 | The default library configuration uses a software serial port. The 71 | example programs will work with either a hardware or a software serial 72 | port. The configuration is changed by modifying the `HC05.h` file. 73 | 74 | See the `SoftwareSerial.fzz` file for the proper default connections. 75 | (`.fzz` files can be read by the free program available from 76 | [Fritzing](http://fritzing.org/home/)) 77 | 78 | `changeName` 79 | This application is one of the reasons I wrote this library. I 80 | wanted to be able to change the name reported by the HC-05 because I 81 | have multiple HC-05 modules that I kept mixing up. With this program 82 | you can set the name of the HC-05 module to reflect something 83 | physically identifying (or anything else that helps you tell your 84 | modules apart). 85 | 86 | `echo` 87 | Echo characters as they are received. 88 | 89 | `hc05_test` 90 | Tests the disconnect command (AT+DISC). This was something I used 91 | during development and probably is not of general interest. 92 | 93 | `recover` 94 | This example used the 2nd command mode to _recover_ the HC-05 when 95 | its serial port settings are incompatible with the Arduino serial 96 | ports. Power to HC-05 must be controlled by an Arduino pin. 97 | See the `Recovery.fzz` diagram for suitable connections. 98 | 99 | `findBaudTest` 100 | Tests both setBaud() and findBaud() by trying every combination of 101 | supported rates. The output from this example looks best if 102 | DEBUG_HC05 is not defined. (Simply comment out that line in HC05.h). 103 | 104 | 105 | Installation 106 | ------------ 107 | ### Option 1: Git (Recommended) 108 | * Follow this [GitHub repository](https://github.com/jdunmire/HC05) 109 | and use `git` to track your own changes by cloning: 110 | 111 | $ cd ~/sketchbook/libraries 112 | $ git clone https://github.com/jdunmire/HC05.git 113 | 114 | * Start the Arduino IDE and you should find `HC05` in the 115 | libraries section. 116 | 117 | ### Option 2: Source only 118 | * Download a ZIP file. The ZIP button at 119 | [GitHub](https://github.com/jdunmire/HC05) will always get the 120 | latest version, but you may prefer one of the 121 | [tagged](https://github.com/jdunmire/HC05/tags) versions. 122 | 123 | * Unpack the zip file into your sketchbook library directory 124 | (`~/sketchbook/libraries` on Linux). 125 | 126 | * Rename the resulting directory (or create a symlink) to 127 | ~/sketchbook/libraries/HC05 128 | 129 | * Start the Arduino IDE and you should find `HC05` in the libraries 130 | section. 131 | 132 | ### Configuration 133 | By default the library is configured for a software serial port and 134 | debugging output to the hardware serial port (Serial) is turned on. You 135 | will need to edit the HC05.h file if you want to change those settings. 136 | 137 | See the `SoftwareSerial.fzz` file for the proper default connections. 138 | The `HardwareSerial.fzz` shows the hardware port alternative. The files 139 | can be read by the free program available from 140 | [Fritzing](http://fritzing.org/home/) 141 | 142 | The Bluetooth port is `btSerial` and must be setup as shown at the top 143 | of the Example sketches. If debugging output is enabled in HC05.h (it is 144 | by default) then your sketch must include a DEBUG_BEGIN(baud) command to 145 | initialize the debug output port and set it's baud rate. 146 | 147 | #### Hardware Serial Port Issues for UNO 148 | Using the hardware serial port on the UNO comes with some caveats: 149 | 150 | * You will have to disconnect the HC-05 module to upload a sketch. 151 | * If you use the Arduino `Serial Monitor` you will see the traffic to 152 | and from the HC-05 serial port. If you type in the `Serial Monitor` 153 | it will interfere with the HC-05 traffic. 154 | 155 | -------------------------------------------------------------------------------- /JoystickControl/joystick.cpp: -------------------------------------------------------------------------------- 1 | #include "joystick.h" 2 | 3 | USB Usb; 4 | USBHub Hub(&Usb); 5 | HIDUniversal Hid(&Usb); 6 | JoystickEvents JoyEvents; 7 | JoystickReportParser Joy(&JoyEvents); 8 | 9 | 10 | void Motion::joy() 11 | { 12 | Usb.Task(); 13 | button_read = JoyEvents.button_read; 14 | hat_read = JoyEvents.hat_read; 15 | 16 | Serial.print("Button read = "); 17 | Serial.println(button_read); 18 | 19 | Serial.print("hat read = "); 20 | Serial.println(hat_read); 21 | 22 | 23 | Serial.print("Speed Divisor = "); 24 | Serial.println(speed_divisor); 25 | 26 | if (button_read == 256) //tejas 27 | { 28 | state = 0; 29 | } 30 | 31 | 32 | if (button_read == 16) //tejas 33 | { 34 | speed_divisor += 0.5; 35 | delay(100); 36 | } 37 | 38 | 39 | if (button_read == 64) //tejas 40 | { 41 | if (speed_divisor != 1) 42 | { 43 | speed_divisor -= 0.5; 44 | delay(100); 45 | } 46 | } 47 | 48 | 49 | if (button_read == 32) //tejas 50 | { 51 | speed_divisor += 0.25; 52 | delay(100); 53 | } 54 | 55 | 56 | if (button_read == 128) //tejas 57 | { 58 | if (speed_divisor != 1) 59 | { 60 | speed_divisor -= 0.25; 61 | delay(100); 62 | } 63 | } 64 | 65 | 66 | 67 | 68 | while(state == 0) 69 | { 70 | Usb.Task(); 71 | button_read = JoyEvents.button_read; 72 | // hat_read = JoyEvents.hat_read; 73 | 74 | analogWrite(4,0); 75 | analogWrite(5,0); 76 | analogWrite(6,0); 77 | analogWrite(7,0); 78 | 79 | if(button_read == 512) // state changer 80 | {state = 1;} 81 | } 82 | 83 | 84 | if(state == 1) // state condition 85 | { 86 | 87 | motor_rotation(); 88 | if(hat_read == 1) 89 | { Serial2.print("a"); 90 | Serial2.print("0"); delay(100);} 91 | else if(hat_read == 16) 92 | { Serial2.print("a"); 93 | Serial2.print("1"); delay(100);} 94 | 95 | 96 | Serial.println(hat_read); 97 | Serial.println(button_read); 98 | 99 | if(hat_read == 4) 100 | { Serial2.print("b"); 101 | Serial2.print("0"); delay(100);} 102 | else if(hat_read == 64) 103 | { Serial2.print("b"); 104 | Serial2.print("1"); delay(100);} 105 | } 106 | } 107 | 108 | 109 | 110 | 111 | 112 | void Motion::init() 113 | { 114 | Serial.begin(115200); 115 | #if !defined(__MIPSEL__) 116 | while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 117 | #endif 118 | Serial.println("Start"); 119 | 120 | if (Usb.Init() == -1) 121 | Serial.println("OSC did not start."); 122 | 123 | delay(200); 124 | 125 | if (!Hid.SetReportParser(0, &Joy)) 126 | ErrorMessage (PSTR("SetReportParser"), 1); 127 | pinMode(8,OUTPUT); 128 | pinMode(9,OUTPUT); 129 | pinMode(10,OUTPUT); 130 | pinMode(11,OUTPUT); 131 | } 132 | 133 | 134 | void Motion::motor_rotation() 135 | { 136 | 137 | if(JoyEvents.Y1 < 128) 138 | { 139 | if(JoyEvents.X2 < 128) 140 | { 141 | Y1 = map(JoyEvents.Y1, 0, 128, 0, 250); 142 | X2 = map(JoyEvents.X2, 128, 0, 0, 250); 143 | avg = (Y1 + X2)/2; 144 | diagonal_flt(avg,avg,avg,avg); 145 | Serial.println("Diagonal forward-left motion"); 146 | } 147 | 148 | if(JoyEvents.X2 > 128) 149 | { 150 | Y1 = map(JoyEvents.Y1, 0, 128, 0, 250); 151 | X2 = map(JoyEvents.X2, 128, 255, 0, 250); 152 | avg = (Y1 + X2)/2; 153 | diagonal_frt(avg,avg,avg,avg); 154 | Serial.println("Diagonal forward-right motion"); 155 | } 156 | 157 | if(JoyEvents.Y2 > 128) 158 | { 159 | Y1 = map(JoyEvents.Y1, 128, 0, 0, 125); 160 | Y2 = map(JoyEvents.Y2, 128, 255, 0, 125); 161 | avg = (Y1 + Y2)/2; 162 | avg = avg/speed_divisor; 163 | right_rotation(avg,avg,avg,avg); 164 | Serial.println("Right rotation"); 165 | } 166 | else 167 | { 168 | Y1 = map(JoyEvents.Y1, 128, 0, 0, 120); 169 | Y1 = Y1/speed_divisor; 170 | dcforward(Y1,Y1,Y1,Y1); 171 | Serial.println("Forward motion"); 172 | } 173 | 174 | } 175 | 176 | 177 | 178 | else if(JoyEvents.Y1>128) 179 | { 180 | if(JoyEvents.X2 < 128) 181 | { 182 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 250); 183 | X2 = map(JoyEvents.X2, 128, 0, 0, 250); 184 | avg = (Y1 + X2)/2; 185 | diagonal_blt(avg,avg,avg,avg); 186 | Serial.println("Diagonal backward-left motion"); 187 | } 188 | 189 | else if(JoyEvents.X2 > 128) 190 | { 191 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 250); 192 | X2 = map(JoyEvents.X2, 128, 255, 0, 250); 193 | avg = (Y1 + X2)/2; 194 | diagonal_brt(avg,avg,avg,avg); 195 | Serial.println("Diagonal backward-right motion"); 196 | } 197 | if(JoyEvents.Y2<128) 198 | { 199 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 125); //chinmayee 200 | Y2 = map(JoyEvents.Y2, 128, 0, 0, 125); //chinmayee 201 | avg = (Y1 + Y2)/2; 202 | avg = avg/speed_divisor; 203 | left_rotation(avg,avg,avg,avg); 204 | Serial.println("Left rotation"); 205 | } 206 | else 207 | { 208 | Y1 = map(JoyEvents.Y1, 128, 255, 0, 250); 209 | Y1 = Y1/speed_divisor; 210 | dcreverse(Y1,Y1,Y1,Y1); 211 | Serial.println("Reverse motion"); 212 | } 213 | } 214 | 215 | 216 | else if(JoyEvents.X2 < 128) 217 | { 218 | X2 = map(JoyEvents.X2, 128, 0, 0, 250); 219 | X2 = X2/speed_divisor; 220 | dcleft(X2,X2,X2,X2); 221 | Serial.println("Left motion"); 222 | } 223 | 224 | else if(JoyEvents.X2 > 128) 225 | { 226 | X2 = map(JoyEvents.X2, 128, 255, 0, 250); 227 | X2 = X2/speed_divisor; 228 | dcright(X2,X2,X2,X2); 229 | Serial.println("Right motion"); 230 | } 231 | 232 | else { stopp(); } 233 | 234 | 235 | } 236 | 237 | -------------------------------------------------------------------------------- /HC05-master/HC05.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifdef DEBUG_SW_PORT 5 | SoftwareSerial DEBUG_SW_PORT; 6 | #endif 7 | 8 | #ifdef HC05_SOFTWARE_SERIAL 9 | HC05::HC05(int cmdPin, int statePin, uint8_t rx, uint8_t tx):_btSerial(rx,tx,0) 10 | #else 11 | #define _btSerial HC05_HW_SERIAL_PORT 12 | HC05::HC05(int cmdPin, int statePin) 13 | #endif 14 | { 15 | pinMode(cmdPin, OUTPUT); 16 | _cmdPin = cmdPin; 17 | cmdMode = false; 18 | #ifdef HC05_STATE_PIN 19 | pinMode(statePin, INPUT); 20 | _statePin = statePin; 21 | #endif 22 | _bufsize = sizeof(_buffer)/sizeof(char); 23 | } 24 | 25 | static const unsigned long rates[] = 26 | {4800,9600,19200,38400,57600,115200}; 27 | 28 | unsigned long HC05::findBaud() 29 | { 30 | const int bt_rx = 4; 31 | const int bt_tx = 5; 32 | int numRates = sizeof(rates)/sizeof(unsigned long); 33 | int response = false; 34 | int recvd = 0; 35 | //char _buffer[128]; 36 | 37 | DEBUG_PRINTLN("findBaud"); 38 | setCmdPin(HIGH); 39 | delay(100); 40 | for(int rn = 0; rn < numRates; rn++) 41 | { 42 | _btSerial.begin(rates[rn]); 43 | _btSerial.setTimeout(100); 44 | _btSerial.flush(); 45 | DEBUG_WRITE("Trying "); 46 | DEBUG_PRINT(rates[rn]); 47 | DEBUG_WRITE("... "); 48 | _btSerial.write("AT\r\n"); 49 | recvd = _btSerial.readBytes(_buffer,_bufsize); 50 | if (recvd > 0) 51 | { 52 | DEBUG_PRINTLN("Found."); 53 | // FIXME: refactor to a single return 54 | setCmdPin(LOW); 55 | return(rates[rn]); 56 | } 57 | else 58 | { 59 | DEBUG_PRINTLN("x"); 60 | } 61 | } 62 | setCmdPin(LOW); 63 | DEBUG_WRITE("\r\nNo connection\r\n"); 64 | return(0); 65 | } 66 | 67 | int HC05::cmd(const char* cmd, unsigned long timeout) 68 | { 69 | int recvd = 0; 70 | DEBUG_PRINTLN(cmd); 71 | 72 | setCmdPin(HIGH); 73 | // No spec for how long it takes to enter command mode, but 100ms 74 | // seems to work- assuming the output has been drained. 75 | delay(100); 76 | _btSerial.write(cmd); 77 | _btSerial.write("\r\n"); 78 | _btSerial.setTimeout(timeout); 79 | do 80 | { 81 | // ATTENTION: At least through Arduino v1.0.3, it is not possible 82 | // to tell the difference between a timeout and 83 | // receiving only the termination character (NL in this 84 | // case), because the termination character is not 85 | // returned and timeout is not returned as a unique 86 | // indication. 87 | // In this case the result would be an early return 88 | // of a multiline response before the OK is received. 89 | // The return would incorrectly indicate an error (no 90 | // OK response). 91 | recvd = _btSerial.readBytesUntil('\n',_buffer,_bufsize); 92 | if (recvd > 0) 93 | { 94 | DEBUG_WRITE((uint8_t *)_buffer,recvd); 95 | DEBUG_WRITE('\n'); 96 | } 97 | else 98 | { 99 | DEBUG_PRINTLN("timeout 1"); 100 | } 101 | } 102 | while ((recvd > 0) && (_buffer[0] != 'O' || _buffer[1] != 'K')); 103 | 104 | setCmdPin(LOW); 105 | 106 | // Empirically determined that it takes some time to reliably exit 107 | // command mode. The appeared to be a baud rate dependency and with 108 | // >100ms required at 9600 baud. 109 | delay(150); 110 | return((_buffer[0] == 'O' && _buffer[1] == 'K')); 111 | } 112 | 113 | 114 | /* 115 | * If setBaud() is called while the HC-05 is connected, then 116 | * it will be disconnected when AT+RESET command is issued, and 117 | * it may take 2 (or more?) connection attempts to reconnect. The extra 118 | * connect attempts may be a host side issue and not specific to the 119 | * HC-05 module. 120 | */ 121 | void HC05::setBaud(unsigned long baud, unsigned long stopbits, unsigned long parity) 122 | { 123 | int recvd = 0; 124 | setCmdPin(HIGH); 125 | delay(200); 126 | DEBUG_WRITE("AT+UART="); 127 | _btSerial.write("AT+UART="); 128 | DEBUG_PRINT(baud); 129 | _btSerial.print(baud); 130 | 131 | DEBUG_PRINT(","); 132 | _btSerial.print(","); 133 | 134 | DEBUG_PRINT(stopbits); 135 | _btSerial.print(stopbits); 136 | 137 | DEBUG_PRINT(","); 138 | _btSerial.print(","); 139 | 140 | DEBUG_PRINT(parity); 141 | _btSerial.print(parity); 142 | 143 | DEBUG_WRITE("\r\n"); 144 | _btSerial.write("\r\n"); 145 | 146 | recvd = _btSerial.readBytes(_buffer,_bufsize); 147 | if (recvd > 0) 148 | { 149 | DEBUG_WRITE((uint8_t *)_buffer,recvd); 150 | } 151 | else 152 | { 153 | DEBUG_PRINTLN("timeout 2"); 154 | } 155 | cmd("AT+RESET"); 156 | setCmdPin(LOW); 157 | _btSerial.begin(baud); 158 | delay(1000); 159 | } 160 | 161 | // Usually parity is none, and there is only one stop bit, so this 162 | // simpler call will do the job. 163 | void HC05::setBaud(unsigned long baud) 164 | { 165 | setBaud(baud, 0, 0); 166 | } 167 | 168 | 169 | int HC05::available() 170 | { 171 | return _btSerial.available(); 172 | } 173 | 174 | int HC05::peek() 175 | { 176 | return _btSerial.peek(); 177 | } 178 | 179 | void HC05::flush() 180 | { 181 | _btSerial.flush(); 182 | } 183 | 184 | int HC05::read() 185 | { 186 | return _btSerial.read(); 187 | } 188 | 189 | void HC05::begin(unsigned long baud) 190 | { 191 | _btSerial.begin(baud); 192 | } 193 | 194 | #ifndef HC05_SOFTWARE_SERIAL 195 | // only hardware serial ports support parity/stop bit configuration 196 | void HC05::begin(unsigned long baud, uint8_t config) 197 | { 198 | _btSerial.begin(baud, config); 199 | } 200 | #endif 201 | 202 | #ifdef HC05_STATE_PIN 203 | bool HC05::connected() 204 | { 205 | return(digitalRead(_statePin)?true:false); 206 | } 207 | #endif 208 | 209 | size_t HC05::write(uint8_t byte) 210 | { 211 | #ifdef HC05_STATE_PIN 212 | // The down side of this check is that the status gets checked for 213 | // every byte written out. That doesn't seem efficient. 214 | if (digitalRead(_statePin) != HIGH) 215 | { 216 | DEBUG_PRINT("No Connection, waiting..."); 217 | while (digitalRead(_statePin) == LOW) 218 | { 219 | delay(100); 220 | } 221 | DEBUG_PRINTLN("OK"); 222 | } 223 | #endif 224 | return _btSerial.write(byte); 225 | } 226 | 227 | 228 | void HC05::cmdMode2Start(int pwrPin) 229 | { 230 | pinMode(pwrPin, OUTPUT); 231 | digitalWrite(pwrPin, LOW); 232 | delay(250); // off or reset time 233 | digitalWrite(_cmdPin, HIGH); 234 | digitalWrite(pwrPin, HIGH); 235 | cmdMode = true; 236 | _btSerial.begin(38400); 237 | delay(1500); // time for the HC05 to initialize 238 | } 239 | 240 | 241 | void HC05::cmdMode2End(void) 242 | { 243 | digitalWrite(_cmdPin, LOW); 244 | cmdMode = false; 245 | delay(1000); 246 | } 247 | 248 | void HC05::setCmdPin(bool state) 249 | { 250 | if (cmdMode == false) 251 | { 252 | digitalWrite(_cmdPin, state); 253 | } 254 | } 255 | -------------------------------------------------------------------------------- /Test equipments/Test_Program/DCmotor.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "DCMotor.h" 3 | #define R 36.25 4 | #define encoderPin1 2 5 | #define encoderPin2 3 6 | 7 | 8 | 9 | //Variables for motor 10 | 11 | extern uint8_t pwm1; 12 | extern uint8_t pwm2; 13 | extern uint8_t pwm3; 14 | extern uint8_t pwm4; 15 | 16 | extern uint8_t dir1; 17 | extern uint8_t dir2; 18 | extern uint8_t dir3; 19 | extern uint8_t dir4; 20 | extern uint8_t PPR; 21 | 22 | //Variables for motor 23 | 24 | 25 | void DCMotor::stop1() //function used to stop motor 26 | { 27 | analogWrite(pwm1,0); 28 | analogWrite(pwm2,0); 29 | analogWrite(pwm3,0); 30 | analogWrite(pwm4,0); 31 | } 32 | 33 | 34 | 35 | void DCMotor::stop() //function used to stop motor 36 | { 37 | int i; 38 | for (i = max; i >= 0; (i = (i-d))) 39 | { 40 | if (ssfl > 0) 41 | { 42 | analogWrite(pwm1, i); 43 | } 44 | 45 | if (ssfr > 0) 46 | { 47 | analogWrite(pwm2, i); 48 | } 49 | 50 | if (ssbl > 0) 51 | { 52 | analogWrite(pwm3, i); 53 | } 54 | 55 | if (ssbr > 0) 56 | { 57 | analogWrite(pwm4, i); 58 | } 59 | 60 | delay(ds); 61 | } 62 | max = 0; 63 | } 64 | 65 | void DCMotor::motorinit() //Setting motor pins as output 66 | { 67 | pinMode(encoderPin1,INPUT); 68 | pinMode(encoderPin2,INPUT); 69 | 70 | pinMode(dir1,OUTPUT); 71 | pinMode(dir2,OUTPUT); 72 | Serial.println("Front motor set as output"); 73 | 74 | pinMode(dir3,OUTPUT); 75 | pinMode(dir4,OUTPUT); 76 | Serial.println("Back motor set as output"); 77 | 78 | pinMode(pwm1,OUTPUT); 79 | pinMode(pwm2,OUTPUT); 80 | pinMode(pwm3,OUTPUT); 81 | pinMode(pwm4,OUTPUT); 82 | Serial.println("Enable pins set as output"); 83 | } 84 | 85 | void DCMotor::dcforward(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr) //Giving forward motion 86 | { 87 | stop(); 88 | max = max(sfl, sfr); 89 | max = max(max, sbl); 90 | max = max(max, sbr); 91 | 92 | 93 | 94 | frontlt_CW(); //Giving clockwise motion to front left wheel 95 | frontrt_CCW(); //Giving counter-clockwise motion to front right wheel 96 | 97 | backlt_CCW(); //Giving counter-clockwise motion to back left wheel 98 | backrt_CW(); 99 | 100 | 101 | for (int i=0; i <= max; i = i+k) 102 | { 103 | if (i < sfl) 104 | { 105 | analogWrite(pwm1, i); 106 | } 107 | 108 | if (i < sfr) 109 | { 110 | analogWrite(pwm2, i); 111 | } 112 | 113 | if (i < sbl) 114 | { 115 | analogWrite(pwm3, i); 116 | } 117 | 118 | if (i < sbr) 119 | { 120 | analogWrite(pwm4, i); 121 | } 122 | delay(d); 123 | 124 | 125 | } 126 | 127 | Serial.print("Speed of Front left motor set to: "); 128 | Serial.println(sfl); 129 | 130 | Serial.print("Speed of Front right motor set to: "); 131 | Serial.println(sfr); 132 | 133 | Serial.print("Speed of Back left motor set to: "); 134 | Serial.println(sbl); 135 | 136 | Serial.print("Speed of Back right motor set to: "); 137 | Serial.println(sbr); 138 | ssfr = sfr; 139 | ssfl = sfl; 140 | ssbr = sbr; 141 | ssbl = sbl; 142 | 143 | //Giving clockwise motion to back right wheel 144 | } 145 | 146 | void DCMotor::dcreverse(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr) //Giving backward motion 147 | { 148 | stop(); 149 | 150 | max = max(sfl, sfr); 151 | max = max(max, sbl); 152 | max = max(max, sbr); 153 | 154 | 155 | 156 | frontlt_CCW();//Giving counter-clockwise motion to front left wheel 157 | frontrt_CW(); //Giving clockwise motion to front right wheel 158 | 159 | backlt_CW(); //Giving clockwise motion to back left wheel 160 | backrt_CCW(); 161 | for (int i=0; i <= max; i = i+k) 162 | { 163 | if (i < sfl) 164 | { 165 | analogWrite(pwm1, i); 166 | } 167 | 168 | if (i < sfr) 169 | { 170 | analogWrite(pwm2, i); 171 | } 172 | 173 | if (i < sbl) 174 | { 175 | analogWrite(pwm3, i); 176 | } 177 | 178 | if (i < sbr) 179 | { 180 | analogWrite(pwm4, i); 181 | } 182 | delay(d); 183 | } 184 | 185 | ssfr = sfr; 186 | ssfl = sfl; 187 | ssbr = sbr; 188 | ssbl = sbl; 189 | //Giving counter-clockwise motion to back right wheel 190 | } 191 | 192 | void DCMotor::dcleft(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr) // Motion towards left 193 | { 194 | stop(); 195 | max = max(sfl, sfr); 196 | max = max(max, sbl); 197 | max = max(max, sbr); 198 | 199 | 200 | frontlt_CCW(); //Giving counter-clockwise motion to front left wheel 201 | frontrt_CCW(); //Giving counter-clockwise motion to front right wheel 202 | 203 | backlt_CCW(); //Giving counter-clockwise motion to back left wheel 204 | backrt_CCW(); //Giving counter-clockwise motion to back right wheel 205 | 206 | frontlt_CCW();//Giving counter-clockwise motion to front left wheel 207 | frontrt_CW(); //Giving clockwise motion to front right wheel 208 | 209 | backlt_CW(); //Giving clockwise motion to back left wheel 210 | backrt_CCW(); 211 | 212 | 213 | for (int i=0; i <= max; i = i+k) 214 | { 215 | if (i < sfl) 216 | { 217 | analogWrite(pwm1, i); 218 | } 219 | 220 | if (i < sfr) 221 | { 222 | analogWrite(pwm2, i); 223 | } 224 | 225 | if (i < sbl) 226 | { 227 | analogWrite(pwm3, i); 228 | } 229 | 230 | if (i < sbr) 231 | { 232 | analogWrite(pwm4, i); 233 | } 234 | delay(d); 235 | } 236 | ssfr = sfr; 237 | ssfl = sfl; 238 | ssbr = sbr; 239 | ssbl = sbl; 240 | 241 | } 242 | 243 | void DCMotor::dcright(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr) // Motion towards right 244 | { 245 | frontlt_CW(); //Giving clockwise motion to front left wheel 246 | frontrt_CW(); //Giving clockwise motion to front right wheel 247 | 248 | backlt_CCW(); //Giving counter-clockwise motion to back left wheel 249 | backrt_CW(); //Giving clockwise motion to back right wheel 250 | 251 | frontlt_CCW();//Giving counter-clockwise motion to front left wheel 252 | frontrt_CW(); //Giving clockwise motion to front right wheel 253 | 254 | backlt_CW(); //Giving clockwise motion to back left wheel 255 | backrt_CCW(); 256 | 257 | max = max(sfl, sfr); 258 | max = max(max, sbl); 259 | max = max(max, sbr); 260 | 261 | 262 | stop(); 263 | for (int i=0; i <= max; i = i+k) 264 | { 265 | if (i < sfl) 266 | { 267 | analogWrite(pwm1, i); 268 | } 269 | 270 | if (i < sfr) 271 | { 272 | analogWrite(pwm2, i); 273 | } 274 | 275 | if (i < sbl) 276 | { 277 | analogWrite(pwm3, i); 278 | } 279 | 280 | if (i < sbr) 281 | { 282 | analogWrite(pwm4, i); 283 | } 284 | delay(d); 285 | } 286 | ssfr = sfr; 287 | ssfl = sfl; 288 | ssbr = sbr; 289 | ssbl = sbl; 290 | } 291 | 292 | void DCMotor::diagonal_flt(uint8_t sfl ,uint8_t sfr,uint8_t sbl,uint8_t sbr ) // Diagonal motion towards front-left 293 | { 294 | 295 | sfl=0; 296 | sbr=0; 297 | frontrt_CCW(); //Giving counter-clockwise motion to front right wheel 298 | backlt_CCW(); //Giving counter-clockwise motion to back left wheel 299 | 300 | max = max(sfl, sfr); 301 | max = max(max, sbl); 302 | max = max(max, sbr); 303 | 304 | 305 | stop(); 306 | 307 | for (int i=0; i <= max; i = i+k) 308 | { 309 | if (i < sfl) 310 | { 311 | analogWrite(pwm1, i); 312 | } 313 | 314 | if (i < sfr) 315 | { 316 | analogWrite(pwm2, i); 317 | } 318 | 319 | if (i < sbl) 320 | { 321 | analogWrite(pwm3, i); 322 | } 323 | 324 | if (i < sbr) 325 | { 326 | analogWrite(pwm4, i); 327 | } 328 | delay(d); 329 | } 330 | ssfr = sfr; 331 | ssfl = sfl; 332 | ssbr = sbr; 333 | ssbl = sbl; 334 | 335 | 336 | } 337 | 338 | void DCMotor::diagonal_frt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr) // Diagonal motion towards front-right 339 | { 340 | sfr=0; 341 | sbl=0; 342 | frontlt_CW(); //Giving clockwise motion to front left wheel 343 | backrt_CW(); //Giving clockwise motion to back right wheel 344 | 345 | max = max(sfl, sfr); 346 | max = max(max, sbl); 347 | max = max(max, sbr); 348 | 349 | 350 | stop(); 351 | 352 | for (int i=0; i <= max; i = i+k) 353 | { 354 | if (i < sfl) 355 | { 356 | analogWrite(pwm1, i); 357 | } 358 | 359 | if (i < sfr) 360 | { 361 | analogWrite(pwm2, i); 362 | } 363 | 364 | if (i < sbl) 365 | { 366 | analogWrite(pwm3, i); 367 | } 368 | 369 | if (i < sbr) 370 | { 371 | analogWrite(pwm4, i); 372 | } 373 | delay(d); 374 | } 375 | ssfr = sfr; 376 | ssfl = sfl; 377 | ssbr = sbr; 378 | ssbl = sbl; 379 | 380 | } 381 | 382 | void DCMotor::diagonal_blt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr) // Diagonal motion towards back-left 383 | { 384 | sfr=0; 385 | sbl=0; 386 | frontlt_CCW(); //Giving counter-clockwise motion to front left wheel 387 | backrt_CCW(); //Giving counter-clockwise motion to back right wheel 388 | 389 | 390 | max = max(sfl, sfr); 391 | max = max(max, sbl); 392 | max = max(max, sbr); 393 | 394 | 395 | stop(); 396 | 397 | for (int i=0; i <= max; i = i+k) 398 | { 399 | if (i < sfl) 400 | { 401 | analogWrite(pwm1, i); 402 | } 403 | 404 | if (i < sfr) 405 | { 406 | analogWrite(pwm2, i); 407 | } 408 | 409 | if (i < sbl) 410 | { 411 | analogWrite(pwm3, i); 412 | } 413 | 414 | if (i < sbr) 415 | { 416 | analogWrite(pwm4, i); 417 | } 418 | delay(d); 419 | } 420 | ssfr = sfr; 421 | ssfl = sfl; 422 | ssbr = sbr; 423 | ssbl = sbl; 424 | 425 | } 426 | 427 | void DCMotor::diagonal_brt(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr) // Diagonal motion towards back-right 428 | { 429 | sfl=0; 430 | sbr=0; 431 | frontrt_CW(); //Giving clockwise motion to front right wheel 432 | backlt_CW(); //Giving clockwise motion to back left wheel 433 | 434 | max = max(sfl, sfr); 435 | max = max(max, sbl); 436 | max = max(max, sbr); 437 | 438 | stop(); 439 | 440 | for (int i=0; i <= max; i = i+k) 441 | { 442 | if (i < sfl) 443 | { 444 | analogWrite(pwm1, i); 445 | } 446 | 447 | if (i < sfr) 448 | { 449 | analogWrite(pwm2, i); 450 | } 451 | 452 | if (i < sbl) 453 | { 454 | analogWrite(pwm3, i); 455 | } 456 | 457 | if (i < sbr) 458 | { 459 | analogWrite(pwm4, i); 460 | } 461 | delay(d); 462 | } 463 | ssfr = sfr; 464 | ssfl = sfl; 465 | ssbr = sbr; 466 | ssbl = sbl; 467 | 468 | } 469 | 470 | void DCMotor::left_rotation(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr) // Turning to left 471 | { 472 | sfl=0; 473 | sbr=0; 474 | frontrt_CCW(); //Giving counter-clockwise motion to front right wheel 475 | backlt_CW(); //Giving clockwise motion to back left wheel 476 | 477 | max = max(sfl, sfr); 478 | max = max(max, sbl); 479 | max = max(max, sbr); 480 | 481 | //stop(); 482 | for (int i=0; i <= max; i = i+k) 483 | { 484 | if (i < sfl) 485 | { 486 | analogWrite(pwm1, i); 487 | } 488 | 489 | if (i < sfr) 490 | { 491 | analogWrite(pwm2, i); 492 | } 493 | 494 | if (i < sbl) 495 | { 496 | analogWrite(pwm3, i); 497 | } 498 | 499 | if (i < sbr) 500 | { 501 | analogWrite(pwm4, i); 502 | } 503 | delay(d); 504 | } 505 | ssfr = sfr; 506 | ssfl = sfl; 507 | ssbr = sbr; 508 | ssbl = sbl; 509 | 510 | analogWrite(pwm1,sfl); 511 | analogWrite(pwm2,sfr); 512 | analogWrite(pwm3,sbl); 513 | analogWrite(pwm4,sbr); 514 | } 515 | 516 | void DCMotor::right_rotation(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr) // Turning to right 517 | { 518 | sfl=0; 519 | sbr=0; 520 | 521 | frontrt_CW(); //Giving clockwise motion to front right wheel 522 | backlt_CCW(); //Giving counter-clockwise motion to back left wheel 523 | 524 | max = max(sfl, sfr); 525 | max = max(max, sbl); 526 | max = max(max, sbr); 527 | 528 | stop(); 529 | 530 | for (int i=0; i <= max; i = i+k) 531 | { 532 | if (i < sfl) 533 | { 534 | analogWrite(pwm1, i); 535 | } 536 | 537 | if (i < sfr) 538 | { 539 | analogWrite(pwm2, i); 540 | } 541 | 542 | if (i < sbl) 543 | { 544 | analogWrite(pwm3, i); 545 | } 546 | 547 | if (i < sbr) 548 | { 549 | analogWrite(pwm4, i); 550 | } 551 | delay(d); 552 | } 553 | ssfr = sfr; 554 | ssfl = sfl; 555 | ssbr = sbr; 556 | ssbl = sbl; 557 | } 558 | 559 | 560 | 561 | 562 | //Code for encoder 563 | 564 | int encoder::E1() 565 | { 566 | 567 | int MSB = digitalRead(encoderPin1); //MSB = most significant bit 568 | int LSB = digitalRead(encoderPin2); //LSB = least significant bit 569 | 570 | int encoded = (MSB << 1) |LSB; //converting the 2 pin value to single number 571 | int sum = (lastencoded << 2) | encoded; //adding it to the previous encoded value 572 | 573 | if(sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) { encoderValue ++; steps_taken++; } 574 | if (sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) { encoderValue ++; steps_taken++; } 575 | 576 | lastencoded = encoded; //store this value for next time 577 | Serial.println(steps_taken); 578 | } 579 | 580 | int encoder::step(int a) //a is angle in degree 581 | { 582 | Serial.print("direction3"); 583 | float radian_angle; 584 | radian_angle = a * (3.14/180); 585 | s = (R * radian_angle); // s is distance to be traveled 586 | steps = s / (31.42/PPR); // 0.320=(31.42 cm / ppr) 587 | return steps; 588 | } 589 | 590 | 591 | void DCMotor::rotate(unsigned char direction, uint8_t angle) //To rotate with direction and angle 592 | { 593 | //Serial.print("direction"); 594 | steps_taken = 0; 595 | int required_steps = step(angle); 596 | 597 | switch(direction) //Direction must be in 'L' or 'R' 598 | { 599 | case 'L': 600 | while (steps_taken < required_steps) 601 | { 602 | left_rotation(100,100,100,100); //calling left rotation function 603 | E1(); 604 | } 605 | stop(); //calling stop function 606 | break; 607 | 608 | case 'R': 609 | while (steps_taken < required_steps) 610 | { 611 | right_rotation(10,10,10,10); //calling right rotation function 612 | E1(); 613 | } 614 | stop(); //calling stop function 615 | break; 616 | 617 | default: 618 | stop(); 619 | break; 620 | } 621 | } 622 | 623 | 624 | 625 | void DCMotor::rotate1(unsigned char direction, uint16_t steps) //To rotate with direction and steps 626 | { 627 | //Serial.print("direction"); 628 | steps_taken = 0; 629 | 630 | 631 | switch(direction) //Direction must be in 'L' or 'R' 632 | { 633 | case 'L': 634 | left_rotation(20,20,20,20); 635 | while (steps_taken < steps) 636 | { 637 | //calling left rotation function 638 | E1(); 639 | } 640 | stop1(); //calling stop function 641 | break; 642 | 643 | case 'R': 644 | right_rotation(20,20,20,20); 645 | while (steps_taken < steps) 646 | { 647 | //calling right rotation function 648 | E1(); 649 | } 650 | stop1(); //calling stop function 651 | break; 652 | 653 | default: 654 | stop1(); 655 | break; 656 | } 657 | } 658 | -------------------------------------------------------------------------------- /JoystickControl/DCmotor.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "DCMotor.h" 3 | #define R 36.25 4 | #define encoderPin1 51 5 | #define encoderPin2 52 6 | 7 | 8 | 9 | //Variables for motor 10 | 11 | extern uint8_t pwm1; 12 | extern uint8_t pwm2; 13 | extern uint8_t pwm3; 14 | extern uint8_t pwm4; 15 | 16 | extern uint8_t dir1; 17 | extern uint8_t dir2; 18 | extern uint8_t dir3; 19 | extern uint8_t dir4; 20 | extern uint16_t PPR; 21 | uint8_t flag = 0 ; 22 | 23 | //Variables for motor 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | //Code for motor 36 | 37 | void DCMotor::stopp() //function used to stop motor 38 | { 39 | int i; 40 | flag = 0; 41 | if (max == 0){ 42 | for (i = max; i >= 0; (i = (i-d))) 43 | { 44 | if (ssfl > 0) 45 | { 46 | analogWrite(pwm1, i); 47 | } 48 | 49 | if (ssfr > 0) 50 | { 51 | analogWrite(pwm4, i); 52 | } 53 | 54 | if (ssbl > 0) 55 | { 56 | analogWrite(pwm3, i); 57 | } 58 | 59 | if (ssbr > 0) 60 | { 61 | analogWrite(pwm2, i); 62 | } 63 | delay(ds); 64 | } 65 | } 66 | 67 | analogWrite(pwm1, 0); 68 | analogWrite(pwm2, 0); 69 | analogWrite(pwm3, 0); 70 | analogWrite(pwm4, 0); 71 | max = 0; 72 | } 73 | 74 | void DCMotor::motorinit() //Setting motor pins as output 75 | { 76 | pinMode(encoderPin1,INPUT); 77 | pinMode(encoderPin2,INPUT); 78 | 79 | pinMode(dir1,OUTPUT); 80 | pinMode(dir2,OUTPUT); 81 | Serial.println("Front motor set as output"); 82 | 83 | pinMode(dir3,OUTPUT); 84 | pinMode(dir4,OUTPUT); 85 | Serial.println("Back motor set as output"); 86 | 87 | pinMode(pwm1,OUTPUT); 88 | pinMode(pwm2,OUTPUT); 89 | pinMode(pwm3,OUTPUT); 90 | pinMode(pwm4,OUTPUT); 91 | Serial.println("Enable pins set as output"); 92 | } 93 | 94 | void DCMotor::dcforward(uint8_t sfl,uint8_t sfr,uint8_t sbl,uint8_t sbr) //Giving forward motion 95 | { 96 | max = max(sfl, sfr); 97 | max = max(max, sbl); 98 | max = max(max, sbr); 99 | 100 | frontlt_CW(); //Giving clockwise motion to front left wheel 101 | frontrt_CCW(); //Giving counter-clockwise motion to front right wheel 102 | backlt_CCW(); //Giving counter-clockwise motion to back left wheel 103 | backrt_CW(); //Giving clockwise motion to back rightt wheel 104 | 105 | if (flag == 0) 106 | { 107 | for(uint8_t i=1;i 0) && (sensorB > 0)) 95 | { 96 | assignSensor(); 97 | mymotor.dcright(70,70,70,70); 98 | } 99 | 100 | 101 | 102 | mymotor.dcright(70,70,70,70); 103 | assignSensor(); 104 | while(sensorR > 0 || sensorR < 192) 105 | { 106 | mymotor.dcright(100,100,100,100); 107 | assignSensor(); 108 | if(sensorR > 0 && sensorR < 8) 109 | {mymotor.left_rotation(80,80,80,80); 110 | 111 | 112 | assignSensor();} 113 | else if(sensorR > 64 && sensorR < 192) 114 | {mymotor.right_rotation(80,80,80,80); 115 | 116 | assignSensor();} 117 | 118 | else if(sensorF >=4 && sensorB > 0 ) 119 | { 120 | assignSensor(); 121 | // Serial1.println("Stopped beacuse of : front and right"); 122 | mymotor.stop1(); 123 | break;} 124 | 125 | 126 | // else {mymotor.stop1();} 127 | 128 | } 129 | 130 | mymotor.stop1(); 131 | 132 | } 133 | numatics(); 134 | 135 | } 136 | 137 | 138 | 139 | 140 | 141 | void linesensorTest() 142 | { 143 | mymotor.dcforward(100,100,100,100); 144 | assignSensor(); 145 | 146 | while(sensorF < 128) { assignSensor();} 147 | mymotor.dcforward(60,60,60,60); 148 | 149 | while(sensorR < 1) 150 | { assignSensor(); } 151 | mymotor.stop1(); 152 | 153 | mymotor.dcright(100,100,100,100); 154 | assignSensor(); 155 | while(sensorR > 0 || sensorR < 192) 156 | { 157 | mymotor.dcright(120,120,120,120); 158 | assignSensor(); 159 | if(sensorR > 0 && sensorR < 8) 160 | {mymotor.left_rotation(80,80,80,80); 161 | 162 | 163 | assignSensor();} 164 | else if(sensorR > 64 && sensorR < 192) 165 | {mymotor.right_rotation(80,80,80,80); 166 | 167 | assignSensor();} 168 | 169 | else if(sensorF >=4 && sensorB > 0 ) 170 | { 171 | assignSensor(); 172 | // Serial1.println("Stopped beacuse of : front and right"); 173 | mymotor.stop1(); 174 | break;} 175 | 176 | 177 | // else {mymotor.stop1();} 178 | 179 | } 180 | 181 | mymotor.stop1(); 182 | 183 | 184 | 185 | assignSensor(); 186 | while(sensorB != 0) 187 | { assignSensor(); 188 | mymotor.left_rotation(90,90,90,90); } 189 | while(sensorB == 0 ) 190 | { 191 | assignSensor(); 192 | mymotor.left_rotation(90,90,90,90); 193 | } 194 | 195 | while((sensorB > 0) && (sensorB < 16) ) 196 | {assignSensor(); mymotor.left_rotation(70,70,70,70); } 197 | 198 | mymotor.stop1(); 199 | 200 | // delay(2000); 201 | 202 | gripper(); 203 | // gripper(); 204 | } //rotate and repeat process or TZ2 205 | 206 | 207 | /* while((sensorR > 0) || (sensorR <= 192)) 208 | { 209 | assignSensor(); 210 | if(sensorR < 8 && sensorR > 0 ) 211 | { 212 | mymotor.left_rotation(60,60,60,60); 213 | assignSensor(); 214 | while(sensorR < 8){assignSensor();}; 215 | mymotor.dcright(60,60,60,60); 216 | if((sensorR > 8 || sensorR < 26) ) 217 | { 218 | mymotor.dcright(120,120,120,120); 219 | } 220 | } 221 | 222 | else if(sensorR > 64 && sensorR < 192 ) 223 | { 224 | mymotor.right_rotation(60,60,60,60); 225 | assignSensor(); 226 | 227 | while(sensorR > 64){assignSensor();}; 228 | mymotor.dcright(60,60,60,60); 229 | if((sensorR > 7 || sensorR < 26 )) 230 | { 231 | mymotor.dcright(120,120,120,120); 232 | } 233 | } 234 | 235 | 236 | 237 | 238 | else if((sensorF>=4 && sensorL >=4) ||( sensorB >= 4 && sensorL >=4)) 239 | {assignSensor(); 240 | Serial1.println("Stopped beacuse of : front and right"); 241 | mymotor.stop1(); 242 | break; 243 | 244 | 245 | 246 | // else {mymotor.dcright(120,120,120,120); 247 | } 248 | }*/ 249 | 250 | 251 | 252 | 253 | 254 | //char data = 0; 255 | void setup() { 256 | 257 | mymotor.motorinit(); 258 | // Motions.init(); 259 | Serial1.begin(115200); 260 | Serial.begin(115200); 261 | 262 | 263 | pinMode(dir1,OUTPUT); 264 | pinMode(dir2,OUTPUT); 265 | Serial.println("Front motor set as output"); 266 | 267 | pinMode(dir3,OUTPUT); 268 | pinMode(dir4,OUTPUT); 269 | Serial.println("Back motor set as output"); 270 | 271 | pinMode(pwm1,OUTPUT); 272 | pinMode(pwm2,OUTPUT); 273 | pinMode(pwm3,OUTPUT); 274 | pinMode(pwm4,OUTPUT); 275 | 276 | /*delay(2000); 277 | Serial1.println("Ready"); 278 | delay(2000); 279 | Serial.println("Ready");*/ 280 | 281 | linesensorTest(); 282 | 283 | 284 | 285 | 286 | /*Serial.begin(115200); 287 | pinMode(5,OUTPUT); 288 | digitalWrite(5,LOW); //new Encodder test program 289 | pinMode(2,INPUT); 290 | pinMode(3,INPUT); 291 | 292 | digitalWrite(2, HIGH); //turn pullup resistor on 293 | digitalWrite(3, HIGH); //turn pullup resistor on 294 | 295 | attachInterrupt(digitalPinToInterrupt(2),encoder, LOW); */ 296 | 297 | } 298 | 299 | /*void encoder() 300 | { 301 | updateEncoder(); //new Encodder test program 302 | }*/ 303 | 304 | void loop() 305 | { 306 | // e.E1(); 307 | 308 | assignSensor(); 309 | 310 | /*Serial.print("Front read = "); 311 | Serial.println(LineF.readsensor());*/ 312 | 313 | 314 | /*Serial1.print("Back read = "); 315 | Serial1.println(LineB.readsensor());*/ 316 | 317 | 318 | /*Serial1.print("Right read = "); 319 | Serial1.println(LineR.readsensor())*/ 320 | 321 | 322 | /*Serial1.print("Left read = "); 323 | Serial1.println(LineL.readsensor()); 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | char data = 0; 333 | if(Serial.available() > 0) // Send data only when you receive data: 334 | { 335 | data = Serial.read(); //Read the incoming data & store into data 336 | Serial1.println(data); //Print Value inside data in Serial monitor 337 | Serial.println(data); 338 | switch(data) 339 | { 340 | case '1':mymotor.dcforward(80,80,80,80); 341 | Serial1.println("Moving Forward"); 342 | Serial.println("Moving Forward"); 343 | break; 344 | case '2': mymotor.dcreverse(80,80,80,80); 345 | Serial1.println("Moving Reverse"); 346 | Serial.println("Moving Reverse"); 347 | break; 348 | case '3': mymotor.right_rotation(120,120,120,120); 349 | Serial1.println("right rotation"); 350 | Serial.println("right rotation"); 351 | break; 352 | case '4': mymotor.left_rotation(80,80,80,80); 353 | Serial1.println("left Rotation"); 354 | Serial.println("left Rotation"); 355 | break; 356 | case '5': mymotor.dcleft(80,80,80,80); 357 | Serial1.println("Moving left"); 358 | Serial.println("Moving left"); 359 | break; 360 | case '6': mymotor.dcright(80,80,80,80); 361 | Serial1.println(" Moving Right"); 362 | Serial.println(" Moving Right"); 363 | break; 364 | case '7': mymotor.diagonal_flt(80,80,80,80); 365 | Serial1.println(" Moving Diagonal front left"); 366 | Serial.println(" Moving Diagonal front left"); 367 | break; 368 | case '8': mymotor.diagonal_frt(80,80,80,80); 369 | Serial1.println(" Moving diagonal front right"); 370 | Serial.println(" Moving diagonal front right"); 371 | break; 372 | case '9': mymotor.diagonal_blt(80,80,80,80); 373 | Serial1.println(" Moving diagonal bacl left"); 374 | Serial.println(" Moving diagonal bacl left"); 375 | break; 376 | case 'a': mymotor.diagonal_brt(80,80,80,80); 377 | Serial1.println(" Moving diagonal back right"); 378 | Serial.println(" Moving diagonal back right"); 379 | break; 380 | case 'b': mymotor.stop(); 381 | Serial1.println("STOP"); 382 | Serial.println("STOP"); 383 | break; 384 | 385 | } 386 | 387 | 388 | 389 | delay(1500); 390 | mymotor.stop(); 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | //Motions.joy(); 402 | /*if(Serial.available() > 0) 403 | { 404 | x=Serial.parseInt(); 405 | Serial.println(x); 406 | 407 | Serial.print("inside"); 408 | mymotor.rotate1('L',x); 409 | }*/ 410 | // Serial.println(e.E1()); 411 | 412 | 413 | /* Serial.print("count = "); 414 | Serial.println(count); 415 | if (Serial.available()) 416 | { 417 | char a = Serial.read(); 418 | switch(a) 419 | { //new Encodder test program 420 | case 'a': 421 | speed+=5; 422 | analogWrite(4,speed); 423 | Serial.println(speed); 424 | break; 425 | 426 | case 's': 427 | speed-=5; 428 | analogWrite(4,speed); 429 | Serial.println(speed); 430 | break; 431 | 432 | case 'z': 433 | count = 0; 434 | break; 435 | 436 | case 't': 437 | //analogWrite(4,0); 438 | flag = 0; 439 | digitalWrite(5,LOW); 440 | break; 441 | 442 | case 'g': 443 | //analogWrite(4,0); 444 | flag = 1; 445 | digitalWrite(5,HIGH); 446 | break; 447 | } 448 | } 449 | 450 | delay(100);*/ 451 | } 452 | 453 | 454 | 455 | 456 | 457 | -------------------------------------------------------------------------------- /Final1.2/Test_Program/Test_Program.ino: -------------------------------------------------------------------------------- 1 | ///////final 2 | 3 | 4 | #include "def.h" 5 | //#include "DCmotor.h" 6 | //#include "Servo.h" //ashish 7 | //Servo myservo 8 | uint16_t x; 9 | uint16_t y; 10 | 11 | 12 | uint8_t sensorF; 13 | uint8_t sensorB; 14 | uint8_t sensorR; 15 | uint8_t sensorL; 16 | char received; 17 | 18 | 19 | void assignSensor() 20 | { 21 | sensorF = LineF.readsensor(); 22 | // Serial1.print("Front read ="); 23 | // Serial1.println(sensorF); 24 | 25 | sensorB = LineB.readsensor(); 26 | // Serial1.print("Back read ="); 27 | // Serial1.println( sensorB); 28 | 29 | sensorR = LineR.readsensor(); 30 | // Serial1.print("Right read ="); 31 | // Serial1.println(sensorR); 32 | 33 | sensorL = LineL.readsensor(); 34 | // Serial1.print("Left read ="); 35 | // Serial1.println(sensorL); 36 | 37 | //delay(2000); 38 | } 39 | 40 | 41 | 42 | //encoder e; 43 | 44 | void numatics() 45 | { 46 | uint8_t in = 0; 47 | Serial2.println('b'); 48 | 49 | // while(Serial2.available() == 0); 50 | digitalWrite(A2,HIGH); 51 | digitalWrite(A3,LOW); 52 | in =((digitalWrite(A0)<<0) || (digitalWrite(A1)<<1) ) 53 | 54 | received = Serial2.read(); 55 | 56 | if(received == 'b' ){ 57 | 58 | 59 | 60 | Serial2.print('c'); 61 | Serial2.print(received); 62 | 63 | 64 | 65 | 66 | assignSensor(); 67 | while(sensorR > 0 && sensorL > 0) 68 | {mymotor.dcleft(80,80,80,80); 69 | assignSensor(); 70 | } 71 | 72 | while(sensorL > 0 || sensorL < 192) // reverse motion 73 | { 74 | mymotor.dcleft(70,70,70,70); 75 | 76 | assignSensor(); 77 | if(sensorL > 0 && sensorL < 8) 78 | { 79 | mymotor.left_rotation(75,75,75,75); 80 | assignSensor();} 81 | else if(sensorL > 64 && sensorL < 192) 82 | { mymotor.right_rotation(75,75,75,75); 83 | assignSensor(); 84 | } 85 | else if(sensorF >= 4 && sensorB > 0 ) 86 | { 87 | assignSensor(); 88 | // Serial1.println("Stopped beacuse of : front and right"); 89 | mymotor.stop1(); 90 | break; 91 | } 92 | } 93 | mymotor.stop1(); 94 | } } 95 | 96 | 97 | void gripper() 98 | {uint8_t in = 0; 99 | Serial2.println('a'); 100 | digitalWrite(A2,HIGH); 101 | digitalWrite(A3,LOW); 102 | in =((digitalWrite(A0)<<0) || (digitalWrite(A1)<<1) ) 103 | 104 | //received = Serial2.read(); 105 | if(received == 0x01){ 106 | delay(500); 107 | 108 | while((sensorF > 0) && (sensorB > 0)) 109 | { 110 | assignSensor(); 111 | mymotor.dcright(70,70,70,70); 112 | } 113 | 114 | 115 | 116 | mymotor.dcright(70,70,70,70); 117 | assignSensor(); 118 | while(sensorR > 0 || sensorR < 192) 119 | { 120 | mymotor.dcright(100,100,100,100); 121 | assignSensor(); 122 | if(sensorR > 0 && sensorR < 8) 123 | {mymotor.left_rotation(80,80,80,80); 124 | 125 | 126 | assignSensor();} 127 | else if(sensorR > 64 && sensorR < 192) 128 | {mymotor.right_rotation(80,80,80,80); 129 | 130 | assignSensor();} 131 | 132 | else if(sensorF >=4 && sensorB > 0 ) 133 | { 134 | assignSensor(); 135 | // Serial1.println("Stopped beacuse of : front and right"); 136 | mymotor.stop1(); 137 | break;} 138 | 139 | 140 | // else {mymotor.stop1();} 141 | 142 | } 143 | 144 | mymotor.stop1(); 145 | 146 | } 147 | numatics(); 148 | 149 | } 150 | 151 | 152 | 153 | 154 | 155 | void linesensorTest() 156 | { 157 | mymotor.dcforward(100,100,100,100); 158 | assignSensor(); 159 | 160 | while(sensorF < 128) { assignSensor();} 161 | mymotor.dcforward(60,60,60,60); 162 | 163 | while(sensorR < 1) 164 | { assignSensor(); } 165 | mymotor.stop1(); 166 | 167 | mymotor.dcright(100,100,100,100); 168 | assignSensor(); 169 | while(sensorR > 0 || sensorR < 192) 170 | { 171 | mymotor.dcright(120,120,120,120); 172 | assignSensor(); 173 | if(sensorR > 0 && sensorR < 8) 174 | {mymotor.left_rotation(80,80,80,80); 175 | 176 | 177 | assignSensor();} 178 | else if(sensorR > 64 && sensorR < 192) 179 | {mymotor.right_rotation(80,80,80,80); 180 | 181 | assignSensor();} 182 | 183 | else if(sensorF >=4 && sensorB > 0 ) 184 | { 185 | assignSensor(); 186 | // Serial1.println("Stopped beacuse of : front and right"); 187 | mymotor.stop1(); 188 | break;} 189 | 190 | 191 | // else {mymotor.stop1();} 192 | 193 | } 194 | 195 | mymotor.stop1(); 196 | 197 | 198 | 199 | assignSensor(); 200 | while(sensorB != 0) 201 | { assignSensor(); 202 | mymotor.left_rotation(90,90,90,90); } 203 | while(sensorB == 0 ) 204 | { 205 | assignSensor(); 206 | mymotor.left_rotation(90,90,90,90); 207 | } 208 | 209 | while((sensorB > 0) && (sensorB < 16) ) 210 | {assignSensor(); mymotor.left_rotation(70,70,70,70); } 211 | 212 | mymotor.stop1(); 213 | 214 | // delay(2000); 215 | 216 | gripper(); 217 | gripper(); 218 | } //rotate and repeat process or TZ2 219 | 220 | 221 | /* while((sensorR > 0) || (sensorR <= 192)) 222 | { 223 | assignSensor(); 224 | if(sensorR < 8 && sensorR > 0 ) 225 | { 226 | mymotor.left_rotation(60,60,60,60); 227 | assignSensor(); 228 | while(sensorR < 8){assignSensor();}; 229 | mymotor.dcright(60,60,60,60); 230 | if((sensorR > 8 || sensorR < 26) ) 231 | { 232 | mymotor.dcright(120,120,120,120); 233 | } 234 | } 235 | 236 | else if(sensorR > 64 && sensorR < 192 ) 237 | { 238 | mymotor.right_rotation(60,60,60,60); 239 | assignSensor(); 240 | 241 | while(sensorR > 64){assignSensor();}; 242 | mymotor.dcright(60,60,60,60); 243 | if((sensorR > 7 || sensorR < 26 )) 244 | { 245 | mymotor.dcright(120,120,120,120); 246 | } 247 | } 248 | 249 | 250 | 251 | 252 | else if((sensorF>=4 && sensorL >=4) ||( sensorB >= 4 && sensorL >=4)) 253 | {assignSensor(); 254 | Serial1.println("Stopped beacuse of : front and right"); 255 | mymotor.stop1(); 256 | break; 257 | 258 | 259 | 260 | // else {mymotor.dcright(120,120,120,120); 261 | } 262 | }*/ 263 | 264 | 265 | 266 | 267 | 268 | //char data = 0; 269 | void setup() { 270 | 271 | mymotor.motorinit(); 272 | // Motions.init(); 273 | Serial1.begin(115200); 274 | Serial.begin(115200); 275 | 276 | 277 | pinMode(dir1,OUTPUT); 278 | pinMode(dir2,OUTPUT); 279 | Serial.println("Front motor set as output"); 280 | 281 | pinMode(dir3,OUTPUT); 282 | pinMode(dir4,OUTPUT); 283 | Serial.println("Back motor set as output"); 284 | 285 | pinMode(pwm1,OUTPUT); 286 | pinMode(pwm2,OUTPUT); 287 | pinMode(pwm3,OUTPUT); 288 | pinMode(pwm4,OUTPUT); 289 | pinMode(A0,INPUT); 290 | pinMode(A1,INPUT); 291 | pinMode(A2,OUTPUT); 292 | pinMode(A3,OUTPUT); 293 | /*delay(2000); 294 | Serial1.println("Ready"); 295 | delay(2000); 296 | Serial.println("Ready");*/ 297 | 298 | linesensorTest(); 299 | 300 | 301 | 302 | 303 | /*Serial.begin(115200); 304 | pinMode(5,OUTPUT); 305 | digitalWrite(5,LOW); //new Encodder test program 306 | pinMode(2,INPUT); 307 | pinMode(3,INPUT); 308 | 309 | digitalWrite(2, HIGH); //turn pullup resistor on 310 | digitalWrite(3, HIGH); //turn pullup resistor on 311 | 312 | attachInterrupt(digitalPinToInterrupt(2),encoder, LOW); */ 313 | 314 | } 315 | 316 | /*void encoder() 317 | { 318 | updateEncoder(); //new Encodder test program 319 | }*/ 320 | 321 | void loop() 322 | { 323 | // e.E1(); 324 | 325 | assignSensor(); 326 | 327 | /*Serial.print("Front read = "); 328 | Serial.println(LineF.readsensor());*/ 329 | 330 | 331 | /*Serial1.print("Back read = "); 332 | Serial1.println(LineB.readsensor());*/ 333 | 334 | 335 | /*Serial1.print("Right read = "); 336 | Serial1.println(LineR.readsensor())*/ 337 | 338 | 339 | /*Serial1.print("Left read = "); 340 | Serial1.println(LineL.readsensor()); 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | char data = 0; 350 | if(Serial.available() > 0) // Send data only when you receive data: 351 | { 352 | data = Serial.read(); //Read the incoming data & store into data 353 | Serial1.println(data); //Print Value inside data in Serial monitor 354 | Serial.println(data); 355 | switch(data) 356 | { 357 | case '1':mymotor.dcforward(80,80,80,80); 358 | Serial1.println("Moving Forward"); 359 | Serial.println("Moving Forward"); 360 | break; 361 | case '2': mymotor.dcreverse(80,80,80,80); 362 | Serial1.println("Moving Reverse"); 363 | Serial.println("Moving Reverse"); 364 | break; 365 | case '3': mymotor.right_rotation(120,120,120,120); 366 | Serial1.println("right rotation"); 367 | Serial.println("right rotation"); 368 | break; 369 | case '4': mymotor.left_rotation(80,80,80,80); 370 | Serial1.println("left Rotation"); 371 | Serial.println("left Rotation"); 372 | break; 373 | case '5': mymotor.dcleft(80,80,80,80); 374 | Serial1.println("Moving left"); 375 | Serial.println("Moving left"); 376 | break; 377 | case '6': mymotor.dcright(80,80,80,80); 378 | Serial1.println(" Moving Right"); 379 | Serial.println(" Moving Right"); 380 | break; 381 | case '7': mymotor.diagonal_flt(80,80,80,80); 382 | Serial1.println(" Moving Diagonal front left"); 383 | Serial.println(" Moving Diagonal front left"); 384 | break; 385 | case '8': mymotor.diagonal_frt(80,80,80,80); 386 | Serial1.println(" Moving diagonal front right"); 387 | Serial.println(" Moving diagonal front right"); 388 | break; 389 | case '9': mymotor.diagonal_blt(80,80,80,80); 390 | Serial1.println(" Moving diagonal bacl left"); 391 | Serial.println(" Moving diagonal bacl left"); 392 | break; 393 | case 'a': mymotor.diagonal_brt(80,80,80,80); 394 | Serial1.println(" Moving diagonal back right"); 395 | Serial.println(" Moving diagonal back right"); 396 | break; 397 | case 'b': mymotor.stop(); 398 | Serial1.println("STOP"); 399 | Serial.println("STOP"); 400 | break; 401 | 402 | } 403 | 404 | 405 | 406 | delay(1500); 407 | mymotor.stop(); 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | //Motions.joy(); 419 | /*if(Serial.available() > 0) 420 | { 421 | x=Serial.parseInt(); 422 | Serial.println(x); 423 | 424 | Serial.print("inside"); 425 | mymotor.rotate1('L',x); 426 | }*/ 427 | // Serial.println(e.E1()); 428 | 429 | 430 | /* Serial.print("count = "); 431 | Serial.println(count); 432 | if (Serial.available()) 433 | { 434 | char a = Serial.read(); 435 | switch(a) 436 | { //new Encodder test program 437 | case 'a': 438 | speed+=5; 439 | analogWrite(4,speed); 440 | Serial.println(speed); 441 | break; 442 | 443 | case 's': 444 | speed-=5; 445 | analogWrite(4,speed); 446 | Serial.println(speed); 447 | break; 448 | 449 | case 'z': 450 | count = 0; 451 | break; 452 | 453 | case 't': 454 | //analogWrite(4,0); 455 | flag = 0; 456 | digitalWrite(5,LOW); 457 | break; 458 | 459 | case 'g': 460 | //analogWrite(4,0); 461 | flag = 1; 462 | digitalWrite(5,HIGH); 463 | break; 464 | } 465 | } 466 | 467 | delay(100);*/ 468 | } 469 | 470 | 471 | 472 | 473 | 474 | --------------------------------------------------------------------------------