MTM PPO mbed cz2

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI

Committer:
paweler
Date:
Mon Jun 15 14:47:01 2020 +0000
Revision:
0:5d432267a99f
mbed cz2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
paweler 0:5d432267a99f 1 #include "servo_gui.h"
paweler 0:5d432267a99f 2 #define PI 3.1415
paweler 0:5d432267a99f 3
paweler 0:5d432267a99f 4 ServoGui::ServoGui(void)
paweler 0:5d432267a99f 5 {
paweler 0:5d432267a99f 6 lcd.Clear(LCD_COLOR_WHITE);
paweler 0:5d432267a99f 7 lcd.SetTextColor(LCD_COLOR_BLACK);
paweler 0:5d432267a99f 8 lcd.FillCircle(120, 120, 98);
paweler 0:5d432267a99f 9 lcd.DrawCircle(30, 290, 20);
paweler 0:5d432267a99f 10 lcd.DrawCircle(90, 290, 20);
paweler 0:5d432267a99f 11 lcd.DrawCircle(150, 290, 20);
paweler 0:5d432267a99f 12 lcd.DrawCircle(210, 290, 20);
paweler 0:5d432267a99f 13 lcd.SetTextColor(LCD_COLOR_WHITE);
paweler 0:5d432267a99f 14 lcd.FillCircle(120, 120, 20);
paweler 0:5d432267a99f 15 lcd.DrawLine(120, 120, 120+98, 120);
paweler 0:5d432267a99f 16 }
paweler 0:5d432267a99f 17
paweler 0:5d432267a99f 18 void ServoGui::LedOn(unsigned char ucLedIndex)
paweler 0:5d432267a99f 19 {
paweler 0:5d432267a99f 20 lcd.SetTextColor(LCD_COLOR_WHITE);
paweler 0:5d432267a99f 21 for(unsigned char ucLedCounter = 0; ucLedCounter < 4; ucLedCounter++) {
paweler 0:5d432267a99f 22 lcd.FillCircle(30+ucLedCounter*60, 290, 19);
paweler 0:5d432267a99f 23 }
paweler 0:5d432267a99f 24 lcd.SetTextColor(LCD_COLOR_BLUE);
paweler 0:5d432267a99f 25 lcd.FillCircle(30+ucLedIndex*60, 290, 19);
paweler 0:5d432267a99f 26 }
paweler 0:5d432267a99f 27
paweler 0:5d432267a99f 28 void ServoGui::LedStep(enum StepDirection eDirection)
paweler 0:5d432267a99f 29 {
paweler 0:5d432267a99f 30 if(eDirection == LEFT) {
paweler 0:5d432267a99f 31 ucLedCtr--;
paweler 0:5d432267a99f 32 } else if(eDirection == RIGHT) {
paweler 0:5d432267a99f 33 ucLedCtr++;
paweler 0:5d432267a99f 34 }
paweler 0:5d432267a99f 35 LedOn(ucLedCtr%4);
paweler 0:5d432267a99f 36 }
paweler 0:5d432267a99f 37
paweler 0:5d432267a99f 38 void ServoGui::MotorStep(enum StepDirection eDirection)
paweler 0:5d432267a99f 39 {
paweler 0:5d432267a99f 40 if(eDirection == LEFT) {
paweler 0:5d432267a99f 41 uiStepCounter--;
paweler 0:5d432267a99f 42 } else if(eDirection == RIGHT) {
paweler 0:5d432267a99f 43 uiStepCounter++;
paweler 0:5d432267a99f 44 }
paweler 0:5d432267a99f 45 dAngle = uiStepCounter % 360;
paweler 0:5d432267a99f 46 lcd.SetTextColor(LCD_COLOR_BLACK);
paweler 0:5d432267a99f 47 lcd.FillCircle(120, 120, 98);
paweler 0:5d432267a99f 48 lcd.SetTextColor(LCD_COLOR_WHITE);
paweler 0:5d432267a99f 49 lcd.DrawLine(120,120,120+98*cos(dAngle*PI/180), 120+98*sin(dAngle*PI/180));
paweler 0:5d432267a99f 50 lcd.FillCircle(120, 120, 20);
paweler 0:5d432267a99f 51 }
paweler 0:5d432267a99f 52
paweler 0:5d432267a99f 53 void ServoGui::GuiStepLeft(void)
paweler 0:5d432267a99f 54 {
paweler 0:5d432267a99f 55 LedStep(LEFT);
paweler 0:5d432267a99f 56 MotorStep(LEFT);
paweler 0:5d432267a99f 57 //wait(0.04);
paweler 0:5d432267a99f 58 }
paweler 0:5d432267a99f 59
paweler 0:5d432267a99f 60 void ServoGui::GuiStepRight(void)
paweler 0:5d432267a99f 61 {
paweler 0:5d432267a99f 62 LedStep(RIGHT);
paweler 0:5d432267a99f 63 MotorStep(RIGHT);
paweler 0:5d432267a99f 64 //wait(0.04);
paweler 0:5d432267a99f 65 }
paweler 0:5d432267a99f 66
paweler 0:5d432267a99f 67 unsigned char ServoGui::ucReadDetector(void)
paweler 0:5d432267a99f 68 {
paweler 0:5d432267a99f 69 if(dAngle == 0) {
paweler 0:5d432267a99f 70 return 1;
paweler 0:5d432267a99f 71 } else {
paweler 0:5d432267a99f 72 return 0;
paweler 0:5d432267a99f 73 }
paweler 0:5d432267a99f 74 }