Finalny program mbed2
Dependencies: LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI
led.cpp@0:33ff53112cc9, 2020-06-09 (annotated)
- Committer:
- azmuth_sd
- Date:
- Tue Jun 09 08:24:40 2020 +0000
- Revision:
- 0:33ff53112cc9
Ostatni program drugiej czesci mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
azmuth_sd | 0:33ff53112cc9 | 1 | #include "led.h" |
azmuth_sd | 0:33ff53112cc9 | 2 | |
azmuth_sd | 0:33ff53112cc9 | 3 | Led::Led (void){ |
azmuth_sd | 0:33ff53112cc9 | 4 | ucServoPos = 0; |
azmuth_sd | 0:33ff53112cc9 | 5 | unsigned char ucCurrentLed; |
azmuth_sd | 0:33ff53112cc9 | 6 | lcd.SetFont(&Font24); |
azmuth_sd | 0:33ff53112cc9 | 7 | lcd.Clear(LCD_COLOR_WHITE); |
azmuth_sd | 0:33ff53112cc9 | 8 | |
azmuth_sd | 0:33ff53112cc9 | 9 | lcd.SetTextColor(LCD_COLOR_BLACK); |
azmuth_sd | 0:33ff53112cc9 | 10 | for( ucCurrentLed = 1; ucCurrentLed < 5; ucCurrentLed++ ){ |
azmuth_sd | 0:33ff53112cc9 | 11 | lcd.FillCircle((ucCurrentLed*50)-5,260,20); |
azmuth_sd | 0:33ff53112cc9 | 12 | } |
azmuth_sd | 0:33ff53112cc9 | 13 | } |
azmuth_sd | 0:33ff53112cc9 | 14 | |
azmuth_sd | 0:33ff53112cc9 | 15 | void Led::On(unsigned char ucLedIndeks){ |
azmuth_sd | 0:33ff53112cc9 | 16 | |
azmuth_sd | 0:33ff53112cc9 | 17 | unsigned char ucCurrentLed; |
azmuth_sd | 0:33ff53112cc9 | 18 | float posX, posY; |
azmuth_sd | 0:33ff53112cc9 | 19 | lcd.SetTextColor(LCD_COLOR_BLACK); |
azmuth_sd | 0:33ff53112cc9 | 20 | lcd.FillCircle(120,120,90); |
azmuth_sd | 0:33ff53112cc9 | 21 | |
azmuth_sd | 0:33ff53112cc9 | 22 | lcd.SetTextColor(LCD_COLOR_WHITE); |
azmuth_sd | 0:33ff53112cc9 | 23 | lcd.FillCircle(120, 120, 10); |
azmuth_sd | 0:33ff53112cc9 | 24 | |
azmuth_sd | 0:33ff53112cc9 | 25 | for( ucCurrentLed = 1; ucCurrentLed < 5; ucCurrentLed++ ) |
azmuth_sd | 0:33ff53112cc9 | 26 | { |
azmuth_sd | 0:33ff53112cc9 | 27 | lcd.FillCircle((ucCurrentLed*50)-5,260,16); |
azmuth_sd | 0:33ff53112cc9 | 28 | } |
azmuth_sd | 0:33ff53112cc9 | 29 | |
azmuth_sd | 0:33ff53112cc9 | 30 | posX = 120 + (90 * sin((0.131 * ucServoPos))); |
azmuth_sd | 0:33ff53112cc9 | 31 | posY = 120 + (90 * cos((0.131 * ucServoPos))); |
azmuth_sd | 0:33ff53112cc9 | 32 | lcd.DrawLine(120, 120, posX, posY); |
azmuth_sd | 0:33ff53112cc9 | 33 | |
azmuth_sd | 0:33ff53112cc9 | 34 | lcd.SetTextColor(LCD_COLOR_BLUE); |
azmuth_sd | 0:33ff53112cc9 | 35 | lcd.FillCircle(((ucLedIndeks+1)*50)-5,260,16); |
azmuth_sd | 0:33ff53112cc9 | 36 | |
azmuth_sd | 0:33ff53112cc9 | 37 | } |
azmuth_sd | 0:33ff53112cc9 | 38 | |
azmuth_sd | 0:33ff53112cc9 | 39 | void Led::Step (enum LedDirection Direction){ |
azmuth_sd | 0:33ff53112cc9 | 40 | |
azmuth_sd | 0:33ff53112cc9 | 41 | static unsigned int uiLedCounter = 0; |
azmuth_sd | 0:33ff53112cc9 | 42 | |
azmuth_sd | 0:33ff53112cc9 | 43 | if(Direction == LEFT) |
azmuth_sd | 0:33ff53112cc9 | 44 | { |
azmuth_sd | 0:33ff53112cc9 | 45 | uiLedCounter++; |
azmuth_sd | 0:33ff53112cc9 | 46 | } |
azmuth_sd | 0:33ff53112cc9 | 47 | else |
azmuth_sd | 0:33ff53112cc9 | 48 | { |
azmuth_sd | 0:33ff53112cc9 | 49 | uiLedCounter--; |
azmuth_sd | 0:33ff53112cc9 | 50 | } |
azmuth_sd | 0:33ff53112cc9 | 51 | On(uiLedCounter%4); |
azmuth_sd | 0:33ff53112cc9 | 52 | } |
azmuth_sd | 0:33ff53112cc9 | 53 | |
azmuth_sd | 0:33ff53112cc9 | 54 | void Led::StepLeft(void){ |
azmuth_sd | 0:33ff53112cc9 | 55 | if(ucServoPos < 47) |
azmuth_sd | 0:33ff53112cc9 | 56 | { |
azmuth_sd | 0:33ff53112cc9 | 57 | ucServoPos++; |
azmuth_sd | 0:33ff53112cc9 | 58 | } |
azmuth_sd | 0:33ff53112cc9 | 59 | else |
azmuth_sd | 0:33ff53112cc9 | 60 | { |
azmuth_sd | 0:33ff53112cc9 | 61 | ucServoPos = 0; |
azmuth_sd | 0:33ff53112cc9 | 62 | } |
azmuth_sd | 0:33ff53112cc9 | 63 | Step(LEFT); |
azmuth_sd | 0:33ff53112cc9 | 64 | } |
azmuth_sd | 0:33ff53112cc9 | 65 | |
azmuth_sd | 0:33ff53112cc9 | 66 | void Led::StepRight(void){ |
azmuth_sd | 0:33ff53112cc9 | 67 | if(ucServoPos > 0) |
azmuth_sd | 0:33ff53112cc9 | 68 | { |
azmuth_sd | 0:33ff53112cc9 | 69 | ucServoPos--; |
azmuth_sd | 0:33ff53112cc9 | 70 | } |
azmuth_sd | 0:33ff53112cc9 | 71 | else |
azmuth_sd | 0:33ff53112cc9 | 72 | { |
azmuth_sd | 0:33ff53112cc9 | 73 | ucServoPos = 47; |
azmuth_sd | 0:33ff53112cc9 | 74 | } |
azmuth_sd | 0:33ff53112cc9 | 75 | Step(RIGHT); |
azmuth_sd | 0:33ff53112cc9 | 76 | } |