lab4
Dependencies: 4DGL-uLCD-SE mbed-rtos mbed
Diff: main.cpp
- Revision:
- 1:070b617f00f3
- Parent:
- 0:fcc91e110a28
- Child:
- 2:437fc6e9a1c3
--- a/main.cpp Sun Mar 08 05:23:33 2015 +0000 +++ b/main.cpp Tue Mar 10 02:46:39 2015 +0000 @@ -2,26 +2,47 @@ #include "uLCD_4DGL.h" #include "math.h" #include "rtos.h" +#include "wave_player.h" +#include "SDFileSystem.h" +#include "Speaker.h" +#include <string> -AnalogIn ain(p17); +#define YELLOW 0xFFFF00 +#define ORANGE 0xffdd76 +#define MECYAN 0x009696 + +AnalogIn steer(p17); AnalogIn force(p16); -PwmOut dout(LED1); +AnalogIn timer(p20); uLCD_4DGL lcd(p28, p27, p30); -//const int row=10; Mutex stdio_mutex; volatile int count=30; volatile int a=0; +volatile int cheat=3; + +void forward(void const *args) +{ + while(1) { + if (timer<0.1) { + if(count<29 && cheat>0) { + ++count; + --cheat; + } + } + Thread::wait(400); + } +} void steering(void const *args) { while(1) { stdio_mutex.lock(); - lcd.cls(); - a=floor(ain*39); - if(a>9) - {a=9;} + a=floor(steer*39); + if(a>9) { + a=9; + } switch(a) { case (1): { lcd.filled_rectangle(0, 98, 9, 110, BLUE); @@ -68,8 +89,6 @@ Thread::wait(200); break; } - - } stdio_mutex.unlock(); } @@ -79,7 +98,6 @@ { while(1) { stdio_mutex.lock(); - switch(count) { case (30): { lcd.filled_rectangle(0, 0, 90, 10, RED); @@ -149,7 +167,6 @@ break; } case (17): { - // lcd.filled_rectangle(0, 0, 100, 100, RED); lcd.filled_rectangle(70, 80, 127, 90, GREEN); lcd.filled_rectangle(40,20 , 90, 30, WHITE); break; @@ -167,70 +184,94 @@ lcd.printf("YOU LOSE!!!"); exit(0); } - break; } case (14): { lcd.filled_rectangle(70, 110, 127, 120, GREEN); lcd.filled_rectangle(40,50 , 90, 60, WHITE); - break; } case (13): { lcd.filled_rectangle(70, 120, 127, 130, GREEN); - lcd.filled_rectangle(40,60 , 90, 70, WHITE); + lcd.filled_rectangle(40, 60 , 90, 70, WHITE); + lcd.filled_rectangle(0, 0 , 30, 10, YELLOW); + lcd.filled_rectangle(60, 0 , 127, 10, YELLOW); break; } case (12): { - lcd.filled_rectangle(40,70 , 90,80 , WHITE); + lcd.filled_rectangle(40, 70, 90, 80 , WHITE); + lcd.filled_rectangle(0, 10, 30, 20, YELLOW); + lcd.filled_rectangle(60, 10, 127, 20, YELLOW); break; } case (11): { - lcd.filled_rectangle(40,80 , 90,90 , WHITE); + lcd.filled_rectangle(40, 80, 90, 90 , WHITE); + lcd.filled_rectangle(0, 20 , 30, 30, YELLOW); + lcd.filled_rectangle(60, 20 , 127, 30, YELLOW); break; } case (10): { - lcd.filled_rectangle(40,90 , 90,100 , WHITE); + lcd.filled_rectangle(40, 90, 90, 100 , WHITE); + lcd.filled_rectangle(0, 30 , 30, 40, YELLOW); + lcd.filled_rectangle(60, 30 , 127, 40, YELLOW); break; } case (9): { lcd.filled_rectangle(40,100 , 90, 110, WHITE); - if(a>5 && a<8 ) - {lcd.locate(3,8); + lcd.filled_rectangle(0, 40 , 30, 50, YELLOW); + lcd.filled_rectangle(60, 40 , 127, 50, YELLOW); + if(a>3 && a<8 ) { + lcd.locate(3,8); lcd.printf("YOU LOSE!!!"); - exit(0);} + exit(0); + } break; } case (8): { - lcd.filled_rectangle(40,110 , 90, 120, WHITE); + lcd.filled_rectangle(40,110 , 90, 120, WHITE); + lcd.filled_rectangle(0, 50 , 30, 60, YELLOW); + lcd.filled_rectangle(60, 50 , 127, 60, YELLOW); break; } case (7): { - lcd.filled_rectangle(40,120 , 90, 130, WHITE); + lcd.filled_rectangle(40,120 , 90, 130, WHITE); + lcd.filled_rectangle(0, 60 , 30, 70, YELLOW); + lcd.filled_rectangle(60, 60 , 127, 70, YELLOW); break; } case (6): { - + lcd.filled_rectangle(0, 70 , 30, 80, YELLOW); + lcd.filled_rectangle(60, 70 , 127, 80, YELLOW); break; } case (5): { - + lcd.filled_rectangle(0, 80 , 30, 90, YELLOW); + lcd.filled_rectangle(60, 80 , 127, 90, YELLOW); break; } case (4): { - + lcd.filled_rectangle(0, 90 , 30, 100, YELLOW); + lcd.filled_rectangle(60, 90 , 127, 100, YELLOW); break; } case (3): { - + lcd.filled_rectangle(0, 100 , 30, 110, YELLOW); + lcd.filled_rectangle(60, 100 , 127, 110, YELLOW); + if(a<4 || a>5 ) { + lcd.locate(3,8); + lcd.printf("YOU LOSE!!!"); + exit(0); + } break; } case (2): { - + lcd.filled_rectangle(0, 110 , 30, 120, YELLOW); + lcd.filled_rectangle(60, 110 , 127, 120, YELLOW); break; } case (1): { - + lcd.filled_rectangle(0, 120 , 30, 130, YELLOW); + lcd.filled_rectangle(60, 120 , 127, 130, YELLOW); break; } @@ -244,19 +285,17 @@ Thread thread1(steering); Thread thread2(obstacle); + Thread thread3(forward); while (1) { stdio_mutex.lock(); int wait=450*force; - // lcd.locate(4,3); - //lcd.printf("wait- %d ",wait); lcd.locate(13,0); lcd.printf("%d",--count); Thread::wait(600-wait); - - if(count==0) { + lcd.cls(); lcd.locate(1,8); lcd.printf("Congrats You win!"); exit(0);