My version of servo tester for single servo.
Dependencies: F746_GUI Servo mbed
main.cpp@2:20db1e92bcf8, 2018-02-12 (annotated)
- Committer:
- no111u3
- Date:
- Mon Feb 12 19:45:55 2018 +0000
- Revision:
- 2:20db1e92bcf8
- Parent:
- 1:63566652d74d
- Child:
- 3:0eb12c3043a3
Clean project. Adding version.
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 | 1:63566652d74d | 11 | LCD_DISCO_F746NG lcd; |
no111u3 | 0:d63249ffaef5 | 12 | |
no111u3 | 0:d63249ffaef5 | 13 | int main() |
no111u3 | 0:d63249ffaef5 | 14 | { |
no111u3 | 1:63566652d74d | 15 | lcd.Clear(LCD_COLOR_BLUE); |
no111u3 | 1:63566652d74d | 16 | lcd.SetFont(&Font24); |
no111u3 | 1:63566652d74d | 17 | |
no111u3 | 1:63566652d74d | 18 | lcd.SetBackColor(LCD_COLOR_BLUE); |
no111u3 | 1:63566652d74d | 19 | lcd.SetTextColor(LCD_COLOR_WHITE); |
no111u3 | 1:63566652d74d | 20 | |
no111u3 | 1:63566652d74d | 21 | Label title(240, 2, |
no111u3 | 2:20db1e92bcf8 | 22 | "Servo - Tester. version: 0.1.0", Label::CENTER, Font16); |
no111u3 | 1:63566652d74d | 23 | Button buttonLed(10, 54, 50, 40, "Led"); |
no111u3 | 1:63566652d74d | 24 | |
no111u3 | 1:63566652d74d | 25 | SeekBar barServo(20, 250, 200, 0, 100, 0, "0", "50", "100"); |
no111u3 | 1:63566652d74d | 26 | NumericLabel<float> labelServo(130, 205, "%%%5.1f", barServo.GetValue()); |
no111u3 | 1:63566652d74d | 27 | |
no111u3 | 1:63566652d74d | 28 | const int NUMBER_BUTTONS = 3; |
no111u3 | 1:63566652d74d | 29 | const string STR1[NUMBER_BUTTONS] = { |
no111u3 | 1:63566652d74d | 30 | "Left", "Center", "Right"}; |
no111u3 | 1:63566652d74d | 31 | ButtonGroup bgroupPosition(160, 54, 66, 40, |
no111u3 | 1:63566652d74d | 32 | NUMBER_BUTTONS, STR1, 5, 5, 3, 1, |
no111u3 | 1:63566652d74d | 33 | Font12, LCD_COLOR_WHITE, 0xFF003538, 0xFFB70068); |
no111u3 | 0:d63249ffaef5 | 34 | |
no111u3 | 0:d63249ffaef5 | 35 | while(1) { |
no111u3 | 1:63566652d74d | 36 | float position; |
no111u3 | 1:63566652d74d | 37 | |
no111u3 | 1:63566652d74d | 38 | if (buttonLed.Touched()) { |
no111u3 | 1:63566652d74d | 39 | buttonLed.Draw(); |
no111u3 | 1:63566652d74d | 40 | led = led.read() ^ 1; |
no111u3 | 1:63566652d74d | 41 | wait(0.5f); |
no111u3 | 1:63566652d74d | 42 | } |
no111u3 | 1:63566652d74d | 43 | if (barServo.Slide()) { |
no111u3 | 1:63566652d74d | 44 | labelServo.Draw("%%%5.1f", barServo.GetValue()); |
no111u3 | 1:63566652d74d | 45 | position = barServo.GetValue() / 100; |
no111u3 | 1:63566652d74d | 46 | test_servo = position; |
no111u3 | 0:d63249ffaef5 | 47 | } |
no111u3 | 1:63566652d74d | 48 | |
no111u3 | 1:63566652d74d | 49 | int num = 0; |
no111u3 | 1:63566652d74d | 50 | if (bgroupPosition.GetTouchedNumber(num)) { |
no111u3 | 1:63566652d74d | 51 | bgroupPosition.DrawAll(); |
no111u3 | 1:63566652d74d | 52 | switch (num) { |
no111u3 | 1:63566652d74d | 53 | case 0: |
no111u3 | 1:63566652d74d | 54 | position = 0.0f; |
no111u3 | 1:63566652d74d | 55 | test_servo = position; |
no111u3 | 1:63566652d74d | 56 | break; |
no111u3 | 1:63566652d74d | 57 | case 1: |
no111u3 | 1:63566652d74d | 58 | position = 0.5f; |
no111u3 | 1:63566652d74d | 59 | test_servo = position; |
no111u3 | 1:63566652d74d | 60 | break; |
no111u3 | 1:63566652d74d | 61 | case 2: |
no111u3 | 1:63566652d74d | 62 | position = 1.0f; |
no111u3 | 1:63566652d74d | 63 | test_servo = position; |
no111u3 | 1:63566652d74d | 64 | break; |
no111u3 | 1:63566652d74d | 65 | } |
no111u3 | 1:63566652d74d | 66 | barServo.SetValue(position*100); |
no111u3 | 1:63566652d74d | 67 | barServo.Redraw(); |
no111u3 | 1:63566652d74d | 68 | labelServo.Draw("%%%5.1f", barServo.GetValue()); |
no111u3 | 1:63566652d74d | 69 | wait(0.5f); |
no111u3 | 1:63566652d74d | 70 | } |
no111u3 | 1:63566652d74d | 71 | |
no111u3 | 1:63566652d74d | 72 | wait(0.02f); |
no111u3 | 0:d63249ffaef5 | 73 | } |
no111u3 | 0:d63249ffaef5 | 74 | } |