Академический Документы
Профессиональный Документы
Культура Документы
h"
#include "rtos.h"
#include "LCD_DISCO_F429ZI.h"
LCD_DISCO_F429ZI lcd;
InterruptIn button(PA_0);
DigitalOut led1(LED1);
Thread thread_blink;
Thread t2;
Thread thread_lcd;
bool bounce_up;
int y_movement;
int x_movement;
struct xy {
public:
int x;
int y;
};
xy *xy2 = mpool.alloc();
bounce_up = 1;
void ball_thread()
led1 = 1;
// set font
BSP_LCD_SetFont(&Font20);
// lcd.Clear(LCD_COLOR_WHITE);
// lcd.SetBackColor(LCD_COLOR_WHITE);
y_movement = 0;
bool bounce_down = 0;
while(1)
lcd.Clear(LCD_COLOR_WHITE);
x_movement = 0;
y_movement = 0;
bounce_up = 0;
bounce_down = 0;
Thread::wait(5000);
// lcd.SetTextColor(LCD_COLOR_RED);
y_movement += 3;
bounce_up = 0;
bounce_down = 1;
// Thread::wait(250);
// lcd.SetTextColor(LCD_COLOR_RED);
y_movement -= 5;
bounce_down = 0;
{
//lcd.Clear(LCD_COLOR_WHITE);
//lcd.SetBackColor(LCD_COLOR_WHITE);
//lcd.SetTextColor(LCD_COLOR_RED);
//Thread::wait(250);
Thread::wait(250);
xy2->x = x_movement;
xy2->y = y_movement;
queue.put(xy2);
void bg_thread()
//lcd.SetTextColor(LCD_COLOR_BLACK);
// initial position
x_movement = 0;
while (1)
x_movement = 0;
else
x_movement += 5;
// obstacle approaching.
//lcd.Clear(LCD_COLOR_WHITE);
// lcd.SetTextColor(LCD_COLOR_BLACK);
Thread::wait(250);
xy2->x = x_movement;
xy2->y = y_movement;
queue.put(xy2);
void lcd_resource(){
led1 = 1;
// set font
BSP_LCD_SetFont(&Font20);
lcd.Clear(LCD_COLOR_WHITE);
lcd.SetBackColor(LCD_COLOR_WHITE);
while (1)
if (evt.status == osEventMessage){
x_1 = xy3->x;
y_1 = xy3->y;
mpool.free(xy3);
lcd.Clear(LCD_COLOR_WHITE);
lcd.SetTextColor(LCD_COLOR_BLACK);
lcd.SetTextColor(LCD_COLOR_RED);
int main() {
button.rise(&btn_int);
// initialize thread.
thread_blink.set_priority(osPriorityHigh);
thread_blink.start(ball_thread);
t2.start(bg_thread);
thread_lcd.start(lcd_resource);