hiermee test je alle uitgangen

Dependencies:   mbed

Committer:
joosthartkamp
Date:
Wed May 31 22:14:43 2017 +0000
Revision:
0:5f21633b5255
om alle uitgangen te testen

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joosthartkamp 0:5f21633b5255 1 #include "mbed.h"
joosthartkamp 0:5f21633b5255 2
joosthartkamp 0:5f21633b5255 3 Ticker stepperspeed;
joosthartkamp 0:5f21633b5255 4
joosthartkamp 0:5f21633b5255 5
joosthartkamp 0:5f21633b5255 6 DigitalOut steppulse(D3);
joosthartkamp 0:5f21633b5255 7 DigitalOut enable(D4);
joosthartkamp 0:5f21633b5255 8 DigitalOut dir(D2);
joosthartkamp 0:5f21633b5255 9
joosthartkamp 0:5f21633b5255 10 DigitalIn button(D8);
joosthartkamp 0:5f21633b5255 11 DigitalOut led(D1);
joosthartkamp 0:5f21633b5255 12
joosthartkamp 0:5f21633b5255 13 PwmOut motorlpwm(D6);
joosthartkamp 0:5f21633b5255 14 PwmOut motorrpwm(D12);
joosthartkamp 0:5f21633b5255 15 DigitalOut motorlfwd(D7);
joosthartkamp 0:5f21633b5255 16 DigitalOut motorlrwd(D9);
joosthartkamp 0:5f21633b5255 17 DigitalOut motorrfwd(D10);
joosthartkamp 0:5f21633b5255 18 DigitalOut motorrrwd(D11);
joosthartkamp 0:5f21633b5255 19
joosthartkamp 0:5f21633b5255 20 bool run = 0;
joosthartkamp 0:5f21633b5255 21 bool lastbuttonstate = 0;
joosthartkamp 0:5f21633b5255 22 int ledset = 0;
joosthartkamp 0:5f21633b5255 23
joosthartkamp 0:5f21633b5255 24
joosthartkamp 0:5f21633b5255 25 void setstep()
joosthartkamp 0:5f21633b5255 26 {
joosthartkamp 0:5f21633b5255 27 steppulse = !steppulse;
joosthartkamp 0:5f21633b5255 28 }
joosthartkamp 0:5f21633b5255 29
joosthartkamp 0:5f21633b5255 30
joosthartkamp 0:5f21633b5255 31 int main()
joosthartkamp 0:5f21633b5255 32 {
joosthartkamp 0:5f21633b5255 33 button.mode(PullUp);
joosthartkamp 0:5f21633b5255 34 // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms)
joosthartkamp 0:5f21633b5255 35 stepperspeed.attach(&setstep, 0.0008);
joosthartkamp 0:5f21633b5255 36
joosthartkamp 0:5f21633b5255 37 motorlpwm.pulsewidth_us(50);
joosthartkamp 0:5f21633b5255 38 motorrpwm.pulsewidth_us(50);
joosthartkamp 0:5f21633b5255 39 enable = 1;
joosthartkamp 0:5f21633b5255 40 dir = 0;
joosthartkamp 0:5f21633b5255 41 motorlpwm = 0.8;
joosthartkamp 0:5f21633b5255 42 motorrpwm = 0.8;
joosthartkamp 0:5f21633b5255 43
joosthartkamp 0:5f21633b5255 44 while (1) {
joosthartkamp 0:5f21633b5255 45
joosthartkamp 0:5f21633b5255 46 led = 1;
joosthartkamp 0:5f21633b5255 47 wait_ms(500);
joosthartkamp 0:5f21633b5255 48 led = 0;
joosthartkamp 0:5f21633b5255 49 wait_ms(500);
joosthartkamp 0:5f21633b5255 50 led = 1;
joosthartkamp 0:5f21633b5255 51 wait_ms(500);
joosthartkamp 0:5f21633b5255 52 led = 0;
joosthartkamp 0:5f21633b5255 53 wait_ms(500);
joosthartkamp 0:5f21633b5255 54 motorlfwd = 1;
joosthartkamp 0:5f21633b5255 55 wait_ms(1000);
joosthartkamp 0:5f21633b5255 56 motorlfwd = 0;
joosthartkamp 0:5f21633b5255 57 motorlrwd = 1;
joosthartkamp 0:5f21633b5255 58 wait_ms(1000);
joosthartkamp 0:5f21633b5255 59 motorlrwd = 0;
joosthartkamp 0:5f21633b5255 60 motorrfwd = 1;
joosthartkamp 0:5f21633b5255 61 wait_ms(1000);
joosthartkamp 0:5f21633b5255 62 motorrfwd = 0;
joosthartkamp 0:5f21633b5255 63 motorrrwd = 1;
joosthartkamp 0:5f21633b5255 64 wait_ms(1000);
joosthartkamp 0:5f21633b5255 65 motorrrwd = 0;
joosthartkamp 0:5f21633b5255 66 enable = 0;
joosthartkamp 0:5f21633b5255 67 dir = 0;
joosthartkamp 0:5f21633b5255 68 wait_ms(2000);
joosthartkamp 0:5f21633b5255 69
joosthartkamp 0:5f21633b5255 70 dir = 1;
joosthartkamp 0:5f21633b5255 71 wait_ms(2000);
joosthartkamp 0:5f21633b5255 72 enable = 1;
joosthartkamp 0:5f21633b5255 73 }
joosthartkamp 0:5f21633b5255 74 }