Boris Vinogradov / Mbed 2 deprecated servo_test

Dependencies:   F746_GUI Servo mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Servo.h"
00003 #include "PinNames.h"
00004 
00005 #include    "F746_GUI.hpp"
00006 
00007 Serial pc(SERIAL_TX, SERIAL_RX);
00008 DigitalOut led(LED1);
00009 
00010 Servo test_servo(D0);
00011 
00012 int main()
00013 {
00014     Label title(240, 2,
00015         "Servo - Tester. version: 0.1.0", Label::CENTER, Font16);
00016     Button buttonLed(10, 54, 50, 40, "Led");
00017 
00018     SeekBar barServo(20, 250, 200, 0, 100, 0, "0", "50", "100");
00019     NumericLabel<float> labelServo(130, 205, "%%%5.1f", barServo.GetValue());
00020 
00021     const int NUMBER_BUTTONS = 3;
00022     const string STR1[NUMBER_BUTTONS] = {
00023         "Left", "Center", "Right"};
00024     ButtonGroup bgroupPosition(160, 54, 66, 40,
00025         NUMBER_BUTTONS, STR1, 5, 5, 3, 1,
00026         Font12, LCD_COLOR_WHITE, 0xFF003538, 0xFFB70068);
00027 
00028     while(1) {
00029         float position;
00030         
00031         if (buttonLed.Touched()) {
00032             buttonLed.Draw();
00033             led = led.read() ^ 1;
00034             wait(0.5f);
00035         }
00036         if (barServo.Slide()) {
00037             labelServo.Draw("%%%5.1f", barServo.GetValue());
00038             position = barServo.GetValue() / 100;
00039             test_servo = position;
00040         }
00041         
00042         int num = 0;
00043         if (bgroupPosition.GetTouchedNumber(num)) {
00044             bgroupPosition.DrawAll();
00045             switch (num) {
00046                 case 0:
00047                     position = 0.0f;
00048                     test_servo = position;
00049                     break;
00050                 case 1:
00051                     position = 0.5f;
00052                     test_servo = position;
00053                     break;
00054                 case 2:
00055                     position = 1.0f;
00056                     test_servo = position;
00057                     break;
00058             }
00059             barServo.SetValue(position*100);
00060             barServo.Redraw();
00061             labelServo.Draw("%%%5.1f", barServo.GetValue());
00062             wait(0.5f);
00063         }
00064 
00065         wait(0.02f);
00066     }
00067 }