My version of servo tester for single servo.
Dependencies: F746_GUI Servo mbed
main.cpp@3:0eb12c3043a3, 2018-02-13 (annotated)
- Committer:
- no111u3
- Date:
- Tue Feb 13 16:45:08 2018 +0000
- Revision:
- 3:0eb12c3043a3
- Parent:
- 2:20db1e92bcf8
Remove unneeded lcd instance from main.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
no111u3 | 0:d63249ffaef5 | 1 | #include "mbed.h" |
no111u3 | 0:d63249ffaef5 | 2 | #include "Servo.h" |
no111u3 | 0:d63249ffaef5 | 3 | #include "PinNames.h" |
no111u3 | 0:d63249ffaef5 | 4 | |
no111u3 | 1:63566652d74d | 5 | #include "F746_GUI.hpp" |
no111u3 | 1:63566652d74d | 6 | |
no111u3 | 0:d63249ffaef5 | 7 | Serial pc(SERIAL_TX, SERIAL_RX); |
no111u3 | 0:d63249ffaef5 | 8 | DigitalOut led(LED1); |
no111u3 | 0:d63249ffaef5 | 9 | |
no111u3 | 0:d63249ffaef5 | 10 | Servo test_servo(D0); |
no111u3 | 0:d63249ffaef5 | 11 | |
no111u3 | 0:d63249ffaef5 | 12 | int main() |
no111u3 | 0:d63249ffaef5 | 13 | { |
no111u3 | 1:63566652d74d | 14 | Label title(240, 2, |
no111u3 | 2:20db1e92bcf8 | 15 | "Servo - Tester. version: 0.1.0", Label::CENTER, Font16); |
no111u3 | 1:63566652d74d | 16 | Button buttonLed(10, 54, 50, 40, "Led"); |
no111u3 | 1:63566652d74d | 17 | |
no111u3 | 1:63566652d74d | 18 | SeekBar barServo(20, 250, 200, 0, 100, 0, "0", "50", "100"); |
no111u3 | 1:63566652d74d | 19 | NumericLabel<float> labelServo(130, 205, "%%%5.1f", barServo.GetValue()); |
no111u3 | 1:63566652d74d | 20 | |
no111u3 | 1:63566652d74d | 21 | const int NUMBER_BUTTONS = 3; |
no111u3 | 1:63566652d74d | 22 | const string STR1[NUMBER_BUTTONS] = { |
no111u3 | 1:63566652d74d | 23 | "Left", "Center", "Right"}; |
no111u3 | 1:63566652d74d | 24 | ButtonGroup bgroupPosition(160, 54, 66, 40, |
no111u3 | 1:63566652d74d | 25 | NUMBER_BUTTONS, STR1, 5, 5, 3, 1, |
no111u3 | 1:63566652d74d | 26 | Font12, LCD_COLOR_WHITE, 0xFF003538, 0xFFB70068); |
no111u3 | 0:d63249ffaef5 | 27 | |
no111u3 | 0:d63249ffaef5 | 28 | while(1) { |
no111u3 | 1:63566652d74d | 29 | float position; |
no111u3 | 1:63566652d74d | 30 | |
no111u3 | 1:63566652d74d | 31 | if (buttonLed.Touched()) { |
no111u3 | 1:63566652d74d | 32 | buttonLed.Draw(); |
no111u3 | 1:63566652d74d | 33 | led = led.read() ^ 1; |
no111u3 | 1:63566652d74d | 34 | wait(0.5f); |
no111u3 | 1:63566652d74d | 35 | } |
no111u3 | 1:63566652d74d | 36 | if (barServo.Slide()) { |
no111u3 | 1:63566652d74d | 37 | labelServo.Draw("%%%5.1f", barServo.GetValue()); |
no111u3 | 1:63566652d74d | 38 | position = barServo.GetValue() / 100; |
no111u3 | 1:63566652d74d | 39 | test_servo = position; |
no111u3 | 0:d63249ffaef5 | 40 | } |
no111u3 | 1:63566652d74d | 41 | |
no111u3 | 1:63566652d74d | 42 | int num = 0; |
no111u3 | 1:63566652d74d | 43 | if (bgroupPosition.GetTouchedNumber(num)) { |
no111u3 | 1:63566652d74d | 44 | bgroupPosition.DrawAll(); |
no111u3 | 1:63566652d74d | 45 | switch (num) { |
no111u3 | 1:63566652d74d | 46 | case 0: |
no111u3 | 1:63566652d74d | 47 | position = 0.0f; |
no111u3 | 1:63566652d74d | 48 | test_servo = position; |
no111u3 | 1:63566652d74d | 49 | break; |
no111u3 | 1:63566652d74d | 50 | case 1: |
no111u3 | 1:63566652d74d | 51 | position = 0.5f; |
no111u3 | 1:63566652d74d | 52 | test_servo = position; |
no111u3 | 1:63566652d74d | 53 | break; |
no111u3 | 1:63566652d74d | 54 | case 2: |
no111u3 | 1:63566652d74d | 55 | position = 1.0f; |
no111u3 | 1:63566652d74d | 56 | test_servo = position; |
no111u3 | 1:63566652d74d | 57 | break; |
no111u3 | 1:63566652d74d | 58 | } |
no111u3 | 1:63566652d74d | 59 | barServo.SetValue(position*100); |
no111u3 | 1:63566652d74d | 60 | barServo.Redraw(); |
no111u3 | 1:63566652d74d | 61 | labelServo.Draw("%%%5.1f", barServo.GetValue()); |
no111u3 | 1:63566652d74d | 62 | wait(0.5f); |
no111u3 | 1:63566652d74d | 63 | } |
no111u3 | 1:63566652d74d | 64 | |
no111u3 | 1:63566652d74d | 65 | wait(0.02f); |
no111u3 | 0:d63249ffaef5 | 66 | } |
no111u3 | 0:d63249ffaef5 | 67 | } |