Werkend motorscript met led feedback

Dependencies:   Encoder MODSERIAL mbed HIDScope

Fork of frdm_Motortryout2 by Robert Schulte

Committer:
Margreeth95
Date:
Mon Sep 21 12:47:49 2015 +0000
Revision:
8:44d4f2eb6a81
Parent:
7:7fce8b4db9d8
uploading error

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rvs94 0:c8684fed9b61 1 #include "mbed.h"
Rvs94 0:c8684fed9b61 2 #include "encoder.h"
Rvs94 0:c8684fed9b61 3 #include "MODSERIAL.h"
Margreeth95 6:866d461c7be8 4 #include "HIDScope.h"
Rvs94 0:c8684fed9b61 5
Rvs94 0:c8684fed9b61 6 Serial pc(USBTX, USBRX); // tx, rx
Rvs94 3:051c91b04acd 7 DigitalOut led(LED_RED);
Rvs94 0:c8684fed9b61 8 DigitalOut motor2direction(D4); //D4 en D5 zijn motor 2 (op het motorshield)
Rvs94 0:c8684fed9b61 9 PwmOut motor2speed(D5);
Rvs94 0:c8684fed9b61 10 DigitalIn button1(SW3);
Margreeth95 6:866d461c7be8 11 HIDScope scope(1);
Margreeth95 7:7fce8b4db9d8 12 Ticker ScopeTime;
Margreeth95 6:866d461c7be8 13
Margreeth95 7:7fce8b4db9d8 14 void ScopeSend()//Functie die de gegevens voor de scope uitleest en doorstuurt
Margreeth95 6:866d461c7be8 15 {
Margreeth95 6:866d461c7be8 16 scope.set(0, motor2direction.read());
Margreeth95 6:866d461c7be8 17 scope.send();
Margreeth95 6:866d461c7be8 18 }
Rvs94 0:c8684fed9b61 19
Rvs94 0:c8684fed9b61 20 int main()
Rvs94 0:c8684fed9b61 21 {
Rvs94 3:051c91b04acd 22 motor2direction = 0;
Rvs94 0:c8684fed9b61 23 motor2speed = 0;
Rvs94 3:051c91b04acd 24 led = 1;
Rvs94 0:c8684fed9b61 25 pc.baud(9600);
Margreeth95 8:44d4f2eb6a81 26 pc.printf("Tot aan loop werkt");
Margreeth95 8:44d4f2eb6a81 27 ScopeTime.attach_us(&ScopeSend, 10e4);
Margreeth95 8:44d4f2eb6a81 28
Margreeth95 7:7fce8b4db9d8 29
Rvs94 0:c8684fed9b61 30 while(true)
Rvs94 0:c8684fed9b61 31 {
Margreeth95 4:69c6cc1247c1 32 char c = pc.getc();
Margreeth95 7:7fce8b4db9d8 33
Margreeth95 4:69c6cc1247c1 34 switch(c)
Margreeth95 4:69c6cc1247c1 35 {
Margreeth95 4:69c6cc1247c1 36 case 'f':
Rvs94 0:c8684fed9b61 37 {
Rvs94 3:051c91b04acd 38 motor2direction = 1;
Rvs94 0:c8684fed9b61 39 motor2speed = 0.5f;
Margreeth95 4:69c6cc1247c1 40 pc.printf("het werkt\n");
Rvs94 1:4e65a72b622e 41 wait(1);
Rvs94 3:051c91b04acd 42 led = 0;
Rvs94 1:4e65a72b622e 43 wait(0.2f);
Rvs94 1:4e65a72b622e 44 motor2speed = 0;
Rvs94 3:051c91b04acd 45 led = 1;
Margreeth95 4:69c6cc1247c1 46 break;
Rvs94 0:c8684fed9b61 47 }
Margreeth95 4:69c6cc1247c1 48
Margreeth95 4:69c6cc1247c1 49 case 'r':
Margreeth95 4:69c6cc1247c1 50 {
Margreeth95 5:672798238952 51 motor2direction = 0;
Margreeth95 4:69c6cc1247c1 52 motor2speed = 0.5f;
Margreeth95 4:69c6cc1247c1 53 pc.printf("dit werkt ook\n");
Margreeth95 4:69c6cc1247c1 54 wait(1);
Margreeth95 4:69c6cc1247c1 55 led = 0;
Margreeth95 4:69c6cc1247c1 56 wait(0.2f);
Margreeth95 4:69c6cc1247c1 57 motor2speed = 0;
Margreeth95 4:69c6cc1247c1 58 led = 1;
Margreeth95 4:69c6cc1247c1 59 break;
Margreeth95 4:69c6cc1247c1 60 }
Margreeth95 4:69c6cc1247c1 61 }
Rvs94 0:c8684fed9b61 62 }
Rvs94 0:c8684fed9b61 63 }