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.
Revision 0:e70cf0da7c72, committed 2017-05-04
- Comitter:
 - hongyunAHN
 - Date:
 - Thu May 04 11:46:46 2017 +0000
 - Commit message:
 - 200943373
 
Changed in this revision
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Background/Background.cpp	Thu May 04 11:46:46 2017 +0000
@@ -0,0 +1,182 @@
+#include "Background.h"
+
+#include "mbed.h"
+
+
+Background::Background()
+    :
+    _led1(new PwmOut(PTA1)),
+    _led2(new PwmOut(PTA2)),
+    _led3(new PwmOut(PTC2)),
+    _led4(new PwmOut(PTC3)),
+    _led5(new PwmOut(PTC4)),
+    _led6(new PwmOut(PTD3)),
+
+    _button_A(new InterruptIn(PTB9)),
+    _button_B(new InterruptIn(PTD0)),
+    _button_X(new InterruptIn(PTC17)),
+    _button_Y(new InterruptIn(PTC12)),
+    _button_L(new InterruptIn(PTB18)),
+    _button_R(new InterruptIn(PTB3)),
+    _button_back(new InterruptIn(PTB19)),
+    _button_start(new InterruptIn(PTC5)),
+    _button_joystick(new InterruptIn(PTC16)),
+
+    _vert(new AnalogIn(PTB10)),
+    _horiz(new AnalogIn(PTB11)),
+
+    _buzzer(new PwmOut(PTC10)),
+    _pot(new AnalogIn(PTB2)),
+
+    _timeout(new Timeout()),
+
+    _event_state(0),
+
+    _x0(0),
+    _y0(0)
+{}
+
+Background::~Background()
+{
+    delete _led1,_led2,_led3,_led4,_led5,_led6;
+    delete _button_A,_button_B,_button_joystick,_vert,_horiz;
+    delete _button_X,_button_Y,_button_back,_button_start;
+    delete _button_L,_button_R, _buzzer, _pot, _timeout;
+}
+
+
+void Background::init()
+{
+    leds_off();
+    init_buttons();
+
+    
+    _x0 = _horiz->read();
+    _y0 = _vert->read();
+
+   
+    _event_state = 0;
+}
+
+
+
+
+
+
+
+
+float Background::read_pot() const
+{
+    return _pot->read();
+}
+
+
+bool Background::check_event(BackgroundEvent const id)
+{
+    
+    if (_event_state[id]) {
+        _event_state.reset(id);  
+        return true;
+    } else {
+        return false;
+    }
+}
+
+float Background::get_mag()
+{
+    Polar p = get_polar();
+    return p.mag;
+}
+
+
+
+Direction Background::get_direction()
+{
+    float angle = get_angle();  
+
+    Direction d;
+   
+    if (angle < 0.0f) {
+        d = CENTRE;   
+    } else if (angle < 22.5f) {  
+        d = N;
+    } else if (angle < 67.5f) {
+        d = NE;
+    } else if (angle < 112.5f) {
+        d = E;
+    } else if (angle < 157.5f) {
+        d = SE;
+    } else if (angle < 202.5f) {
+        d = S;
+    } else if (angle < 247.5f) {
+        d = SW;
+    } else if (angle < 292.5f) {
+        d = W;
+    } else if (angle < 337.5f) {
+        d = NW;
+    } else {
+        d = N;
+    }
+
+    return d;
+}
+
+Vector2D Background::get_mapped_coord()
+{
+  const char array[48][85]={  
+    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},  
+    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+    {1,1,1,1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,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
+    {1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
+    {1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
+    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+    
+    };  
+       
+      
+      
+      
+      
+      }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Background/Background.h	Thu May 04 11:46:46 2017 +0000
@@ -0,0 +1,154 @@
+#ifndef BACKGROUND_H
+#define BACKGROUND_H
+
+#include <bitset>
+
+
+namespace mbed
+{
+class AnalogIn;
+class InterruptIn;
+class PwmOut;
+class Timeout;
+}
+#define TOL 0.1f
+#define RAD2DEG 57.2957795131f
+enum Direction {
+    CENTRE,  
+    N,       
+    NE,    
+    E,       
+    SE,     
+    S,       
+    SW,      
+    W,       
+    NW       
+};
+
+
+struct Vector2D {
+    float x; 
+    float y; 
+};
+
+
+struct Polar {
+    float mag;  
+    float angle; 
+};
+
+
+class Background
+{
+    public:
+   
+enum BackgroundEvent {
+    A_PRESSED,    
+    B_PRESSED,    
+    X_PRESSED,     
+    Y_PRESSED,     
+    L_PRESSED,     
+    R_PRESSED,     
+    BACK_PRESSED,  
+    START_PRESSED, 
+    JOY_PRESSED,   
+    N_EVENTS      
+};
+private:
+    mbed::PwmOut *_led1;
+    mbed::PwmOut *_led2;
+    mbed::PwmOut *_led3;
+    mbed::PwmOut *_led4;
+    mbed::PwmOut *_led5;
+    mbed::PwmOut *_led6;
+
+    mbed::InterruptIn *_button_A;
+    mbed::InterruptIn *_button_B;
+    mbed::InterruptIn *_button_X;
+    mbed::InterruptIn *_button_Y;
+    mbed::InterruptIn *_button_L;
+    mbed::InterruptIn *_button_R;
+    mbed::InterruptIn *_button_back;
+    mbed::InterruptIn *_button_start;
+    mbed::InterruptIn *_button_joystick;
+
+    mbed::AnalogIn *_vert;
+    mbed::AnalogIn *_horiz;
+
+    mbed::PwmOut   *_buzzer;
+    mbed::AnalogIn *_pot;
+
+    mbed::Timeout *_timeout;
+
+    std::bitset<N_EVENTS> _event_state; 
+
+
+    float _x0;
+    float _y0;
+
+public:
+
+   
+    Background();
+
+  
+    ~Background();
+
+   
+    void init();
+
+   
+    void leds_on();
+
+    
+    void leds_off();
+
+   
+    void leds(float val) const;
+
+   
+    void led(int n,float val) const;
+
+   
+    float read_pot() const;
+
+  
+    void tone(float frequency, float duration);
+
+   
+    bool check_event(BackgroundEvent const id);
+
+  
+    float get_mag();
+
+   
+    float get_angle();
+
+    
+    Direction get_direction();   
+
+   
+    Vector2D get_coord();         
+
+ 
+    Vector2D get_mapped_coord();  
+
+   
+    Polar get_polar();            
+
+private:
+    void init_buttons();
+    void tone_off();
+
+    void a_isr();
+    void b_isr();
+    void x_isr();
+    void y_isr();
+    void l_isr();
+    void r_isr();
+    void back_isr();
+    void start_isr();
+    void joy_isr();
+};
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/N5110.lib Thu May 04 11:46:46 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/eencae/code/N5110/#d80e568a2e18
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 04 11:46:46 2017 +0000
@@ -0,0 +1,74 @@
+///////// pre-processor directives ////////
+#include "mbed.h"
+#include "background.h"
+#include "N5110.h"
+#include "player.h"
+
+
+
+
+struct UserInput {
+    Direction d;
+    float mag;
+};
+N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
+background map;
+player ply;
+
+
+void init();
+void update_game(UserInput input);
+void render();
+void welcome();
+
+int main()
+{
+    int fps = 8;  
+
+    init();
+    welcome();
+    
+    render();  
+    wait(1.0f/fps);  
+
+
+    while (1) {
+        ply.read_input(map);
+        //ply.update(map);
+        render();
+        wait(1.0f/fps);
+    }
+}
+
+void init()
+{
+
+    lcd.init();
+  
+     
+
+}
+
+void render()
+{
+    lcd.clear();  
+  
+    lcd.refresh();
+}
+
+void welcome() {
+    
+    lcd.printString("     MAZE    ",0,1);  
+    lcd.printString("  Press Start ",0,4);
+    lcd.refresh();
+     
+
+ 
+    while ( map.check_event(background::START_PRESSED) == false) {
+        map.leds_on();
+        wait(0.1);
+        map.leds_off();
+        wait(0.1);
+    }
+ 
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu May 04 11:46:46 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/794e51388b66 \ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/player/player.cpp	Thu May 04 11:46:46 2017 +0000
@@ -0,0 +1,178 @@
+#include "player.h"
+#include "background.h"
+
+player::player()
+
+:
+    _led1(new PwmOut(PTA1)),
+    _led2(new PwmOut(PTA2)),
+    _led3(new PwmOut(PTC2)),
+    _led4(new PwmOut(PTC3)),
+    _led5(new PwmOut(PTC4)),
+    _led6(new PwmOut(PTD3)),
+
+    _button_A(new InterruptIn(PTB9)),
+    _button_B(new InterruptIn(PTD0)),
+    _button_X(new InterruptIn(PTC17)),
+    _button_Y(new InterruptIn(PTC12)),
+    _button_L(new InterruptIn(PTB18)),
+    _button_R(new InterruptIn(PTB3)),
+    _button_back(new InterruptIn(PTB19)),
+    _button_start(new InterruptIn(PTC5)),
+    _button_joystick(new InterruptIn(PTC16)),
+
+    _vert(new AnalogIn(PTB10)),
+    _horiz(new AnalogIn(PTB11)),
+
+    _buzzer(new PwmOut(PTC10)),
+    _pot(new AnalogIn(PTB2)),
+
+    _timeout(new Timeout()),
+
+    _event_state(0),
+
+    _x0(0),
+    _y0(0)
+{}
+
+
+
+
+
+player::~player()
+{
+
+    delete _led1,_led2,_led3,_led4,_led5,_led6;
+    delete _button_A,_button_B,_button_joystick,_vert,_horiz;
+    delete _button_X,_button_Y,_button_back,_button_start;
+    delete _button_L,_button_R, _buzzer, _pot, _timeout;
+
+
+}
+Vector2D player::get_player_coord(){
+     const char array[3][3]={
+    {1,1,1},
+    {1,1,1},
+    {1,1,1},
+    };
+    
+    }
+
+void player::init(int x,int y){
+
+  const char array[3][3]={
+    {1,1,1},
+    {1,1,1},
+    {1,1,1},
+    };
+    _speed=1:
+     setXYAddress(2,2); 
+    }
+
+void player::read_input(background &pad)
+{
+    _d = pad.get_direction();
+    //_mag = pad.get_mag();
+}
+
+void player::move_update()
+{
+    
+}
+
+void player::update(Direction d)
+{
+  
+    const char map[48][85] = get_mapped_coord();
+    Vector2D monsterPos = get_pos();
+    if(A_PRESSED){
+        if(map[Y][X+5]==1){
+             setXYAddress(X,Y);
+            }
+        else{setXYAddress(X+5,Y);}
+    }
+    else if (B_PRESSED){
+        if(map[Y+5][X]==1){
+             setXYAddress(X,Y);
+            }
+        else{setXYAddress(X,Y+5);}
+        }
+    else if (d == N) { 
+        if(map[Y+3][X]==1){
+            setXYAddress(X,Y);
+        }
+        else if (map[Y+3][X+2]==1){
+            setXYAddress(X,Y);
+        }     
+        else{ 
+            setXYAddress(X,Y+1); 
+        }
+    } 
+    else if (d == S) {
+        if(map[Y-1][X]==1){
+            setXYAddress(X,Y);
+        }
+        else if(map[Y-1][X+2]==1){
+            setXYAddress(X,Y);    
+        }
+        else{   
+            setXYAddress(X,Y-1);
+        }   
+    }else if (d == W) {
+        if(map[Y][X-1]==1){
+            setXYAddress(X,Y);    
+        }
+        else if(map[Y+2][X-1]==1){
+            setXYAddress(X,Y);
+        }    
+        else{
+            setXYAddress(X-1,Y); 
+        }  
+    }else if (d == E) {
+        if(map[Y][X+3]==1){
+            setXYAddress(X,Y);
+        }
+        else if(map[Y+2][X+3]==1){
+            setXYAddress(X,Y);
+        }
+        else{
+            setXYAddress(X+1,Y);
+        }   
+    }
+}
+
+
+if(pin==(40,24)){
+     lcd.printString("    GOAL    ",0,2);  
+    }
+if(pin==(83,43) ){
+    lcd.printString("   FAKE     ",0,2);
+     lcd.printString("  Find the other way  ",0,2);
+    lcd.refresh();  
+    }
+
+if(pin==(56,4)){
+     leds_on(0.2);
+     lcd.printString("   trap    ",0,2);
+     leds_off(0.2);
+     lcd.printString("  Find the other way  ",0,2);
+     lcd.refresh();
+     setXYAddress(2,2); 
+}
+if(pin==(77,29)){
+     leds_on(0.2);
+     lcd.printString("   trap    ",0,2);
+     lcd.refresh();
+     leds_off(0.2);
+   
+     setXYAddress(2,2); 
+}
+if(pin==(65,40)){
+     leds_on(0.2);
+     lcd.printString("   JUMP    ",0,2);
+     leds_off(0.2);
+    lcd.refresh();
+     setXYAddress(65,30); 
+}
+        
+        
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/player/player.h	Thu May 04 11:46:46 2017 +0000
@@ -0,0 +1,27 @@
+#ifndef PLAYER_H
+#define PLAYER_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "background.h"
+
+class player
+{
+public:
+
+    player();
+    ~player();
+    void init(int x,int height,int width);
+    void read_input(background pad);
+    void update(Direction d,float mag);
+    void draw(N5110 &lcd);
+    Vector2D get_pos();
+
+private:
+
+
+    int _x;
+    int _y;
+
+};
+#endif
\ No newline at end of file