-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmindsensors-rcxmotormux-test1.c
70 lines (58 loc) · 2.01 KB
/
mindsensors-rcxmotormux-test1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma config(Sensor, S1, MSMTRMX, sensorI2CCustomFastSkipStates)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*
* $Id: mindsensors-rcxmotormux-test1.c 133 2013-03-10 15:15:38Z xander $
*/
/**
* mindsensors-rcxmotormux.h provides an API for the Mindsensors RCX Motor MUX.
* This program demonstrates how to use the driver for the Mindsensors RCX Motor Mux.
* Plug the mux into sensor port 1, and a motor into motor output 1. The motor will
* gradually speed up to full power and then back again, and then the same backwards.
* It will then gradually increase the braking force from nothing to full power, and
* back to zero, before turning the motor off
*
* Changelog:
* - 0.1: Initial release
*
* License: You may use this code as you wish, provided you give credit where it's due.
*
* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER.
* Daniel Playfair Cal (daniel.playfair.cal_at_gmail.com)
* 20 September 2011
* version 0.1
*/
#include "drivers/mindsensors-rcxmotormux.h"
task main () {
// Gradually speed up
for (int power = 0; power <= 255; power++) {
MSMTRMX_Control (MSMTRMX, MSMTRMX_M1, power);
wait1Msec (20);
}
// Gradually slow down
for (int power = 255; power >=1; power--) {
MSMTRMX_Control (MSMTRMX, MSMTRMX_M1, power);
wait1Msec (20);
}
// The same backwards
for (int power = 0; power >= -255; power--) {
MSMTRMX_Control (MSMTRMX, MSMTRMX_M1, power);
wait1Msec (20);
}
// Slow down again
for (int power = -255; power <= -1; power++) {
MSMTRMX_Control (MSMTRMX, MSMTRMX_M1, power);
wait1Msec (20);
}
// Gradually increase braking force
for (int force = 0; force <= 255; force++) {
MSMTRMX_Brake (MSMTRMX, MSMTRMX_M1, force);
wait1Msec (20);
}
// Gradually reduce braing force
for (int force = 255; force >=1; force--) {
MSMTRMX_Brake (MSMTRMX, MSMTRMX_M1, force);
wait1Msec (20);
}
// Turn off the motor
MSMTRMX_Control (MSMTRMX, MSMTRMX_M1, 0);
}