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.
joystick.cpp
00001 /** Projektiranje ugradbenih računalnih sustava 00002 * Default metoda za joystick X i Y os 00003 * @author: mario_meh 00004 * @code 00005 * #include "mbed.h" 00006 * #include "joystick.h" 00007 * 00008 * JoysKompas *data = new JoysKompas; 00009 * Joystick *joys = new Joystick(data); 00010 * joys->YEnable(); 00011 * 00012 * while(1) { 00013 * switch(data->vertikala) { 00014 * case 0: 00015 * serial.printf("Gore: %i\r\n", data->vertikala); 00016 * t_y0 = 0; 00017 * break; 00018 * case 1: 00019 * serial.printf("Dolje: %i\r\n", data->vertikala); 00020 * t_y1 = 0; 00021 * break; 00022 * } 00023 * 00024 *} 00025 * 00026 * @endcode 00027 */ 00028 #include "mbed.h" 00029 #include "joystick.h" 00030 00031 bool yRadi = false; 00032 volatile int y_i = 0; 00033 00034 int y_flag = false; 00035 int x_flag = false; 00036 00037 Joystick::Joystick(JoysKompas *Data) : _x(PTB0), _y(PTB1), y_enable(Data) 00038 // PTB0 | PTB1 00039 { 00040 } 00041 00042 void Joystick::YEnable() { 00043 y_ticker.attach(this, &Joystick::YStatus, 1); 00044 } 00045 00046 void Joystick::YDisable() { 00047 y_ticker.detach(); 00048 } 00049 00050 void Joystick::YStatus() { 00051 if(_x.read() < 0.022222222) { 00052 y_enable->horizontala = Lijevo; 00053 } else if(_x.read() > 0.9888888) { 00054 y_enable->horizontala = Desno; 00055 } else if(_y.read() < 0.022222222) { 00056 y_enable->vertikala = Dolje; 00057 } else if(_y.read() > 0.9888888) { 00058 y_enable->vertikala = Gore; 00059 } 00060 }
Generated on Tue Jul 26 2022 17:28:06 by
1.7.2