Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG
main.cpp
- Committer:
- lolialf
- Date:
- 2020-02-07
- Revision:
- 1:a9bc635779dd
- Parent:
- 0:6ea52364a685
- Child:
- 2:41fa40a21162
File content as of revision 1:a9bc635779dd:
#include "mbed.h"
#include "stm32746g_discovery_lcd.h"
DigitalOut light(D8);
InterruptIn butt(D4);
char let[50];
int counter = 10;
int downer = 1;
int add = 0;
int randomoner;
void lights()
{
light = 0;
HAL_Delay(20);
light= 1;
HAL_Delay(200);
}
void menu()
{
BSP_LCD_Init();
BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS);
BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
BSP_LCD_Clear(LCD_COLOR_BLACK);
BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_DisplayStringAt(0, 250, (uint8_t *)"Nikki S.", RIGHT_MODE);
BSP_LCD_DisplayStringAt(0, 100, (uint8_t *)"Countdowner!!!", CENTER_MODE);
HAL_Delay(2000);
}
void disp()
{
BSP_LCD_Clear(LCD_COLOR_WHITE); // farve til bagrund
BSP_LCD_SetTextColor(LCD_COLOR_BLUE); // farve til de neste ting, indtil man vlger ny farve
BSP_LCD_DrawCircle(250, 100, 50);
BSP_LCD_DrawRect(265,75,1,20);
BSP_LCD_DrawRect(235,75,1,20);
BSP_LCD_DrawRect(235,120,30,1);
BSP_LCD_DrawRect(235,115,1,5);
BSP_LCD_DrawRect(265,116,1,5);
// min smiley
HAL_Delay(2000);
BSP_LCD_Clear(LCD_COLOR_WHITE);
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
BSP_LCD_DrawCircle(250, 100, 50);
BSP_LCD_DrawRect(265,75,10,1);
BSP_LCD_DrawRect(235,75,10,1);
BSP_LCD_DrawRect(235,120,30,1);
BSP_LCD_DrawRect(235,115,1,5);
BSP_LCD_DrawRect(265,116,1,5);
BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_DisplayStringAt(0, 250, (uint8_t *)("%s", let), LEFT_MODE);
HAL_Delay(10);
counter = counter - downer + add;
sprintf(let, "%d",counter);
BSP_LCD_DisplayStringAt(0, 200, (uint8_t *)("%s", let), LEFT_MODE);
// den viser counter og random number til LCD'en
// counter til LCD
// self comment: sprintf er min nye Savior, fik prøvet alt andet, men den var den eneste jeg kunne fik virket
HAL_Delay(1000);
if(counter == 0) {
BSP_LCD_Clear(LCD_COLOR_BLACK);
BSP_LCD_SetTextColor(LCD_COLOR_RED);
BSP_LCD_DisplayStringAt(0, 100, (uint8_t *)"KABOOOOOOM!!!!\nYou Died", CENTER_MODE);
light = 1;
getchar();
// the whole code will stop once the counter reaches 0
};
HAL_Delay(10);
add = 0;
}
void rando()
{
int random = rand() % 3;
// creates a random number from 0-2, dependant on the number at the code
sprintf(let, "%d", random);
randomoner = random;
}
void pressed()
{
while(randomoner == 0)
{
add = 3;
}
}
int main()
{
menu(); // use the menu code
while (1) {
butt.rise(&pressed);
disp(); // use the disp code
lights();
rando();
}
}