My version of servo tester for single servo.

Dependencies:   F746_GUI Servo mbed

Committer:
no111u3
Date:
Mon Feb 12 19:41:30 2018 +0000
Revision:
1:63566652d74d
Parent:
0:d63249ffaef5
Child:
2:20db1e92bcf8
Graphical fronted to servo test proto.

Who changed what in which revision?

UserRevisionLine numberNew 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 pc.printf("Press '1' to turn LED1 ON, '0' to turn it OFF\r\n");
no111u3 1:63566652d74d 22 pc.printf("2,3,4 - Position Servo (full left, middle, full right)\r\n");
no111u3 1:63566652d74d 23 Label title(240, 2,
no111u3 1:63566652d74d 24 "Servo - Tester: 2018/02/12, 21:53", Label::CENTER, Font16);
no111u3 1:63566652d74d 25 Button buttonLed(10, 54, 50, 40, "Led");
no111u3 1:63566652d74d 26
no111u3 1:63566652d74d 27 SeekBar barServo(20, 250, 200, 0, 100, 0, "0", "50", "100");
no111u3 1:63566652d74d 28 NumericLabel<float> labelServo(130, 205, "%%%5.1f", barServo.GetValue());
no111u3 1:63566652d74d 29
no111u3 1:63566652d74d 30 const int NUMBER_BUTTONS = 3;
no111u3 1:63566652d74d 31 const string STR1[NUMBER_BUTTONS] = {
no111u3 1:63566652d74d 32 "Left", "Center", "Right"};
no111u3 1:63566652d74d 33 ButtonGroup bgroupPosition(160, 54, 66, 40,
no111u3 1:63566652d74d 34 NUMBER_BUTTONS, STR1, 5, 5, 3, 1,
no111u3 1:63566652d74d 35 Font12, LCD_COLOR_WHITE, 0xFF003538, 0xFFB70068);
no111u3 0:d63249ffaef5 36
no111u3 0:d63249ffaef5 37 while(1) {
no111u3 1:63566652d74d 38 float position;
no111u3 1:63566652d74d 39
no111u3 1:63566652d74d 40 if (buttonLed.Touched()) {
no111u3 1:63566652d74d 41 buttonLed.Draw();
no111u3 1:63566652d74d 42 led = led.read() ^ 1;
no111u3 1:63566652d74d 43 wait(0.5f);
no111u3 1:63566652d74d 44 }
no111u3 1:63566652d74d 45 if (barServo.Slide()) {
no111u3 1:63566652d74d 46 labelServo.Draw("%%%5.1f", barServo.GetValue());
no111u3 1:63566652d74d 47 position = barServo.GetValue() / 100;
no111u3 1:63566652d74d 48 test_servo = position;
no111u3 0:d63249ffaef5 49 }
no111u3 1:63566652d74d 50
no111u3 1:63566652d74d 51 int num = 0;
no111u3 1:63566652d74d 52 if (bgroupPosition.GetTouchedNumber(num)) {
no111u3 1:63566652d74d 53 bgroupPosition.DrawAll();
no111u3 1:63566652d74d 54 switch (num) {
no111u3 1:63566652d74d 55 case 0:
no111u3 1:63566652d74d 56 position = 0.0f;
no111u3 1:63566652d74d 57 test_servo = position;
no111u3 1:63566652d74d 58 break;
no111u3 1:63566652d74d 59 case 1:
no111u3 1:63566652d74d 60 position = 0.5f;
no111u3 1:63566652d74d 61 test_servo = position;
no111u3 1:63566652d74d 62 break;
no111u3 1:63566652d74d 63 case 2:
no111u3 1:63566652d74d 64 position = 1.0f;
no111u3 1:63566652d74d 65 test_servo = position;
no111u3 1:63566652d74d 66 break;
no111u3 1:63566652d74d 67 }
no111u3 1:63566652d74d 68 barServo.SetValue(position*100);
no111u3 1:63566652d74d 69 barServo.Redraw();
no111u3 1:63566652d74d 70 labelServo.Draw("%%%5.1f", barServo.GetValue());
no111u3 1:63566652d74d 71 wait(0.5f);
no111u3 1:63566652d74d 72 }
no111u3 1:63566652d74d 73
no111u3 1:63566652d74d 74 wait(0.02f);
no111u3 0:d63249ffaef5 75 }
no111u3 0:d63249ffaef5 76 }