Samenwerking Groep 12

Dependencies:   Encoder MODSERIAL HIDScope mbed

Foo

Committer:
ThomasBNL
Date:
Mon Sep 21 13:18:29 2015 +0000
Revision:
10:e923f51f18c4
Parent:
9:0a7981d2da8a
Child:
12:af428d56b4eb
Child:
14:7603d7f1dbe9
als >4200 nu reset de positie

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThomasBNL 10:e923f51f18c4 1 #include "mbed.h"
ThomasBNL 10:e923f51f18c4 2 #include "HIDScope.h"
ThomasBNL 10:e923f51f18c4 3 #include "encoder.h"
ThomasBNL 10:e923f51f18c4 4 #include "MODSERIAL.h"
ThomasBNL 10:e923f51f18c4 5
ThomasBNL 10:e923f51f18c4 6 //Motor 2
ThomasBNL 10:e923f51f18c4 7 DigitalOut motor2direction(D4); //D4 en D5 zijn motor 2 (op het motorshield)
ThomasBNL 10:e923f51f18c4 8 PwmOut motor2speed(D5);
ThomasBNL 10:e923f51f18c4 9 DigitalIn button(PTA4);
ThomasBNL 10:e923f51f18c4 10 Encoder motor2(D13,D12);
ThomasBNL 10:e923f51f18c4 11 MODSERIAL pc(USBTX,USBRX);
ThomasBNL 10:e923f51f18c4 12 //AnalogIn potmeter2(A0); /NIEUW
ThomasBNL 10:e923f51f18c4 13 int main()
ThomasBNL 10:e923f51f18c4 14 {
ThomasBNL 10:e923f51f18c4 15 pc.baud(9600);
ThomasBNL 10:e923f51f18c4 16 motor2.setPosition(0);
ThomasBNL 10:e923f51f18c4 17 while(true) {
ThomasBNL 10:e923f51f18c4 18 if (button.read() < 0.5) { //if button pressed
ThomasBNL 10:e923f51f18c4 19 motor2direction = 1;
ThomasBNL 10:e923f51f18c4 20 motor2speed = 0.5f;
ThomasBNL 10:e923f51f18c4 21 pc.printf("positie = %d \r\n", motor2.getPosition());
ThomasBNL 10:e923f51f18c4 22 } else { // If button is not pressed
ThomasBNL 10:e923f51f18c4 23 motor2direction = 0;
ThomasBNL 10:e923f51f18c4 24 motor2speed = 0;
ThomasBNL 10:e923f51f18c4 25 pc.printf("positie = %d \r\n", motor2.getPosition());
ThomasBNL 10:e923f51f18c4 26 }
ThomasBNL 10:e923f51f18c4 27
ThomasBNL 10:e923f51f18c4 28 while (motor2.getPosition() > 4200) {
ThomasBNL 10:e923f51f18c4 29 motor2.setPosition(0);
ThomasBNL 10:e923f51f18c4 30 pc.printf("Call foo! The cake is a lie!! \r\n");
ThomasBNL 10:e923f51f18c4 31 break;
ThomasBNL 10:e923f51f18c4 32 }
ThomasBNL 10:e923f51f18c4 33 }
ThomasBNL 10:e923f51f18c4 34 }
ThomasBNL 10:e923f51f18c4 35
ThomasBNL 10:e923f51f18c4 36
ThomasBNL 9:0a7981d2da8a 37 //#include "mbed.h"
ThomasBNL 10:e923f51f18c4 38 //#include "MODSERIAL.h"
ThomasBNL 9:0a7981d2da8a 39 //#include "HIDScope.h"
ThomasBNL 9:0a7981d2da8a 40 //#include "encoder.h"
ThomasBNL 9:0a7981d2da8a 41 //
ThomasBNL 10:e923f51f18c4 42 //MODSERIAL pc(USBTX,USBRX);
ThomasBNL 10:e923f51f18c4 43 //AnalogIn potmeter2(A0);
ThomasBNL 10:e923f51f18c4 44 //double Convert_pot_to_speed=0.000001;
ThomasBNL 9:0a7981d2da8a 45 //
ThomasBNL 9:0a7981d2da8a 46 //int main()
ThomasBNL 9:0a7981d2da8a 47 //{
ThomasBNL 9:0a7981d2da8a 48 // pc.baud(9600);
ThomasBNL 10:e923f51f18c4 49 // while (true) {
ThomasBNL 10:e923f51f18c4 50 // pc.printf("position: %d \r\n", potmeter2.read());
ThomasBNL 9:0a7981d2da8a 51 // }
ThomasBNL 9:0a7981d2da8a 52 //}