Werkend motorscript met led feedback

Dependencies:   Encoder MODSERIAL mbed HIDScope

Fork of frdm_Motortryout2 by Robert Schulte

Committer:
Margreeth95
Date:
Mon Sep 21 12:17:11 2015 +0000
Revision:
7:7fce8b4db9d8
Parent:
6:866d461c7be8
Child:
8:44d4f2eb6a81
error in HIDscope, lamp gaat aan

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 7:7fce8b4db9d8 26
Rvs94 0:c8684fed9b61 27 while(true)
Rvs94 0:c8684fed9b61 28 {
Margreeth95 7:7fce8b4db9d8 29 ScopeTime.attach_us(&ScopeSend, 10e4);
Margreeth95 4:69c6cc1247c1 30 char c = pc.getc();
Margreeth95 7:7fce8b4db9d8 31
Margreeth95 4:69c6cc1247c1 32 switch(c)
Margreeth95 4:69c6cc1247c1 33 {
Margreeth95 4:69c6cc1247c1 34 case 'f':
Rvs94 0:c8684fed9b61 35 {
Rvs94 3:051c91b04acd 36 motor2direction = 1;
Rvs94 0:c8684fed9b61 37 motor2speed = 0.5f;
Margreeth95 4:69c6cc1247c1 38 pc.printf("het werkt\n");
Rvs94 1:4e65a72b622e 39 wait(1);
Rvs94 3:051c91b04acd 40 led = 0;
Rvs94 1:4e65a72b622e 41 wait(0.2f);
Rvs94 1:4e65a72b622e 42 motor2speed = 0;
Rvs94 3:051c91b04acd 43 led = 1;
Margreeth95 4:69c6cc1247c1 44 break;
Rvs94 0:c8684fed9b61 45 }
Margreeth95 4:69c6cc1247c1 46
Margreeth95 4:69c6cc1247c1 47 case 'r':
Margreeth95 4:69c6cc1247c1 48 {
Margreeth95 5:672798238952 49 motor2direction = 0;
Margreeth95 4:69c6cc1247c1 50 motor2speed = 0.5f;
Margreeth95 4:69c6cc1247c1 51 pc.printf("dit werkt ook\n");
Margreeth95 4:69c6cc1247c1 52 wait(1);
Margreeth95 4:69c6cc1247c1 53 led = 0;
Margreeth95 4:69c6cc1247c1 54 wait(0.2f);
Margreeth95 4:69c6cc1247c1 55 motor2speed = 0;
Margreeth95 4:69c6cc1247c1 56 led = 1;
Margreeth95 4:69c6cc1247c1 57 break;
Margreeth95 4:69c6cc1247c1 58 }
Margreeth95 4:69c6cc1247c1 59 }
Rvs94 0:c8684fed9b61 60 }
Rvs94 0:c8684fed9b61 61 }