Demo to control 4 LEDs

Dependencies:   BSP_DISCO_F469NI mbed

Committer:
Faberge
Date:
Wed Oct 11 22:26:45 2017 +0000
Revision:
0:e06404fdff2f
Child:
1:a6d179a9ffbb
Demo to control 4 LEDs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Faberge 0:e06404fdff2f 1 /*
Faberge 0:e06404fdff2f 2 * main.cpp
Faberge 0:e06404fdff2f 3 *
Faberge 0:e06404fdff2f 4 * Copyright 2017 Faberge@TsarTeam
Faberge 0:e06404fdff2f 5 *
Faberge 0:e06404fdff2f 6 * This program is free software; you can redistribute it and/or modify
Faberge 0:e06404fdff2f 7 * it under the terms of the GNU General Public License as published by
Faberge 0:e06404fdff2f 8 * the Free Software Foundation; either version 2 of the License, or
Faberge 0:e06404fdff2f 9 * (at your option) any later version.
Faberge 0:e06404fdff2f 10 *
Faberge 0:e06404fdff2f 11 * This program is distributed in the hope that it will be useful,
Faberge 0:e06404fdff2f 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Faberge 0:e06404fdff2f 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Faberge 0:e06404fdff2f 14 * GNU General Public License for more details.
Faberge 0:e06404fdff2f 15 *
Faberge 0:e06404fdff2f 16 */
Faberge 0:e06404fdff2f 17
Faberge 0:e06404fdff2f 18 #include "Screen.h"
Faberge 0:e06404fdff2f 19 #include "Textbox.h"
Faberge 0:e06404fdff2f 20 #include "Button.h"
Faberge 0:e06404fdff2f 21 #include "Switch.h"
Faberge 0:e06404fdff2f 22 #include "user.h"
Faberge 0:e06404fdff2f 23
Faberge 0:e06404fdff2f 24 int state;
Faberge 0:e06404fdff2f 25
Faberge 0:e06404fdff2f 26 Screen *scr;
Faberge 0:e06404fdff2f 27
Faberge 0:e06404fdff2f 28 int main()
Faberge 0:e06404fdff2f 29 {
Faberge 0:e06404fdff2f 30 /* Init LEDs */
Faberge 0:e06404fdff2f 31 BSP_LED_Init(DISCO_LED_BLUE);
Faberge 0:e06404fdff2f 32 BSP_LED_Init(DISCO_LED_RED);
Faberge 0:e06404fdff2f 33 BSP_LED_Init(DISCO_LED_ORANGE);
Faberge 0:e06404fdff2f 34 BSP_LED_Init(DISCO_LED_GREEN);
Faberge 0:e06404fdff2f 35
Faberge 0:e06404fdff2f 36 /* Dummy screen */
Faberge 0:e06404fdff2f 37 scr = new Screen(LCD_COLOR_BLACK);
Faberge 0:e06404fdff2f 38 state = 1;
Faberge 0:e06404fdff2f 39
Faberge 0:e06404fdff2f 40 while(1)
Faberge 0:e06404fdff2f 41 {
Faberge 0:e06404fdff2f 42 /* Create screens */
Faberge 0:e06404fdff2f 43 switch(state)
Faberge 0:e06404fdff2f 44 {
Faberge 0:e06404fdff2f 45 case 0: break;
Faberge 0:e06404fdff2f 46 case 1:
Faberge 0:e06404fdff2f 47 {
Faberge 0:e06404fdff2f 48 delete scr;
Faberge 0:e06404fdff2f 49 scr = new Screen(LCD_COLOR_BLACK);
Faberge 0:e06404fdff2f 50
Faberge 0:e06404fdff2f 51 scr -> add(new Textbox(320, 5, LCD_COLOR_BLACK, "Switch Demo"));
Faberge 0:e06404fdff2f 52
Faberge 0:e06404fdff2f 53 /* Create switches */
Faberge 0:e06404fdff2f 54 scr -> add(new Switch(10, 20, LCD_COLOR_BLUE, blueLedOn, blueLedOff));
Faberge 0:e06404fdff2f 55 scr -> add(new Switch(10, 100, LCD_COLOR_RED, redLedOn, redLedOff));
Faberge 0:e06404fdff2f 56 scr -> add(new Switch(10, 180, LCD_COLOR_ORANGE, orangeLedOn, orangeLedOff));
Faberge 0:e06404fdff2f 57 scr -> add(new Switch(10, 260, LCD_COLOR_GREEN, greenLedOn, greenLedOff));
Faberge 0:e06404fdff2f 58
Faberge 0:e06404fdff2f 59 scr -> exitOnWithCode(new Button(10, 390, LCD_COLOR_DARKCYAN, "BTN"), 2);
Faberge 0:e06404fdff2f 60 scr -> exitOnWithCode(new Button(720, 390, LCD_COLOR_DARKCYAN, "TEXT"), 3);
Faberge 0:e06404fdff2f 61 HAL_Delay(300);
Faberge 0:e06404fdff2f 62 break;
Faberge 0:e06404fdff2f 63 }
Faberge 0:e06404fdff2f 64 case 2:
Faberge 0:e06404fdff2f 65 {
Faberge 0:e06404fdff2f 66 delete scr;
Faberge 0:e06404fdff2f 67 scr = new Screen(LCD_COLOR_BLACK);
Faberge 0:e06404fdff2f 68
Faberge 0:e06404fdff2f 69 scr -> add(new Textbox(320, 5, LCD_COLOR_BLACK, "Button Demo"));
Faberge 0:e06404fdff2f 70
Faberge 0:e06404fdff2f 71 /* Create buttons */
Faberge 0:e06404fdff2f 72 scr -> add(new Button(10, 20, LCD_COLOR_BLUE, "LED", blueLedOn, blueLedOff));
Faberge 0:e06404fdff2f 73 scr -> add(new Button(10, 100, LCD_COLOR_RED, "LED", redLedOn, redLedOff));
Faberge 0:e06404fdff2f 74 scr -> add(new Button(10, 180, LCD_COLOR_ORANGE, "LED", orangeLedOn, orangeLedOff));
Faberge 0:e06404fdff2f 75 scr -> add(new Button(10, 260, LCD_COLOR_GREEN, "LED", greenLedOn, greenLedOff));
Faberge 0:e06404fdff2f 76
Faberge 0:e06404fdff2f 77 scr -> exitOnWithCode(new Button(10, 390, LCD_COLOR_DARKCYAN, "TEXT"), 3);
Faberge 0:e06404fdff2f 78 scr -> exitOnWithCode(new Button(720, 390, LCD_COLOR_DARKCYAN, "SWCH"), 1);
Faberge 0:e06404fdff2f 79 HAL_Delay(300);
Faberge 0:e06404fdff2f 80 break;
Faberge 0:e06404fdff2f 81 }
Faberge 0:e06404fdff2f 82 case 3:
Faberge 0:e06404fdff2f 83 {
Faberge 0:e06404fdff2f 84 delete scr;
Faberge 0:e06404fdff2f 85 scr = new Screen(LCD_COLOR_BLACK);
Faberge 0:e06404fdff2f 86
Faberge 0:e06404fdff2f 87 scr -> add(new Textbox(340, 5, LCD_COLOR_BLACK, "Text Demo"));
Faberge 0:e06404fdff2f 88
Faberge 0:e06404fdff2f 89 /* Create textboxes */
Faberge 0:e06404fdff2f 90 scr -> add(new Textbox(10, 20, LCD_COLOR_BLACK, "Some text"));
Faberge 0:e06404fdff2f 91 scr -> add(new Textbox(10, 100, LCD_COLOR_BLACK, "Some more text..."));
Faberge 0:e06404fdff2f 92 scr -> add(new Textbox(10, 180, LCD_COLOR_BLACK, "This demo brought"));
Faberge 0:e06404fdff2f 93 scr -> add(new Textbox(10, 260, LCD_COLOR_BLACK, "to you by Faberge"));
Faberge 0:e06404fdff2f 94
Faberge 0:e06404fdff2f 95 scr -> exitOnWithCode(new Button(10, 390, LCD_COLOR_DARKCYAN, "SWCH"), 1);
Faberge 0:e06404fdff2f 96 scr -> exitOnWithCode(new Button(720, 390, LCD_COLOR_DARKCYAN, "BTN"), 2);
Faberge 0:e06404fdff2f 97
Faberge 0:e06404fdff2f 98 HAL_Delay(300);
Faberge 0:e06404fdff2f 99 break;
Faberge 0:e06404fdff2f 100 }
Faberge 0:e06404fdff2f 101 }
Faberge 0:e06404fdff2f 102 /* Check and upadte */
Faberge 0:e06404fdff2f 103 state = scr -> update();
Faberge 0:e06404fdff2f 104
Faberge 0:e06404fdff2f 105 /* Small delay for stability */
Faberge 0:e06404fdff2f 106 HAL_Delay(10);
Faberge 0:e06404fdff2f 107 }
Faberge 0:e06404fdff2f 108 }
Faberge 0:e06404fdff2f 109