mbed2 zad 5b

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI

Committer:
krzysiek99
Date:
Mon Jun 08 21:49:36 2020 +0000
Revision:
4:7855d3ab4c15
mbed2 zad 5b

Who changed what in which revision?

UserRevisionLine numberNew contents of line
krzysiek99 4:7855d3ab4c15 1 #include "ServoGui.h"
krzysiek99 4:7855d3ab4c15 2 #define PI (3.1415)
krzysiek99 4:7855d3ab4c15 3
krzysiek99 4:7855d3ab4c15 4 extern DigitalIn DetectorSignal;
krzysiek99 4:7855d3ab4c15 5
krzysiek99 4:7855d3ab4c15 6 void ServoGui::DrawBackground()
krzysiek99 4:7855d3ab4c15 7 {
krzysiek99 4:7855d3ab4c15 8 lcd.Clear(LCD_COLOR_WHITE);
krzysiek99 4:7855d3ab4c15 9 }
krzysiek99 4:7855d3ab4c15 10
krzysiek99 4:7855d3ab4c15 11 void ServoGui::DrawMotor()
krzysiek99 4:7855d3ab4c15 12 {
krzysiek99 4:7855d3ab4c15 13 lcd.SetTextColor(LCD_COLOR_BLACK);
krzysiek99 4:7855d3ab4c15 14 lcd.FillCircle(120, 100, 80);
krzysiek99 4:7855d3ab4c15 15 lcd.SetTextColor(LCD_COLOR_WHITE);
krzysiek99 4:7855d3ab4c15 16 lcd.FillCircle(120, 100, 15);
krzysiek99 4:7855d3ab4c15 17 }
krzysiek99 4:7855d3ab4c15 18
krzysiek99 4:7855d3ab4c15 19 DetectorState ServoGui::eDetectorRead(void)
krzysiek99 4:7855d3ab4c15 20 {
krzysiek99 4:7855d3ab4c15 21 if(DetectorSignal == 1)
krzysiek99 4:7855d3ab4c15 22 return ACTIVE;
krzysiek99 4:7855d3ab4c15 23 else
krzysiek99 4:7855d3ab4c15 24 return INACTIVE;
krzysiek99 4:7855d3ab4c15 25 }
krzysiek99 4:7855d3ab4c15 26
krzysiek99 4:7855d3ab4c15 27 void ServoGui::DrawDetectorPosition(unsigned int uiPosition)
krzysiek99 4:7855d3ab4c15 28 {
krzysiek99 4:7855d3ab4c15 29 lcd.SetTextColor(LCD_COLOR_WHITE);
krzysiek99 4:7855d3ab4c15 30 lcd.DrawLine(120, 100, 120+80*cos(0.5*PI+uiPosition*PI/180), 100+80*sin(0.5*PI+uiPosition*PI/180));
krzysiek99 4:7855d3ab4c15 31 }
krzysiek99 4:7855d3ab4c15 32
krzysiek99 4:7855d3ab4c15 33 void ServoGui::DrawLeds()
krzysiek99 4:7855d3ab4c15 34 {
krzysiek99 4:7855d3ab4c15 35 lcd.SetTextColor(LCD_COLOR_BLACK);
krzysiek99 4:7855d3ab4c15 36 unsigned char ucLedXposition = 55;
krzysiek99 4:7855d3ab4c15 37 for(unsigned char ucLedCounter = 0; ucLedCounter < 4; ucLedCounter++, ucLedXposition+=40)
krzysiek99 4:7855d3ab4c15 38 lcd.DrawCircle(ucLedXposition, 240, 15);
krzysiek99 4:7855d3ab4c15 39 }
krzysiek99 4:7855d3ab4c15 40
krzysiek99 4:7855d3ab4c15 41 ServoGui::ServoGui(unsigned int uiDetectorInitialPosition)
krzysiek99 4:7855d3ab4c15 42 {
krzysiek99 4:7855d3ab4c15 43 DrawBackground();
krzysiek99 4:7855d3ab4c15 44 DrawMotor();
krzysiek99 4:7855d3ab4c15 45 DrawLeds();
krzysiek99 4:7855d3ab4c15 46 DrawDetectorPosition(uiDetectorInitialPosition % 360);
krzysiek99 4:7855d3ab4c15 47 uiDetectorPosition = uiDetectorInitialPosition % 360;
krzysiek99 4:7855d3ab4c15 48 }
krzysiek99 4:7855d3ab4c15 49
krzysiek99 4:7855d3ab4c15 50 void ServoGui::ClearLeds()
krzysiek99 4:7855d3ab4c15 51 {
krzysiek99 4:7855d3ab4c15 52 lcd.SetTextColor(LCD_COLOR_WHITE);
krzysiek99 4:7855d3ab4c15 53 unsigned char ucLedXposition = 55;
krzysiek99 4:7855d3ab4c15 54 for(unsigned char ucLedCounter = 0; ucLedCounter < 4; ucLedCounter++, ucLedXposition+=40)
krzysiek99 4:7855d3ab4c15 55 lcd.FillCircle(ucLedXposition, 240, 14);
krzysiek99 4:7855d3ab4c15 56 }
krzysiek99 4:7855d3ab4c15 57
krzysiek99 4:7855d3ab4c15 58 void ServoGui::SetLed(unsigned char ucLedNumber)
krzysiek99 4:7855d3ab4c15 59 {
krzysiek99 4:7855d3ab4c15 60 ClearLeds();
krzysiek99 4:7855d3ab4c15 61 lcd.SetTextColor(LCD_COLOR_BLUE);
krzysiek99 4:7855d3ab4c15 62 lcd.FillCircle(55+40*ucLedNumber, 240, 14);
krzysiek99 4:7855d3ab4c15 63 }
krzysiek99 4:7855d3ab4c15 64
krzysiek99 4:7855d3ab4c15 65 void ServoGui::StepLed(Direction eDirection)
krzysiek99 4:7855d3ab4c15 66 {
krzysiek99 4:7855d3ab4c15 67 if(eDirection == LEFT)
krzysiek99 4:7855d3ab4c15 68 ucLedPosition = (ucLedPosition+3) % 4;
krzysiek99 4:7855d3ab4c15 69 else if(eDirection == RIGHT)
krzysiek99 4:7855d3ab4c15 70 ucLedPosition = (ucLedPosition+1) % 4;
krzysiek99 4:7855d3ab4c15 71 else
krzysiek99 4:7855d3ab4c15 72 ucLedPosition = ucLedPosition;
krzysiek99 4:7855d3ab4c15 73 SetLed(ucLedPosition);
krzysiek99 4:7855d3ab4c15 74 }
krzysiek99 4:7855d3ab4c15 75
krzysiek99 4:7855d3ab4c15 76 void ServoGui::LedStepLeft()
krzysiek99 4:7855d3ab4c15 77 {
krzysiek99 4:7855d3ab4c15 78 StepLed(LEFT);
krzysiek99 4:7855d3ab4c15 79 }
krzysiek99 4:7855d3ab4c15 80
krzysiek99 4:7855d3ab4c15 81 void ServoGui::LedStepRight()
krzysiek99 4:7855d3ab4c15 82 {
krzysiek99 4:7855d3ab4c15 83 StepLed(RIGHT);
krzysiek99 4:7855d3ab4c15 84 }
krzysiek99 4:7855d3ab4c15 85
krzysiek99 4:7855d3ab4c15 86 void ServoGui::DetectorStepLeft()
krzysiek99 4:7855d3ab4c15 87 {
krzysiek99 4:7855d3ab4c15 88 if(uiDetectorPosition == 0)
krzysiek99 4:7855d3ab4c15 89 uiDetectorPosition = 359;
krzysiek99 4:7855d3ab4c15 90 else
krzysiek99 4:7855d3ab4c15 91 uiDetectorPosition--;
krzysiek99 4:7855d3ab4c15 92 DrawMotor();
krzysiek99 4:7855d3ab4c15 93 wait(0.001);
krzysiek99 4:7855d3ab4c15 94 DrawDetectorPosition(uiDetectorPosition);
krzysiek99 4:7855d3ab4c15 95 }
krzysiek99 4:7855d3ab4c15 96
krzysiek99 4:7855d3ab4c15 97 void ServoGui::DetectorStepRight()
krzysiek99 4:7855d3ab4c15 98 {
krzysiek99 4:7855d3ab4c15 99 uiDetectorPosition = (uiDetectorPosition+1) % 360;
krzysiek99 4:7855d3ab4c15 100 DrawMotor();
krzysiek99 4:7855d3ab4c15 101 wait(0.001);
krzysiek99 4:7855d3ab4c15 102 DrawDetectorPosition(uiDetectorPosition);
krzysiek99 4:7855d3ab4c15 103 }