groep 16 / Mbed OS Motor_test_01

Dependencies:   MODSERIAL

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2018 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
00004  */
00005 
00006 #include "mbed.h"
00007 #include "MODSERIAL.h"
00008 
00009 
00010 DigitalOut M1(D4);  //Direction control
00011 DigitalOut M2(D7);  //Direction control
00012 PwmOut E1(D5);      //Speed control
00013 PwmOut E2(D6);      //Speed control
00014 InterruptIn Btn1(A0);  //Potentionmeter
00015 InterruptIn Btn2(A1);  //Potentionmeter
00016 DigitalIn M1A(D2);  //Encoder
00017 DigitalIn M1B(D3);  //Encoder
00018 
00019 //float potVal1;
00020 //float potVal2;
00021 int EncA1;
00022 int EncB1;
00023 int counts = 0;
00024 int speedCount = 0;
00025 
00026 //Ticker readEnc
00027 
00028 MODSERIAL pc(USBTX, USBRX);
00029 
00030 void speedUp(){
00031     speedCount++;
00032 }
00033 void speedDown(){
00034     speedCount--;
00035 }
00036 
00037 
00038 // main() runs in its own thread in the OS
00039 int main(){
00040     pc.baud(9600);
00041     Btn1.rise(&speedUp);
00042     Btn2.rise(&speedDown);
00043     while(true){
00044         if(speedCount > 0){
00045             M1 = 1;
00046             E1 = speedCount/10;
00047             }
00048         else{
00049             M1 = 0;
00050             E1 = -speedCount/10;
00051             }                
00052         /*potVal1 = Pot1.read();
00053         potVal2 = Pot2.read();
00054         if (potVal1 > 0.5){
00055             M1 = 1;
00056             E1 = potVal1-0.5;
00057         }else{
00058             M1 = 0;
00059             E1 = -(potVal1-0.5);
00060         }
00061         if (potVal2 > 0.5){
00062             M2 = 1;
00063             E2 = potVal2-0.5;
00064         }else{
00065             M2 = 0;
00066             E2 = -(potVal2-0.5);
00067         }
00068         pc.printf("Pot1: %f \t Pot2: %f \n\r", potVal1, potVal2);*/
00069     }
00070 }