Jona Vonk
/
MoveMotors
Hier zitten extra leipe functies in naast PID ook x en y naar hoeken
main.cpp
- Committer:
- samzijp
- Date:
- 2019-10-04
- Revision:
- 1:363c5230fe25
- Parent:
- 0:6986a58c4515
- Child:
- 2:f832050b1b4a
File content as of revision 1:363c5230fe25:
/* mbed Microcontroller Library * Copyright (c) 2018 ARM Limited * SPDX-License-Identifier: Apache-2.0 */ #include "mbed.h" #include "MODSERIAL.h" DigitalOut M1(D4); //Direction control DigitalOut M2(D7); //Direction control PwmOut E1(D5); //Speed control PwmOut E2(D6); //Speed control InterruptIn Btn1(A0); //Potentionmeter InterruptIn Btn2(A1); //Potentionmeter DigitalIn M1A(D2); //Encoder DigitalIn M1B(D3); //Encoder //float potVal1; //float potVal2; int EncA1; int EncB1; int counts = 0; int speedCount = 0; //Ticker readEnc MODSERIAL pc(USBTX, USBRX); void speedUp(){ speedCount++; } void speedDown(){ speedCount--; } // main() runs in its own thread in the OS int main(){ pc.baud(9600); Btn1.rise(&speedUp); Btn2.rise(&speedDown); while(true){ if(speedCount > 0){ M1 = 1; E1 = speedCount/10; } else{ M1 = 0; E1 = -speedCount/10; } /*potVal1 = Pot1.read(); potVal2 = Pot2.read(); if (potVal1 > 0.5){ M1 = 1; E1 = potVal1-0.5; }else{ M1 = 0; E1 = -(potVal1-0.5); } if (potVal2 > 0.5){ M2 = 1; E2 = potVal2-0.5; }else{ M2 = 0; E2 = -(potVal2-0.5); } pc.printf("Pot1: %f \t Pot2: %f \n\r", potVal1, potVal2);*/ } }