Joystick Controlled Servos

Dependencies:   Servo Map

Committer:
Galib_Rahman
Date:
Thu Dec 13 02:26:26 2018 +0000
Revision:
1:6dc9dbf60e67
Parent:
0:7e748374bdff
Modified Analog.read()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Galib_Rahman 0:7e748374bdff 1 /*
Galib_Rahman 0:7e748374bdff 2
Galib_Rahman 0:7e748374bdff 3 Joystick Controlled Servo Motors
Galib_Rahman 0:7e748374bdff 4 Developed 12|12|18
Galib_Rahman 1:6dc9dbf60e67 5
Galib_Rahman 0:7e748374bdff 6
Galib_Rahman 0:7e748374bdff 7
Galib_Rahman 0:7e748374bdff 8 */
Galib_Rahman 0:7e748374bdff 9
Galib_Rahman 0:7e748374bdff 10 #include "mbed.h"
Galib_Rahman 0:7e748374bdff 11 #include "Servo.h"
Galib_Rahman 0:7e748374bdff 12 #include "Map.hpp"
Galib_Rahman 0:7e748374bdff 13
Galib_Rahman 0:7e748374bdff 14
Galib_Rahman 0:7e748374bdff 15 AnalogIn JoystickPin1(A0);
Galib_Rahman 0:7e748374bdff 16 AnalogIn JoystickPin2(A1);
Galib_Rahman 0:7e748374bdff 17
Galib_Rahman 0:7e748374bdff 18 Servo ServoMotor1(D3);
Galib_Rahman 1:6dc9dbf60e67 19 //Servo ServoMotor2(D4);
Galib_Rahman 0:7e748374bdff 20
Galib_Rahman 0:7e748374bdff 21 Map AnalogPos(0,1023,0,180);
Galib_Rahman 0:7e748374bdff 22
Galib_Rahman 0:7e748374bdff 23
Galib_Rahman 1:6dc9dbf60e67 24
Galib_Rahman 0:7e748374bdff 25 int main()
Galib_Rahman 0:7e748374bdff 26 {
Galib_Rahman 1:6dc9dbf60e67 27
Galib_Rahman 1:6dc9dbf60e67 28 float Position1,Position2;
Galib_Rahman 0:7e748374bdff 29
Galib_Rahman 0:7e748374bdff 30
Galib_Rahman 0:7e748374bdff 31 while (true) {
Galib_Rahman 0:7e748374bdff 32
Galib_Rahman 1:6dc9dbf60e67 33 Position1=AnalogPos.Calculate(JoystickPin1.read());
Galib_Rahman 1:6dc9dbf60e67 34 Position2=AnalogPos.Calculate(JoystickPin2.read());
Galib_Rahman 1:6dc9dbf60e67 35
Galib_Rahman 0:7e748374bdff 36
Galib_Rahman 0:7e748374bdff 37
Galib_Rahman 1:6dc9dbf60e67 38 ServoMotor1.position(Position1);
Galib_Rahman 1:6dc9dbf60e67 39 printf("JoyStick1");
Galib_Rahman 1:6dc9dbf60e67 40 printf("%f",Position1);
Galib_Rahman 1:6dc9dbf60e67 41
Galib_Rahman 1:6dc9dbf60e67 42 printf("JoyStick2");
Galib_Rahman 1:6dc9dbf60e67 43
Galib_Rahman 1:6dc9dbf60e67 44 printf("%f",Position2);
Galib_Rahman 1:6dc9dbf60e67 45
Galib_Rahman 1:6dc9dbf60e67 46
Galib_Rahman 1:6dc9dbf60e67 47 ServoMotor1.position(Position1);
Galib_Rahman 1:6dc9dbf60e67 48 }
Galib_Rahman 1:6dc9dbf60e67 49
Galib_Rahman 1:6dc9dbf60e67 50
Galib_Rahman 0:7e748374bdff 51
Galib_Rahman 0:7e748374bdff 52
Galib_Rahman 0:7e748374bdff 53
Galib_Rahman 0:7e748374bdff 54 }
Galib_Rahman 1:6dc9dbf60e67 55