ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el19zf

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Instruction.cpp Source File

Instruction.cpp

00001 #include "Instruction.h"
00002 
00003 const char instruction [11][15] = {
00004     {"  Instruction "},
00005     {"--------------"},
00006     {"Move- Joystick"},
00007     {"--------------"},
00008     {"control 'peop-"},
00009     {"le' away from "},
00010     {"shots and rea-"},
00011     {"ch the destin-"},
00012     {"ation.        "},
00013     {"    Press B   "},
00014     {" back to menu "}
00015 };
00016 
00017 Instruction::Instruction()
00018 {
00019 
00020 }
00021 
00022 Instruction::~Instruction()
00023 {
00024 
00025 }
00026 
00027 void Instruction::init()
00028 {
00029     _draw_flag = 0;
00030 }
00031 
00032 void Instruction::draw(N5110 &lcd, Gamepad &pad)
00033 {
00034     init();
00035     pad.tone(10,0.05);
00036     pad.set_bpm(0);
00037     pad.reset_buttons();
00038     while (!pad.B_pressed()) {
00039         lcd.clear();
00040         _d = pad.get_direction();
00041         if(_d == N||_d ==NE||_d==NW) {
00042             _draw_flag = _draw_flag - 1;
00043         } else if(_d == S||_d==SE||_d==SW) {
00044             _draw_flag = _draw_flag + 1;
00045         }
00046         //
00047         if(_draw_flag < 0) {
00048             _draw_flag = 0;
00049         } else if(_draw_flag > 5)
00050             _draw_flag = 5;
00051     
00052         for(int i = 0; i < 6; i++)
00053             lcd.printString(instruction[_draw_flag + i],0,i);
00054         lcd.refresh();
00055         pad.leds_on();
00056         wait(0.25);
00057     }
00058 }