Unko buriburi

Dependencies:   mbed PS_PAD

Committer:
koga641028
Date:
Sat Sep 05 09:16:52 2020 +0000
Revision:
1:aec7284f51de
Parent:
0:dfd7b420339f
Child:
2:61693469fd81
Fight

Who changed what in which revision?

UserRevisionLine numberNew contents of line
koga641028 0:dfd7b420339f 1 /*
koga641028 0:dfd7b420339f 2 * ======================
koga641028 0:dfd7b420339f 3 * VS-C3/VS-RCV3 PIN
koga641028 0:dfd7b420339f 4 * ======================
koga641028 0:dfd7b420339f 5 * 1:NC 2:NC
koga641028 0:dfd7b420339f 6 * 3:DAT 4:CMD
koga641028 0:dfd7b420339f 7 * 5:SEL 6:CLK
koga641028 0:dfd7b420339f 8 * 7:+5~7V 8:NC
koga641028 0:dfd7b420339f 9 * 9:+3V 10:GND
koga641028 0:dfd7b420339f 10 *
koga641028 0:dfd7b420339f 11 */
koga641028 0:dfd7b420339f 12
koga641028 0:dfd7b420339f 13 #include "mbed.h"
koga641028 0:dfd7b420339f 14 #include "PS_PAD.h"
koga641028 0:dfd7b420339f 15
koga641028 0:dfd7b420339f 16 class Motor{
koga641028 0:dfd7b420339f 17 PwmOut a, b;
koga641028 0:dfd7b420339f 18 public:
koga641028 0:dfd7b420339f 19 Motor(PinName A_term, PinName B_term) : a(A_term), b(B_term) {
koga641028 0:dfd7b420339f 20 a.period(0.001);
koga641028 0:dfd7b420339f 21 b.period(0.001);
koga641028 0:dfd7b420339f 22 }
koga641028 0:dfd7b420339f 23
koga641028 0:dfd7b420339f 24 Motor& operator=(double duty) {
koga641028 0:dfd7b420339f 25 if(duty > 0){
koga641028 0:dfd7b420339f 26 a = duty < 1 ? duty : 1;
koga641028 0:dfd7b420339f 27 b = 0;
koga641028 0:dfd7b420339f 28 }else {
koga641028 0:dfd7b420339f 29 a = 0;
koga641028 1:aec7284f51de 30 b = duty > -1 ? -duty : 1;
koga641028 0:dfd7b420339f 31 }
koga641028 0:dfd7b420339f 32 return *this;
koga641028 0:dfd7b420339f 33 }
koga641028 1:aec7284f51de 34 operator double() {
koga641028 1:aec7284f51de 35 if(a > 0)
koga641028 1:aec7284f51de 36 return (double)a;
koga641028 1:aec7284f51de 37 else
koga641028 1:aec7284f51de 38 return -(double)b;
koga641028 1:aec7284f51de 39 }
koga641028 0:dfd7b420339f 40 };
koga641028 0:dfd7b420339f 41
koga641028 0:dfd7b420339f 42
koga641028 0:dfd7b420339f 43 PS_PAD vsc3(PA_7, PA_6, PA_5, PA_4); //MOSI, MISO, SCK, SS
koga641028 0:dfd7b420339f 44
koga641028 0:dfd7b420339f 45 DigitalIn lim[7] = {PD_2, PD_3, PD_4, PD_5, PD_6, PD_7, PG_9};
koga641028 0:dfd7b420339f 46 Motor rmotor(PE_9, PE_11);
koga641028 0:dfd7b420339f 47 Motor lmotor(PE_13, PE_14);
koga641028 0:dfd7b420339f 48 Motor sxmotor(PA_0, PA_1);
koga641028 0:dfd7b420339f 49 Motor tsmotor(PA_2, PA_3);
koga641028 0:dfd7b420339f 50 Motor trmotor(PC_6, PC_7);
koga641028 0:dfd7b420339f 51 Motor tlmotor(PC_8, PC_9);
koga641028 0:dfd7b420339f 52
koga641028 0:dfd7b420339f 53 int main() {
koga641028 0:dfd7b420339f 54 vsc3.init();
koga641028 1:aec7284f51de 55 double movery = 0, movely = 0 , speed = 1 ;
koga641028 0:dfd7b420339f 56 printf("START\n");
koga641028 0:dfd7b420339f 57
koga641028 0:dfd7b420339f 58 while(1) {
koga641028 0:dfd7b420339f 59 vsc3.poll();
koga641028 1:aec7284f51de 60
koga641028 1:aec7284f51de 61 if(abs(vsc3.read(PS_PAD::ANALOG_RY)) > 10){
koga641028 1:aec7284f51de 62 movery = (vsc3.read(PS_PAD::ANALOG_RY)) / 284.4 ;
koga641028 1:aec7284f51de 63 }else{
koga641028 1:aec7284f51de 64 movery = 0;
koga641028 1:aec7284f51de 65 }
koga641028 1:aec7284f51de 66 if(abs(vsc3.read(PS_PAD::ANALOG_LY)) > 10){
koga641028 1:aec7284f51de 67 movely = (vsc3.read(PS_PAD::ANALOG_LY)) / 284.4 ;
koga641028 0:dfd7b420339f 68 }else{
koga641028 1:aec7284f51de 69 movely = 0;
koga641028 1:aec7284f51de 70 }
koga641028 1:aec7284f51de 71 rmotor = movery; //move
koga641028 1:aec7284f51de 72 lmotor = movely;
koga641028 1:aec7284f51de 73
koga641028 1:aec7284f51de 74 /* paper makiage*/
koga641028 1:aec7284f51de 75
koga641028 1:aec7284f51de 76 if (vsc3.read(PS_PAD::PAD_SQUARE)/* && lim[2] == 0*/){
koga641028 1:aec7284f51de 77 sxmotor = speed;
koga641028 1:aec7284f51de 78 }else if (vsc3.read(PS_PAD::PAD_X) /*&& lim[3] == 0*/){
koga641028 1:aec7284f51de 79 sxmotor = -speed;
koga641028 1:aec7284f51de 80 }else{
koga641028 1:aec7284f51de 81 sxmotor = 0;
koga641028 1:aec7284f51de 82 }
koga641028 1:aec7284f51de 83
koga641028 1:aec7284f51de 84 /* fan right */
koga641028 1:aec7284f51de 85 if (vsc3.read(PS_PAD::PAD_L1) /*&& lim[4] == 0*/){
koga641028 1:aec7284f51de 86 tsmotor = speed;
koga641028 1:aec7284f51de 87 }else{
koga641028 1:aec7284f51de 88 tsmotor = 0;
koga641028 0:dfd7b420339f 89 }
koga641028 0:dfd7b420339f 90
koga641028 1:aec7284f51de 91 /* fan left */
koga641028 1:aec7284f51de 92 if (vsc3.read(PS_PAD::PAD_R1) /*&& lim[6] == 0*/){
koga641028 1:aec7284f51de 93 trmotor = speed;
koga641028 0:dfd7b420339f 94 }else{
koga641028 0:dfd7b420339f 95 trmotor = 0;
koga641028 0:dfd7b420339f 96 }
koga641028 1:aec7284f51de 97
koga641028 1:aec7284f51de 98 /*fan makiage double*/
koga641028 1:aec7284f51de 99 if (vsc3.read(PS_PAD::PAD_L1)&& vsc3.read(PS_PAD::PAD_R1)&& vsc3.read(PS_PAD::PAD_SQUARE)/*&& lim[4] == 0*/){
koga641028 1:aec7284f51de 100 tsmotor = 0.5;
koga641028 1:aec7284f51de 101 trmotor = 0.5;
koga641028 1:aec7284f51de 102 sxmotor = speed;
koga641028 1:aec7284f51de 103 }
koga641028 1:aec7284f51de 104 if (vsc3.read(PS_PAD::PAD_L1)&& vsc3.read(PS_PAD::PAD_R1)&& vsc3.read(PS_PAD::PAD_X)/*&& lim[4] == 0*/){
koga641028 1:aec7284f51de 105 tsmotor = 0.5;
koga641028 1:aec7284f51de 106 trmotor = 0.5;
koga641028 1:aec7284f51de 107 sxmotor = -speed;
koga641028 0:dfd7b420339f 108 }
koga641028 0:dfd7b420339f 109
koga641028 0:dfd7b420339f 110 wait(0.05);
koga641028 0:dfd7b420339f 111 }
koga641028 0:dfd7b420339f 112 }