![](/media/cache/profiles/logo.jpeg.50x50_q85.jpg)
Display Steuerung für Lampen per Relais. https://www.youtube.com/watch?v=_CupBMcZ8Xc
Dependencies: BSP_DISCO_F746NG F746_GUI LCD_DISCO_F746NG TS_DISCO_F746NG mbed
main.cpp@0:da00b5dd65c6, 2017-01-30 (annotated)
- Committer:
- hexfactory
- Date:
- Mon Jan 30 20:58:13 2017 +0000
- Revision:
- 0:da00b5dd65c6
- Child:
- 1:f316de154ff7
First Release; 0x08 ARM mbed 001 - Display Steuerung - GUI und Schalter (Relai) [DE]; https://www.youtube.com/watch?v=_CupBMcZ8Xc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hexfactory | 0:da00b5dd65c6 | 1 | #include "mbed.h" |
hexfactory | 0:da00b5dd65c6 | 2 | #include "F746_GUI.hpp" |
hexfactory | 0:da00b5dd65c6 | 3 | #include "flash.h" |
hexfactory | 0:da00b5dd65c6 | 4 | |
hexfactory | 0:da00b5dd65c6 | 5 | /************************************ |
hexfactory | 0:da00b5dd65c6 | 6 | local variables / objects |
hexfactory | 0:da00b5dd65c6 | 7 | ************************************/ |
hexfactory | 0:da00b5dd65c6 | 8 | static DigitalOut light1Fet1(D4, 0); |
hexfactory | 0:da00b5dd65c6 | 9 | static DigitalOut light1Fet2(D5, 0); |
hexfactory | 0:da00b5dd65c6 | 10 | static DigitalOut light2Fet1(D6, 0); |
hexfactory | 0:da00b5dd65c6 | 11 | static DigitalOut light2Fet2(D7, 0); |
hexfactory | 0:da00b5dd65c6 | 12 | static uint8_t flashData[FLASH_DATA_SIZE]; |
hexfactory | 0:da00b5dd65c6 | 13 | |
hexfactory | 0:da00b5dd65c6 | 14 | /************************************ |
hexfactory | 0:da00b5dd65c6 | 15 | local function declaration |
hexfactory | 0:da00b5dd65c6 | 16 | ************************************/ |
hexfactory | 0:da00b5dd65c6 | 17 | |
hexfactory | 0:da00b5dd65c6 | 18 | static void _switchButton(DigitalOut out1, DigitalOut out2, uint8_t *toggleByte); |
hexfactory | 0:da00b5dd65c6 | 19 | |
hexfactory | 0:da00b5dd65c6 | 20 | /************************************ |
hexfactory | 0:da00b5dd65c6 | 21 | local function definition |
hexfactory | 0:da00b5dd65c6 | 22 | ************************************/ |
hexfactory | 0:da00b5dd65c6 | 23 | |
hexfactory | 0:da00b5dd65c6 | 24 | static void _switchButton(DigitalOut out1, DigitalOut out2, uint8_t *toggleByte) { |
hexfactory | 0:da00b5dd65c6 | 25 | /* toggle byte invertieren */ |
hexfactory | 0:da00b5dd65c6 | 26 | *toggleByte = !(*toggleByte); |
hexfactory | 0:da00b5dd65c6 | 27 | /* schreibe Daten ins Flash. Stellt Datenkonsistenz zwischen RAM und ROM sicher. */ |
hexfactory | 0:da00b5dd65c6 | 28 | flash_write(flashData); |
hexfactory | 0:da00b5dd65c6 | 29 | |
hexfactory | 0:da00b5dd65c6 | 30 | /* Je nach Stellung des toggle Bytes, |
hexfactory | 0:da00b5dd65c6 | 31 | wird Ausgang 1 oder 2 kurzzeitig geschaltet (Spannung angelegt). */ |
hexfactory | 0:da00b5dd65c6 | 32 | if(*toggleByte){ |
hexfactory | 0:da00b5dd65c6 | 33 | out1 = 1; |
hexfactory | 0:da00b5dd65c6 | 34 | wait(0.5); |
hexfactory | 0:da00b5dd65c6 | 35 | out1 = 0; |
hexfactory | 0:da00b5dd65c6 | 36 | } else{ |
hexfactory | 0:da00b5dd65c6 | 37 | out2 = 1; |
hexfactory | 0:da00b5dd65c6 | 38 | wait(0.5); |
hexfactory | 0:da00b5dd65c6 | 39 | out2 = 0; |
hexfactory | 0:da00b5dd65c6 | 40 | } |
hexfactory | 0:da00b5dd65c6 | 41 | } |
hexfactory | 0:da00b5dd65c6 | 42 | |
hexfactory | 0:da00b5dd65c6 | 43 | /************************************ |
hexfactory | 0:da00b5dd65c6 | 44 | global function definition |
hexfactory | 0:da00b5dd65c6 | 45 | ************************************/ |
hexfactory | 0:da00b5dd65c6 | 46 | |
hexfactory | 0:da00b5dd65c6 | 47 | int main() { |
hexfactory | 0:da00b5dd65c6 | 48 | /*************************** |
hexfactory | 0:da00b5dd65c6 | 49 | init |
hexfactory | 0:da00b5dd65c6 | 50 | ***************************/ |
hexfactory | 0:da00b5dd65c6 | 51 | /* GUI Ojects */ |
hexfactory | 0:da00b5dd65c6 | 52 | Label label1(240, 2, "Display Steuerung v0.1", Label::CENTER, Font16); |
hexfactory | 0:da00b5dd65c6 | 53 | Button btnLight1(10, 40, 70, 40, "Lampe 1"); |
hexfactory | 0:da00b5dd65c6 | 54 | Button btnLight2(90, 40, 70, 40, "Lampe 2"); |
hexfactory | 0:da00b5dd65c6 | 55 | |
hexfactory | 0:da00b5dd65c6 | 56 | /* flash */ |
hexfactory | 0:da00b5dd65c6 | 57 | flash_init(); |
hexfactory | 0:da00b5dd65c6 | 58 | flash_read(flashData); /* Lese Daten von flash (ROM) in das RAM */ |
hexfactory | 0:da00b5dd65c6 | 59 | |
hexfactory | 0:da00b5dd65c6 | 60 | /*************************** |
hexfactory | 0:da00b5dd65c6 | 61 | main loop |
hexfactory | 0:da00b5dd65c6 | 62 | ***************************/ |
hexfactory | 0:da00b5dd65c6 | 63 | while(1) { |
hexfactory | 0:da00b5dd65c6 | 64 | /* prüft ob button "btnLight1" gerade gedrück ist */ |
hexfactory | 0:da00b5dd65c6 | 65 | if (btnLight1.Touched()){ |
hexfactory | 0:da00b5dd65c6 | 66 | _switchButton(light1Fet1, light1Fet2, flashData + FLASH_TOGGLE_BYTE_LIGHT1); |
hexfactory | 0:da00b5dd65c6 | 67 | btnLight1.Draw(); |
hexfactory | 0:da00b5dd65c6 | 68 | } |
hexfactory | 0:da00b5dd65c6 | 69 | /* prüft ob button "btnLight2" gerade gedrück ist */ |
hexfactory | 0:da00b5dd65c6 | 70 | if (btnLight2.Touched()){ |
hexfactory | 0:da00b5dd65c6 | 71 | _switchButton(light2Fet1, light2Fet2, flashData + FLASH_TOGGLE_BYTE_LIGHT2); |
hexfactory | 0:da00b5dd65c6 | 72 | btnLight2.Draw(); |
hexfactory | 0:da00b5dd65c6 | 73 | } |
hexfactory | 0:da00b5dd65c6 | 74 | } |
hexfactory | 0:da00b5dd65c6 | 75 | } |