finak vers

Dependencies:   BSP_DISCO_F746NG

Committer:
lolialf
Date:
Tue Feb 18 12:42:52 2020 +0000
Revision:
2:41fa40a21162
Parent:
1:a9bc635779dd
nyaa

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lolialf 0:6ea52364a685 1 #include "mbed.h"
lolialf 0:6ea52364a685 2 #include "stm32746g_discovery_lcd.h"
lolialf 0:6ea52364a685 3
lolialf 1:a9bc635779dd 4 DigitalOut light(D8);
lolialf 1:a9bc635779dd 5 InterruptIn butt(D4);
lolialf 1:a9bc635779dd 6
lolialf 1:a9bc635779dd 7
lolialf 1:a9bc635779dd 8
lolialf 1:a9bc635779dd 9
lolialf 0:6ea52364a685 10 char let[50];
lolialf 0:6ea52364a685 11 int counter = 10;
lolialf 1:a9bc635779dd 12 int downer = 1;
lolialf 1:a9bc635779dd 13 int add = 0;
lolialf 1:a9bc635779dd 14 int randomoner;
lolialf 1:a9bc635779dd 15
lolialf 1:a9bc635779dd 16 void lights()
lolialf 1:a9bc635779dd 17 {
lolialf 1:a9bc635779dd 18 light = 0;
lolialf 1:a9bc635779dd 19 HAL_Delay(20);
lolialf 1:a9bc635779dd 20 light= 1;
lolialf 1:a9bc635779dd 21 HAL_Delay(200);
lolialf 1:a9bc635779dd 22
lolialf 1:a9bc635779dd 23
lolialf 1:a9bc635779dd 24 }
lolialf 1:a9bc635779dd 25
lolialf 0:6ea52364a685 26
lolialf 0:6ea52364a685 27 void menu()
lolialf 0:6ea52364a685 28 {
lolialf 0:6ea52364a685 29 BSP_LCD_Init();
lolialf 0:6ea52364a685 30 BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS);
lolialf 0:6ea52364a685 31 BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
lolialf 0:6ea52364a685 32 BSP_LCD_Clear(LCD_COLOR_BLACK);
lolialf 0:6ea52364a685 33 BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
lolialf 0:6ea52364a685 34 BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
lolialf 0:6ea52364a685 35 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
lolialf 0:6ea52364a685 36 BSP_LCD_DisplayStringAt(0, 250, (uint8_t *)"Nikki S.", RIGHT_MODE);
lolialf 0:6ea52364a685 37 BSP_LCD_DisplayStringAt(0, 100, (uint8_t *)"Countdowner!!!", CENTER_MODE);
lolialf 0:6ea52364a685 38 HAL_Delay(2000);
lolialf 0:6ea52364a685 39 }
lolialf 0:6ea52364a685 40
lolialf 0:6ea52364a685 41 void disp()
lolialf 0:6ea52364a685 42 {
lolialf 0:6ea52364a685 43
lolialf 0:6ea52364a685 44 BSP_LCD_Clear(LCD_COLOR_WHITE); // farve til bagrund
lolialf 0:6ea52364a685 45 BSP_LCD_SetTextColor(LCD_COLOR_BLUE); // farve til de neste ting, indtil man vlger ny farve
lolialf 0:6ea52364a685 46 BSP_LCD_DrawCircle(250, 100, 50);
lolialf 0:6ea52364a685 47 BSP_LCD_DrawRect(265,75,1,20);
lolialf 0:6ea52364a685 48 BSP_LCD_DrawRect(235,75,1,20);
lolialf 0:6ea52364a685 49 BSP_LCD_DrawRect(235,120,30,1);
lolialf 0:6ea52364a685 50 BSP_LCD_DrawRect(235,115,1,5);
lolialf 0:6ea52364a685 51 BSP_LCD_DrawRect(265,116,1,5);
lolialf 0:6ea52364a685 52 // min smiley
lolialf 0:6ea52364a685 53
lolialf 0:6ea52364a685 54 HAL_Delay(2000);
lolialf 0:6ea52364a685 55 BSP_LCD_Clear(LCD_COLOR_WHITE);
lolialf 0:6ea52364a685 56 BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
lolialf 0:6ea52364a685 57 BSP_LCD_DrawCircle(250, 100, 50);
lolialf 0:6ea52364a685 58 BSP_LCD_DrawRect(265,75,10,1);
lolialf 0:6ea52364a685 59 BSP_LCD_DrawRect(235,75,10,1);
lolialf 0:6ea52364a685 60 BSP_LCD_DrawRect(235,120,30,1);
lolialf 0:6ea52364a685 61 BSP_LCD_DrawRect(235,115,1,5);
lolialf 0:6ea52364a685 62 BSP_LCD_DrawRect(265,116,1,5);
lolialf 0:6ea52364a685 63
lolialf 0:6ea52364a685 64 BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
lolialf 0:6ea52364a685 65 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
lolialf 0:6ea52364a685 66 BSP_LCD_DisplayStringAt(0, 250, (uint8_t *)("%s", let), LEFT_MODE);
lolialf 0:6ea52364a685 67 HAL_Delay(10);
lolialf 1:a9bc635779dd 68 counter = counter - downer + add;
lolialf 0:6ea52364a685 69 sprintf(let, "%d",counter);
lolialf 0:6ea52364a685 70 BSP_LCD_DisplayStringAt(0, 200, (uint8_t *)("%s", let), LEFT_MODE);
lolialf 0:6ea52364a685 71 // den viser counter og random number til LCD'en
lolialf 0:6ea52364a685 72
lolialf 1:a9bc635779dd 73
lolialf 0:6ea52364a685 74 // counter til LCD
lolialf 0:6ea52364a685 75 // self comment: sprintf er min nye Savior, fik prøvet alt andet, men den var den eneste jeg kunne fik virket
lolialf 0:6ea52364a685 76 HAL_Delay(1000);
lolialf 0:6ea52364a685 77
lolialf 0:6ea52364a685 78 if(counter == 0) {
lolialf 0:6ea52364a685 79
lolialf 0:6ea52364a685 80 BSP_LCD_Clear(LCD_COLOR_BLACK);
lolialf 0:6ea52364a685 81 BSP_LCD_SetTextColor(LCD_COLOR_RED);
lolialf 0:6ea52364a685 82 BSP_LCD_DisplayStringAt(0, 100, (uint8_t *)"KABOOOOOOM!!!!\nYou Died", CENTER_MODE);
lolialf 1:a9bc635779dd 83 light = 1;
lolialf 0:6ea52364a685 84 getchar();
lolialf 0:6ea52364a685 85 // the whole code will stop once the counter reaches 0
lolialf 0:6ea52364a685 86 };
lolialf 0:6ea52364a685 87 HAL_Delay(10);
lolialf 1:a9bc635779dd 88 add = 0;
lolialf 0:6ea52364a685 89 }
lolialf 0:6ea52364a685 90
lolialf 0:6ea52364a685 91
lolialf 0:6ea52364a685 92
lolialf 0:6ea52364a685 93
lolialf 1:a9bc635779dd 94 void rando()
lolialf 1:a9bc635779dd 95 {
lolialf 1:a9bc635779dd 96 int random = rand() % 3;
lolialf 1:a9bc635779dd 97 // creates a random number from 0-2, dependant on the number at the code
lolialf 1:a9bc635779dd 98
lolialf 1:a9bc635779dd 99 sprintf(let, "%d", random);
lolialf 1:a9bc635779dd 100
lolialf 1:a9bc635779dd 101 randomoner = random;
lolialf 1:a9bc635779dd 102 }
lolialf 1:a9bc635779dd 103 void pressed()
lolialf 1:a9bc635779dd 104 {
lolialf 2:41fa40a21162 105
lolialf 1:a9bc635779dd 106 add = 3;
lolialf 2:41fa40a21162 107
lolialf 1:a9bc635779dd 108
lolialf 1:a9bc635779dd 109 }
lolialf 1:a9bc635779dd 110
lolialf 0:6ea52364a685 111
lolialf 0:6ea52364a685 112 int main()
lolialf 0:6ea52364a685 113 {
lolialf 0:6ea52364a685 114
lolialf 0:6ea52364a685 115 menu(); // use the menu code
lolialf 0:6ea52364a685 116
lolialf 0:6ea52364a685 117 while (1) {
lolialf 1:a9bc635779dd 118 butt.rise(&pressed);
lolialf 0:6ea52364a685 119 disp(); // use the disp code
lolialf 1:a9bc635779dd 120 lights();
lolialf 1:a9bc635779dd 121 rando();
lolialf 0:6ea52364a685 122 }
lolialf 0:6ea52364a685 123 }