Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed QEI MODSERIAL
main.cpp
- Committer:
- samzijp
- Date:
- 2019-10-14
- Revision:
- 2:93dcfd18ccb4
- Parent:
- 0:05da2ae2ad90
File content as of revision 2:93dcfd18ccb4:
/* 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);*/
}
}