![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
My version of servo tester for single servo.
Dependencies: F746_GUI Servo mbed
Diff: main.cpp
- Revision:
- 1:63566652d74d
- Parent:
- 0:d63249ffaef5
- Child:
- 2:20db1e92bcf8
--- a/main.cpp Mon Feb 12 17:59:43 2018 +0000 +++ b/main.cpp Mon Feb 12 19:41:30 2018 +0000 @@ -2,38 +2,75 @@ #include "Servo.h" #include "PinNames.h" +#include "F746_GUI.hpp" + Serial pc(SERIAL_TX, SERIAL_RX); DigitalOut led(LED1); Servo test_servo(D0); +LCD_DISCO_F746NG lcd; int main() { - pc.printf("Press '1' to turn LED1 ON, '0' to turn it OFF\n"); - pc.printf("2,3,4 - Position Servo (full left, middle, full right)\n"); - float position = 0.0f; + lcd.Clear(LCD_COLOR_BLUE); + lcd.SetFont(&Font24); + + lcd.SetBackColor(LCD_COLOR_BLUE); + lcd.SetTextColor(LCD_COLOR_WHITE); + + pc.printf("Press '1' to turn LED1 ON, '0' to turn it OFF\r\n"); + pc.printf("2,3,4 - Position Servo (full left, middle, full right)\r\n"); + Label title(240, 2, + "Servo - Tester: 2018/02/12, 21:53", Label::CENTER, Font16); + Button buttonLed(10, 54, 50, 40, "Led"); + + SeekBar barServo(20, 250, 200, 0, 100, 0, "0", "50", "100"); + NumericLabel<float> labelServo(130, 205, "%%%5.1f", barServo.GetValue()); + + const int NUMBER_BUTTONS = 3; + const string STR1[NUMBER_BUTTONS] = { + "Left", "Center", "Right"}; + ButtonGroup bgroupPosition(160, 54, 66, 40, + NUMBER_BUTTONS, STR1, 5, 5, 3, 1, + Font12, LCD_COLOR_WHITE, 0xFF003538, 0xFFB70068); while(1) { - char c = pc.getc(); // Read hyperterminal - switch (c) { - case '0': - led = 0; // OFF - break; - case '1': - led = 1; // ON - break; - case '2': - position = 0.0f; - test_servo = position; - break; - case '3': - position = 0.5f; - test_servo = position; - break; - case '4': - position = 1.0f; - test_servo = position; - break; + float position; + + if (buttonLed.Touched()) { + buttonLed.Draw(); + led = led.read() ^ 1; + wait(0.5f); + } + if (barServo.Slide()) { + labelServo.Draw("%%%5.1f", barServo.GetValue()); + position = barServo.GetValue() / 100; + test_servo = position; } + + int num = 0; + if (bgroupPosition.GetTouchedNumber(num)) { + bgroupPosition.DrawAll(); + switch (num) { + case 0: + position = 0.0f; + test_servo = position; + break; + case 1: + position = 0.5f; + test_servo = position; + break; + case 2: + position = 1.0f; + test_servo = position; + break; + } + barServo.SetValue(position*100); + barServo.Redraw(); + labelServo.Draw("%%%5.1f", barServo.GetValue()); + wait(0.5f); + } + + wait(0.02f); } }