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 17:cf1e1ffcf773, committed 2017-03-05
- Comitter:
- eencae
- Date:
- Sun Mar 05 19:01:31 2017 +0000
- Parent:
- 16:3ea3d9714b0c
- Child:
- 18:e0a4f15a7750
- Commit message:
- Merged separate LED methods into single method. Need to pass LED number as argument.
Changed in this revision
| Gamepad.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Gamepad.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Gamepad.cpp Fri Mar 03 13:19:19 2017 +0000
+++ b/Gamepad.cpp Sun Mar 05 19:01:31 2017 +0000
@@ -11,7 +11,7 @@
_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)),
@@ -21,17 +21,17 @@
_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)
{}
@@ -90,29 +90,32 @@
_led6->write(val);
}
-void Gamepad::led1(float val)
-{
- _led1->write(1.0f-val); // active-low so subtract from 1
-}
-void Gamepad::led2(float val)
-{
- _led2->write(1.0f-val); // active-low so subtract from 1
-}
-void Gamepad::led3(float val)
+void Gamepad::led(int n,float val)
{
- _led3->write(1.0f-val); // active-low so subtract from 1
-}
-void Gamepad::led4(float val)
-{
- _led4->write(1.0f-val); // active-low so subtract from 1
-}
-void Gamepad::led5(float val)
-{
- _led5->write(1.0f-val); // active-low so subtract from 1
-}
-void Gamepad::led6(float val)
-{
- _led6->write(1.0f-val); // active-low so subtract from 1
+ switch (n) {
+
+ // check for valid LED number and set value
+
+ case 1:
+ _led1->write(1.0f-val); // active-low so subtract from 1
+ break;
+ case 2:
+ _led2->write(1.0f-val); // active-low so subtract from 1
+ break;
+ case 3:
+ _led3->write(1.0f-val); // active-low so subtract from 1
+ break;
+ case 4:
+ _led4->write(1.0f-val); // active-low so subtract from 1
+ break;
+ case 5:
+ _led5->write(1.0f-val); // active-low so subtract from 1
+ break;
+ case 6:
+ _led6->write(1.0f-val); // active-low so subtract from 1
+ break;
+
+ }
}
float Gamepad::read_pot() const
@@ -187,6 +190,7 @@
void Gamepad::tone_off()
{
+ // called after timeout
_buzzer->write(0.0);
}
--- a/Gamepad.h Fri Mar 03 13:19:19 2017 +0000
+++ b/Gamepad.h Sun Mar 05 19:01:31 2017 +0000
@@ -45,6 +45,7 @@
/** Gamepad Class
@brief Library for interfacing with ELEC2645 Gamepad PCB, University of Leeds
@author Dr Craig A. Evans
+@author Dr Alex Valanvanis
@date Febraury 2017
*/
class Gamepad
@@ -120,34 +121,10 @@
void leds(float val) const;
/** Set LED to duty-cycle
- *@param value in range 0.0 to 1.0
- */
- void led1(float val);
-
- /** Set LED to duty-cycle
- *@param value in range 0.0 to 1.0
- */
- void led2(float val);
-
- /** Set LED to duty-cycle
+ *@param led number (0 to 5)
*@param value in range 0.0 to 1.0
*/
- void led3(float val);
-
- /** Set LED to duty-cycle
- *@param value in range 0.0 to 1.0
- */
- void led4(float val);
-
- /** Set LED to duty-cycle
- *@param value in range 0.0 to 1.0
- */
- void led5(float val);
-
- /** Set LED to duty-cycle
- *@param value in range 0.0 to 1.0
- */
- void led6(float val);
+ void led(int n,float val);
/** Read potentiometer
*@returns potentiometer value in range 0.0 to 1.0