Werkend motorscript met led feedback

Dependencies:   Encoder MODSERIAL mbed HIDScope

Fork of frdm_Motortryout2 by Robert Schulte

Committer:
Margreeth95
Date:
Mon Sep 21 11:27:52 2015 +0000
Revision:
4:69c6cc1247c1
Parent:
3:051c91b04acd
Child:
5:672798238952
Switch;

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"
Rvs94 0:c8684fed9b61 4
Rvs94 0:c8684fed9b61 5 Serial pc(USBTX, USBRX); // tx, rx
Rvs94 3:051c91b04acd 6 DigitalOut led(LED_RED);
Rvs94 0:c8684fed9b61 7 DigitalOut motor2direction(D4); //D4 en D5 zijn motor 2 (op het motorshield)
Rvs94 0:c8684fed9b61 8 PwmOut motor2speed(D5);
Rvs94 0:c8684fed9b61 9 DigitalIn button1(SW3);
Rvs94 0:c8684fed9b61 10
Rvs94 0:c8684fed9b61 11 int main()
Rvs94 0:c8684fed9b61 12 {
Rvs94 3:051c91b04acd 13 motor2direction = 0;
Rvs94 0:c8684fed9b61 14 motor2speed = 0;
Rvs94 3:051c91b04acd 15 led = 1;
Rvs94 0:c8684fed9b61 16 pc.baud(9600);
Rvs94 0:c8684fed9b61 17 while(true)
Rvs94 0:c8684fed9b61 18 {
Margreeth95 4:69c6cc1247c1 19 char c = pc.getc();
Margreeth95 4:69c6cc1247c1 20 switch(c)
Margreeth95 4:69c6cc1247c1 21 {
Margreeth95 4:69c6cc1247c1 22 case 'f':
Rvs94 0:c8684fed9b61 23 {
Rvs94 3:051c91b04acd 24 motor2direction = 1;
Rvs94 0:c8684fed9b61 25 motor2speed = 0.5f;
Margreeth95 4:69c6cc1247c1 26 pc.printf("het werkt\n");
Rvs94 1:4e65a72b622e 27 wait(1);
Rvs94 3:051c91b04acd 28 led = 0;
Rvs94 1:4e65a72b622e 29 wait(0.2f);
Rvs94 1:4e65a72b622e 30 motor2speed = 0;
Rvs94 3:051c91b04acd 31 led = 1;
Margreeth95 4:69c6cc1247c1 32 break;
Rvs94 0:c8684fed9b61 33 }
Margreeth95 4:69c6cc1247c1 34
Margreeth95 4:69c6cc1247c1 35 case 'r':
Margreeth95 4:69c6cc1247c1 36 {
Margreeth95 4:69c6cc1247c1 37 motor2direction = -1;
Margreeth95 4:69c6cc1247c1 38 motor2speed = 0.5f;
Margreeth95 4:69c6cc1247c1 39 pc.printf("dit werkt ook\n");
Margreeth95 4:69c6cc1247c1 40 wait(1);
Margreeth95 4:69c6cc1247c1 41 led = 0;
Margreeth95 4:69c6cc1247c1 42 wait(0.2f);
Margreeth95 4:69c6cc1247c1 43 motor2speed = 0;
Margreeth95 4:69c6cc1247c1 44 led = 1;
Margreeth95 4:69c6cc1247c1 45 break;
Margreeth95 4:69c6cc1247c1 46 }
Margreeth95 4:69c6cc1247c1 47 }
Rvs94 0:c8684fed9b61 48 }
Rvs94 0:c8684fed9b61 49 }