Library for using the xbee-compatible Bluetooth Bee Module on an m3pi.
Dependencies: SensoryTest
Fork of btbee by
main.cpp@9:6ae4359b73df, 2014-05-20 (annotated)
- Committer:
- mmpeter
- Date:
- Tue May 20 13:53:38 2014 +0000
- Revision:
- 9:6ae4359b73df
- Parent:
- 8:fd8a30a6923d
- Child:
- 10:7ef481d28dcd
Initial WORKING S1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mmpeter | 8:fd8a30a6923d | 1 | #include "mbed.h" |
mmpeter | 8:fd8a30a6923d | 2 | #include "m3pi_ng.h" |
mmpeter | 8:fd8a30a6923d | 3 | |
mmpeter | 8:fd8a30a6923d | 4 | m3pi thinggy; |
mmpeter | 8:fd8a30a6923d | 5 | |
mmpeter | 8:fd8a30a6923d | 6 | |
mmpeter | 8:fd8a30a6923d | 7 | int main() { |
mmpeter | 8:fd8a30a6923d | 8 | |
mmpeter | 8:fd8a30a6923d | 9 | float speed = 0.1; |
mmpeter | 9:6ae4359b73df | 10 | float threshold = 0.1; |
mmpeter | 9:6ae4359b73df | 11 | |
mmpeter | 9:6ae4359b73df | 12 | thinggy.locate(0,1); |
mmpeter | 9:6ae4359b73df | 13 | thinggy.printf("Line Flw"); |
mmpeter | 8:fd8a30a6923d | 14 | |
mmpeter | 8:fd8a30a6923d | 15 | wait(2.0); |
mmpeter | 8:fd8a30a6923d | 16 | |
mmpeter | 8:fd8a30a6923d | 17 | thinggy.sensor_auto_calibrate(); |
mmpeter | 8:fd8a30a6923d | 18 | while(1) { |
mmpeter | 8:fd8a30a6923d | 19 | // -1.0 is far left, 1.0 is far right, 0.0 in the middle |
mmpeter | 8:fd8a30a6923d | 20 | float position= thinggy.line_position(); |
mmpeter | 8:fd8a30a6923d | 21 | |
mmpeter | 8:fd8a30a6923d | 22 | // Line is more than the threshold to the right, slow the left motor |
mmpeter | 8:fd8a30a6923d | 23 | if (position > threshold) { |
mmpeter | 8:fd8a30a6923d | 24 | thinggy.right(speed); |
mmpeter | 9:6ae4359b73df | 25 | |
mmpeter | 8:fd8a30a6923d | 26 | } |
mmpeter | 8:fd8a30a6923d | 27 | |
mmpeter | 8:fd8a30a6923d | 28 | // Line is more than 50% to the left, slow the right motor |
mmpeter | 8:fd8a30a6923d | 29 | else if (position < -threshold) { |
mmpeter | 9:6ae4359b73df | 30 | thinggy.left_motor(speed); |
mmpeter | 8:fd8a30a6923d | 31 | |
mmpeter | 8:fd8a30a6923d | 32 | } |
mmpeter | 8:fd8a30a6923d | 33 | |
mmpeter | 8:fd8a30a6923d | 34 | // Line is in the middle |
mmpeter | 8:fd8a30a6923d | 35 | else { |
mmpeter | 8:fd8a30a6923d | 36 | thinggy.forward(speed); |
mmpeter | 8:fd8a30a6923d | 37 | } |
mmpeter | 8:fd8a30a6923d | 38 | } |
mmpeter | 8:fd8a30a6923d | 39 | } |
mmpeter | 8:fd8a30a6923d | 40 |